1 | #!/usr/bin/env /APSshare/bin/python |
---|
2 | #### |
---|
3 | # needs BCDA's /APSshare/bin/python to find ElementTree on ipnspool3 |
---|
4 | # ipnspool3 has an old Python (2.4) installed with no xml.etree.ElementTree |
---|
5 | |
---|
6 | ''' |
---|
7 | run CGI scripts for each PV (& RRD database) |
---|
8 | |
---|
9 | @note only needed to generate plots from RRD databases from command-line. |
---|
10 | Normally, plots are generated from WWW server operating a CGI page. |
---|
11 | ''' |
---|
12 | ########### SVN repository information ################### |
---|
13 | # $Date: 2010-08-18 20:28:25 +0000 (Wed, 18 Aug 2010) $ |
---|
14 | # $Author: jemian $ |
---|
15 | # $Revision: 206 $ |
---|
16 | # $HeadURL$ |
---|
17 | # $Id: htmlCreate.py 206 2010-08-18 20:28:25Z jemian $ |
---|
18 | ########### SVN repository information ################### |
---|
19 | |
---|
20 | ############################################################################### |
---|
21 | |
---|
22 | import dircache |
---|
23 | import os.path |
---|
24 | import shlex |
---|
25 | import subprocess |
---|
26 | import sys |
---|
27 | import time |
---|
28 | import xmlSupport |
---|
29 | |
---|
30 | ############################################################################### |
---|
31 | |
---|
32 | def processOne(pwd, rootName, properties): |
---|
33 | cgi = os.path.join( pwd, 'cgi', rootName + '.cgi' ) |
---|
34 | rrd = os.path.join( pwd, 'data', rootName + '.rrd' ) |
---|
35 | html = os.path.join( pwd, 'html', rootName + '.html' ) |
---|
36 | |
---|
37 | # Do not update if there is no matching RRD file |
---|
38 | # This will ignore .svn directories and other directory |
---|
39 | # items that are not in compliance with the design |
---|
40 | if (os.path.exists(rrd)): |
---|
41 | rrdModTime = os.path.getmtime(rrd) |
---|
42 | |
---|
43 | # Only update those html files with new RRD data. |
---|
44 | # This will ignore dormant CGI scripts |
---|
45 | htmlModTime = 0 |
---|
46 | if (os.path.exists(html)): |
---|
47 | htmlModTime = os.path.getmtime(html) |
---|
48 | if (rrdModTime >= htmlModTime): |
---|
49 | cmd = properties['rrd']['rrdcgi'] + ' --filter ' + cgi + ' >' + html |
---|
50 | cmd = properties['rrd']['rrdcgi'] + ' --filter ' + cgi |
---|
51 | shellCommandToFile(cmd, html) |
---|
52 | print time.ctime(), cmd |
---|
53 | |
---|
54 | |
---|
55 | def shellCommandToFile(command, outFile): |
---|
56 | '''execute a shell command and write its output to a file''' |
---|
57 | lex = shlex.split(command) |
---|
58 | print command, "\n", lex |
---|
59 | p = subprocess.Popen(lex, stdout=subprocess.PIPE) |
---|
60 | f = p.stdout |
---|
61 | p.wait() |
---|
62 | buf = f.read() |
---|
63 | f.close() |
---|
64 | writeFile(outFile, buf) |
---|
65 | |
---|
66 | |
---|
67 | def writeFile(file, contents): |
---|
68 | '''write contents to file''' |
---|
69 | f = open(file, 'w') |
---|
70 | f.write(contents) |
---|
71 | f.close() |
---|
72 | |
---|
73 | |
---|
74 | ############################################################################### |
---|
75 | |
---|
76 | cfg = xmlSupport.readConfigurationXML('/home/joule/WEB33/www/rrd') |
---|
77 | baseDir = cfg['properties']['rrd_logs_base_dir'] |
---|
78 | |
---|
79 | for fileName in dircache.listdir(os.path.join(baseDir,'cgi')): |
---|
80 | processOne(baseDir, fileName, cfg['properties']) |
---|