CMS 3D CMS Logo

dir2webdir.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 ################################################################################
3 # RelMon: a tool for automatic Release Comparison
4 # https://twiki.cern.ch/twiki/bin/view/CMSPublic/RelMon
5 #
6 #
7 #
8 # Danilo Piparo CERN - danilo.piparo@cern.ch
9 #
10 # Transform all html files into a directory into .htmlgz files and add the
11 # .htaccess file to tell Apache to serve the new compressed data.
12 # Moves also the pickles away.
13 #
14 ################################################################################
15 
16 from __future__ import print_function
17 htaccess_content="""
18 RewriteEngine on
19 
20 RewriteCond %{HTTP:Accept-Encoding} gzip
21 RewriteRule (.*)\.html$ $1\.htmlgz [L]
22 RewriteRule (.*)\.png$ $1\.pnggz [L]
23 
24 AddType "text/html;charset=UTF-8" .htmlgz
25 AddEncoding gzip .htmlgz
26 
27 AddType "image/png" .pnggz
28 AddEncoding gzip .pnggz
29 
30 DirectoryIndex RelMonSummary.htmlgz
31 
32 """
33 
34 
35 from os.path import exists
36 from os import system
37 from sys import argv,exit
38 
39 argc=len(argv)
40 
41 if argc!=2:
42  print("Usage: %prog directoryname")
43  exit(-1)
44 
45 directory = argv[1]
46 
47 while directory[-1]=="/": directory= directory[:-1]
48 
49 if not exists(directory):
50  print("Directory %s does not exist: aborting!"%directory)
51  exit(-1)
52 
53 print("Moving pkls away...")
54 pkl_dir="%s_pkls" %directory
55 system("mkdir %s" %pkl_dir)
56 system("mv %s/*pkl %s" %(directory,pkl_dir))
57 print("All pkls moved in directory %s" %pkl_dir)
58 
59 print("Backupping directory %s" %directory)
60 system("cp -r %s %s_back"%(directory,directory)) # i know, it should be better..
61 print("Backupped!")
62 
63 print("Gzipping content of %s" %directory)
64 system("time gzip -r -S gz %s"%directory) # i know, it should be better..
65 print("Content of %s zipped!" %directory)
66 
67 print("Adding .htaccess file...")
68 htaccess=open("%s/.htaccess"%directory,"w")
69 htaccess.write(htaccess_content)
70 htaccess.close()
71 print("Apache .htaccess file successfully added!")
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:65