/usr/share/pyshared/PyMca/HtmlIndex.py is in pymca 4.5.0-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | #/*##########################################################################
# Copyright (C) 2004-2010 European Synchrotron Radiation Facility
#
# This file is part of the PyMCA X-ray Fluorescence Toolkit developed at
# the ESRF by the Beamline Instrumentation Software Support (BLISS) group.
#
# This toolkit is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# PyMCA is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# PyMCA; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307, USA.
#
# PyMCA follows the dual licensing model of Trolltech's Qt and Riverbank's PyQt
# and cannot be used as a free plugin for a non-free program.
#
# Please contact the ESRF industrial unit (industry@esrf.fr) if this license
# is a problem for you.
#############################################################################*/
import os
import sys
import PyMcaLogo
import time
class HtmlIndex:
def __init__(self, htmldir):
if htmldir is None:htmldir = "/tmp/HTML"
self.htmldir = htmldir
def isHtml(self, x):
if len(x) < 5: return 0
if x[-5:] == ".html":return 1
def isHtmlDir(self, x):
if len(x) < 7: return 0
if x[-7:] == "HTMLDIR":return 1
def getHeader(self,addlink=None):
link= [ ['http://www.esrf.fr', 'ESRF home'],
['http://www.esrf.fr/computing/bliss/', 'BLISS home'],
]
if addlink is not None:
for item in addlink:
link.append(item)
text =""
text+= "<HTML>"
text+= "<HEAD>"
text+= "<TITLE>PyMCA : Advanced Fit Results</TITLE>"
text+= "</HEAD>"
text+= "<BODY TEXT=#000000 BGCOLOR=#FFFFFF ALINK=#ff6600 LINK=#0000cc VLINK=#0000cc marginwidth=10 marginheight=10 topmargin=10 leftmargin=10>"
text+= "<CENTER>"
text+= "<TABLE WIDTH=100%% border=0 Height=70>"
text+= " <TR>"
text+= " <TD><Font Size=5 Color=#0000cc>"
text+= " <b>PyMCA : Advanced Fit Results</b></Font>"
text+= " </td>"
text+= " <td rowspan=2 ALIGN=RIGHT VALIGN=bottom>"
text+= " <a HREF=""http://www.esrf.fr/"">"
logofile = self.htmldir + "/" + "PyMcaLogo.png"
if not os.path.exists(logofile):
try:
import qt
pixmap = qt.QPixmap(PyMcaLogo.PyMcaLogo)
pixmap.save(logofile,"PNG")
except:
pass
text+= " <img SRC=%s ALT=""ESRF home"" WIDTH=55 HEIGHT=68 BORDER=0></a>" % "PyMcaLogo.png"
text+= " </td>"
text+= " </tr>"
text+= " <tr>"
text+= " <td width=100%% VALIGN=bottom>"
text+= " <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%%>"
text+= " <TR>"
text+= " <TD WIDTH=100%% BGCOLOR=#ee22aa HEIGHT=17 ALIGN=LEFT VALIGN=middle>"
text+= " <FONT color=#000000> "
for name in link:
text+= "| <A STYLE=""color: #FFFFFF"" HREF=""%s"">%s</a> "%(tuple(name))
text+= " </FONT>"
text+= " </TD>"
text+= " </TR>"
text+= " </TABLE>"
text+= " </td>"
text+= " </tr>"
text+= " <tr>"
text+= " <td colspan=2 height=5><spacer type=block height=10 width=0>"
text+= " </td>"
text+= " </tr>"
text+= "</table>"
text+= "</center>"
return text
def getFooter(self):
now = time.time()
text =""
text+= "<center>"
text+= "<table width=100%% border=0 cellspacing=0 cellpadding=0>"
text+= " <tr><td colspan=2 height=10><spacer type=block height=10 width=0></td></tr>"
text+= " <tr><td colspan=2 bgcolor=#cc0066 height=5><spacer type=block height=5 width=0></td></tr>"
text+= " <tr><td colspan=2 height=5><spacer type=block height=5 width=0></td></tr>"
text+= " <TR>"
text+= " <TD><FONT size=1 >created: %s</font></TD>" % time.ctime(now)
text+= " <TD ALIGN=RIGHT><FONT size=1 >last modified: %s by" % time.ctime(now)
#text+= " <A STYLE=""color: #0000cc"" HREF=""mailto:papillon@esrf.fr"">papillon@esrf.fr</A></FONT></TD>"
if sys.platform == 'win32':
try:
user = os.environ['USERNAME']
text+= " <A STYLE=""color: #0000cc"">%s</A></FONT></TD>" % user
except:
text +="</FONT></TD>"
else:
try:
user = os.getlogin()
text+= " <A STYLE=""color: #0000cc"">%s</A></FONT></TD>" % user
except:
text +="</FONT></TD>"
text+= " </TR>"
text+= "</TABLE>"
text+= "</center>"
text+= "</BODY>"
text+= "</HTML>"
return text
def getBody(self, htmldir=None):
if htmldir is None:htmldir = self.htmldir
dirlist = filter(self.isHtmlDir, os.listdir(htmldir))
filelist = []
for directory in dirlist:
fulldir = os.path.join(self.htmldir,directory)
filelist += filter(self.isHtml, os.listdir(fulldir))
#I have a list of directories and of indexes
for directory in dirlist:
fulldir = os.path.join(htmldir,directory)
index = os.path.join(fulldir,"index.html")
if os.path.exists(index):
try:
os.remove(index)
except:
print("cannot delete file %s" % index)
continue
def _getHtmlFileList(self, directory):
return filter(self.isHtml, os.listdir(directory))
def _getHtmlDirList(self, directory):
return filter(self.isHtmlDir, os.listdir(directory))
def buildIndex(self, directory = None):
if directory is None: directory = self.htmldir
index = os.path.join(directory, "index.html")
if os.path.exists(index):
try:
os.remove(index)
except:
print("cannot delete file %s" % index)
return
filelist = self._getHtmlFileList(directory)
text = ""
text += self.getHeader()
for file in filelist:
text +="<a href=""%s"">%s</a><BR>" % (file, file.split(".html")[0])
text += self.getFooter()
file=open(index,'wb')
file.write(text)
file.close()
def buildRecursiveIndex(self, directory = None):
if directory is None: directory = self.htmldir
index = os.path.join(directory, "index.html")
if os.path.exists(index):
try:
os.remove(index)
except:
print("cannot delete file %s" % index)
return
directorylist = self._getHtmlDirList(directory)
text = ""
text += self.getHeader()
for file in directorylist:
fulldir = os.path.join(directory,file)
self.buildIndex(fulldir)
fileroot = file.split('_HTMLDIR')[0]
link = "./"+file+"/index.html"
text +="<a href=""%s"">%s</a><BR>" % (link, fileroot)
text += self.getFooter()
file=open(index,'wb')
file.write(text)
file.close()
if __name__ == "__main__":
if len(sys.argv) > 1:
a = HtmlIndex(sys.argv[1])
else:
print("Trying /tmp/HTML as input directory")
a = HtmlIndex('/tmp/HTML')
a.buildRecursiveIndex()
|