# TODO # - append TOC after H1 in documents # - add cookie to tell user which documents changed since last visit # - add FTP upload capacity #----------------------------------------------- import glob import time import os import ConfigParser import re import sys import win32con import win32ui from pywin.mfc import dialog from stat import * dlgStatic = 130 dlgButton = 128 def exists(file): return os.access(file, os.F_OK) def cutelastmodified(file): filetime = os.stat(file)[ST_MTIME] return time.strftime("Last modified %d %b %Y",time.gmtime(filetime)) def lastmodified(file): filetime = os.stat(file)[ST_MTIME] return time.strftime("%Y%m%d",time.gmtime(filetime)) def readini(file): p = ConfigParser.ConfigParser() p.readfp (open('index.ini')) try: return p.get('files',file) except: return 0 def writeini(file,size): p = ConfigParser.ConfigParser() p.read('index.ini') p.set('files', file, size) fp = open('index.ini','w') p.write(fp) fp.close() #The file needs to be regenerated IF #its size in INI differs from actual OR #the output doesn't exist in /docs (in case you work on two hosts) OR #the input version is more recent than the one in /docs OR #its size is not in INI def NeedUpdate(file): #If run for the first time, no INI yet if not exists('index.ini'): fp = open('index.ini','w') fp.write('[files]') fp.close() if (readini(file) != str(os.stat(file)[ST_SIZE])) or \ (not exists('../docs/' + file)) or \ (lastmodified(file) > lastmodified('../docs/' + file)) or \ (readini(file) == 0): return 1 else: return 0 def displaytext(dlg,text): label=dlg.GetDlgItem(dlgStatic) label.SetWindowText(text) class Mydialog(dialog.Dialog): def OnInitDialog(self): rc = dialog.Dialog.OnInitDialog(self) self.pbar = win32ui.CreateProgressCtrl() self.pbar.CreateWindow (win32con.WS_CHILD | win32con.WS_VISIBLE, (7, 30, 270, 50), self, 1001) return rc def OnOK(self): displaytext(self,"Checking files...") button=self.GetDlgItem(win32con.IDOK) button.EnableWindow(0) t1 = time.clock() if not os.path.isdir("../input"): displaytext(self,"../input not found. Aborting.") #label=self.GetDlgItem(dlgStatic) #label.SetWindowText("../input not found. Aborting.") return if not os.path.isdir("../docs"): os.mkdir("../docs") #glob() mixes forward- and backslashes on the Windows platform... os.chdir('../input') #Check whether template for homepage present if not exists("index.tpl"): #label=self.GetDlgItem(dlgStatic) #label.SetWindowText("Missing ./input/index.tpl") displaytext(self,"Missing ./input/index.tpl") return #Read template.tpl into variable if not exists("template.tpl"): #label=self.GetDlgItem(dlgStatic) #label.SetWindowText("Missing ./input/template.tpl") displaytext(self,"Missing ./input/template.tpl") return else: fp=open("template.tpl") templateorig = fp.read() fp.close template = templateorig #this dictionary will contain all the links belonging to a classification links = {} #Find out how many *.HTM* in /input, and set range of progress bar filecount = 0 for file in glob.glob('*.htm*'): filecount+=1 self.pbar.SetRange(0,filecount) for file in glob.glob('*.htm*'): self.pbar.SetStep(1) self.pbar.StepIt() #Read file into variable f = open(file, "r") inputfile = f.read() f.close() #Add file + title + rest of stuff in header into relevant list, eg. unix[], windows[], etc. title = re.search('