Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-13 03:16:14

0001 #! /usr/bin/env python3
0002 ################################################################################
0003 # RelMon: a tool for automatic Release Comparison                              
0004 # https://twiki.cern.ch/twiki/bin/view/CMSPublic/RelMon
0005 #
0006 #
0007 #                                                                              
0008 # Danilo Piparo CERN - danilo.piparo@cern.ch                                   
0009 #                                                                              
0010 # Transform all html files into a directory into .htmlgz files and add the 
0011 # .htaccess file to tell Apache to serve the new compressed data.
0012 # Moves also the pickles away.
0013 #
0014 ################################################################################
0015 
0016 from __future__ import print_function
0017 htaccess_content="""
0018 RewriteEngine on
0019 
0020 RewriteCond %{HTTP:Accept-Encoding} gzip
0021 RewriteRule (.*)\.html$ $1\.htmlgz [L]
0022 RewriteRule (.*)\.png$ $1\.pnggz [L]
0023 
0024 AddType "text/html;charset=UTF-8" .htmlgz
0025 AddEncoding gzip .htmlgz
0026 
0027 AddType "image/png" .pnggz
0028 AddEncoding gzip .pnggz
0029 
0030 DirectoryIndex RelMonSummary.htmlgz
0031 
0032 """
0033 
0034 
0035 from os.path import exists
0036 from os import system
0037 from sys import argv,exit
0038 
0039 argc=len(argv)
0040 
0041 if argc!=2:
0042   print("Usage: %prog directoryname")
0043   exit(-1)
0044 
0045 directory =  argv[1]
0046 
0047 while directory[-1]=="/": directory= directory[:-1]
0048 
0049 if not exists(directory):
0050   print("Directory %s does not exist: aborting!"%directory)
0051   exit(-1)  
0052 
0053 print("Moving pkls away...")
0054 pkl_dir="%s_pkls" %directory
0055 system("mkdir %s" %pkl_dir)
0056 system("mv %s/*pkl %s" %(directory,pkl_dir))
0057 print("All pkls moved in directory %s" %pkl_dir)
0058 
0059 print("Backupping directory %s" %directory)
0060 system("cp -r %s %s_back"%(directory,directory)) # i know, it should be better..
0061 print("Backupped!")
0062 
0063 print("Gzipping content of %s" %directory)
0064 system("time gzip -r -S gz %s"%directory) # i know, it should be better..
0065 print("Content of %s zipped!" %directory)
0066 
0067 print("Adding .htaccess file...")
0068 htaccess=open("%s/.htaccess"%directory,"w")
0069 htaccess.write(htaccess_content)
0070 htaccess.close()
0071 print("Apache .htaccess file successfully added!")