CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10/src/Utilities/RelMon/scripts/dir2webdir.py

Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 ################################################################################
00003 # RelMon: a tool for automatic Release Comparison                              
00004 # https://twiki.cern.ch/twiki/bin/view/CMSPublic/RelMon
00005 #
00006 # $Author: dpiparo $
00007 # $Date: 2012/06/12 12:25:27 $
00008 # $Revision: 1.1 $
00009 #
00010 #                                                                              
00011 # Danilo Piparo CERN - danilo.piparo@cern.ch                                   
00012 #                                                                              
00013 # Transform all html files into a directory into .htmlgz files and add the 
00014 # .htaccess file to tell Apache to serve the new compressed data.
00015 # Moves also the pickles away.
00016 #
00017 ################################################################################
00018 
00019 htaccess_content="""
00020 RewriteEngine on
00021 
00022 RewriteCond %{HTTP:Accept-Encoding} gzip
00023 RewriteRule (.*)\.html$ $1\.htmlgz [L]
00024 RewriteRule (.*)\.png$ $1\.pnggz [L]
00025 
00026 AddType "text/html;charset=UTF-8" .htmlgz
00027 AddEncoding gzip .htmlgz
00028 
00029 AddType "image/png" .pnggz
00030 AddEncoding gzip .pnggz
00031 
00032 DirectoryIndex RelMonSummary.htmlgz
00033 
00034 """
00035 
00036 
00037 from os.path import exists
00038 from os import system
00039 from sys import argv,exit
00040 
00041 argc=len(argv)
00042 
00043 if argc!=2:
00044   print "Usage: %prog directoryname"
00045   exit(-1)
00046 
00047 directory =  argv[1]
00048 
00049 while directory[-1]=="/": directory= directory[:-1]
00050 
00051 if not exists(directory):
00052   print "Directory %s does not exist: aborting!"%directory
00053   exit(-1)  
00054 
00055 print "Moving pkls away..."
00056 pkl_dir="%s_pkls" %directory
00057 system("mkdir %s" %pkl_dir)
00058 system("mv %s/*pkl %s" %(directory,pkl_dir))
00059 print "All pkls moved in directory %s" %pkl_dir
00060 
00061 print "Backupping directory %s" %directory
00062 system("cp -r %s %s_back"%(directory,directory)) # i know, it should be better..
00063 print "Backupped!"
00064 
00065 print "Gzipping content of %s" %directory
00066 system("time gzip -r -S gz %s"%directory) # i know, it should be better..
00067 print "Content of %s zipped!" %directory
00068 
00069 print "Adding .htaccess file..."
00070 htaccess=open("%s/.htaccess"%directory,"w")
00071 htaccess.write(htaccess_content)
00072 htaccess.close()
00073 print "Apache .htaccess file successfully added!"