Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-26 02:34:35

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 htaccess_content="""
0017 RewriteEngine on
0018 
0019 RewriteCond %{HTTP:Accept-Encoding} gzip
0020 RewriteRule (.*)\.html$ $1\.htmlgz [L]
0021 RewriteRule (.*)\.png$ $1\.pnggz [L]
0022 
0023 AddType "text/html;charset=UTF-8" .htmlgz
0024 AddEncoding gzip .htmlgz
0025 
0026 AddType "image/png" .pnggz
0027 AddEncoding gzip .pnggz
0028 
0029 DirectoryIndex RelMonSummary.htmlgz
0030 
0031 """
0032 
0033 
0034 from os.path import exists
0035 from os import system
0036 from sys import argv,exit
0037 
0038 argc=len(argv)
0039 
0040 if argc!=2:
0041   print("Usage: %prog directoryname")
0042   exit(-1)
0043 
0044 directory =  argv[1]
0045 
0046 while directory[-1]=="/": directory= directory[:-1]
0047 
0048 if not exists(directory):
0049   print("Directory %s does not exist: aborting!"%directory)
0050   exit(-1)  
0051 
0052 print("Moving pkls away...")
0053 pkl_dir="%s_pkls" %directory
0054 system("mkdir %s" %pkl_dir)
0055 system("mv %s/*pkl %s" %(directory,pkl_dir))
0056 print("All pkls moved in directory %s" %pkl_dir)
0057 
0058 print("Backupping directory %s" %directory)
0059 system("cp -r %s %s_back"%(directory,directory)) # i know, it should be better..
0060 print("Backupped!")
0061 
0062 print("Gzipping content of %s" %directory)
0063 system("time gzip -r -S gz %s"%directory) # i know, it should be better..
0064 print("Content of %s zipped!" %directory)
0065 
0066 print("Adding .htaccess file...")
0067 htaccess=open("%s/.htaccess"%directory,"w")
0068 htaccess.write(htaccess_content)
0069 htaccess.close()
0070 print("Apache .htaccess file successfully added!")