def begin_build(self): self.document = implementation.createDocument(None,None,None) self.export = self.document.createElement("export") self.export.setAttribute("id", self.config.get_uuid()) domain = self.config.get_domain() if domain is not None: n_domain = self._create_text_node("domain", domain) self.export.appendChild(n_domain) title = self.config.get_title() if title is not None: n_title = self._create_text_node("title", title) self.export.appendChild(n_title) created = self.config.get_created() if created is not None: n_created = self._create_text_node("created", created) self.export.appendChild(n_created) pool = self.config.get_pool() if pool is not None: n_pool = self._create_text_node("pool", pool) self.export.appendChild(n_pool) self.document.appendChild(self.export)
def begin_build(self): self.document = implementation.createDocument(None,None,None) self.firewall = self.document.createElement("firewall") self.firewall.setAttribute("type", "iptables") self.firewall.appendChild(self._create_text_node("last_modified", "%s" % time.ctime())) self.document.appendChild(self.firewall)
def begin_build(self): self.document = implementation.createDocument(None,None,None) self.disk = self.document.createElement("disk") self.disk.setAttribute("type", "file") self.disk.setAttribute("device", "disk") self.document.appendChild(self.disk)
def sciListPage(self, type, singlePages="yes"): nightList = [] document = implementation.createDocument(None, None, None) rootElement = document.createElement("document") rootElement.setAttribute("title", "%s exposures in run %s" % (string.upper(type), self.run)) tableNode = AddTableToDoc(document, "List of %s exposures" % (type, ), ["Exposure", "Object", "Exp. Time/s", "Seeing/\"", "Background/(1/s)", "<e1>", "<e2>", "ZP/mag"], ["left", "left", "right", "right", "right", "right", "right", "right"]) sciFrameListList = self.getSciFrames(type) for sciFrameList in sciFrameListList: recordNode = document.createElement("record") for val in sciFrameList: if sciFrameList.index(val) == 0: AddTextFieldToRecord(document, recordNode, val, [("link", os.path.join("science_frames", string.lower(val[:-4]+"html")))]) if singlePages == "yes": print "Creating single page for", val self.createSingleSci(type, val) else: AddTextFieldToRecord(document, recordNode, val) # Add ZP from Image Header imgPath = os.path.join(self.runDir, type, sciFrameList[0][:-5]+"_1"+self.extension+".fits") zp = GetHeaderVal(imgPath, "ZP") coeff = GetHeaderVal(imgPath, "COEFF") nightID = GetHeaderVal(imgPath, "GABODSID") zpChoice = GetHeaderVal(imgPath, "ZPCHOICE") if not nightID: continue if not nightID in nightList: solFile = os.path.join(self.runDir, "STANDARD_%s" % (self.filter,), "calib", "night_%d_%s_result.asc" % (nightID, self.filter)) if os.path.exists(solFile): self.createPhotPage(nightID, zp, coeff, zpChoice) link = os.path.join("standard", "night_%d.html" % (nightID,)) else: link = None nightList.append(nightID) if zp and float(zp) > -0.9: AddTextFieldToRecord(document, recordNode, "%.2f" % (round(float(zp), 2), ), [("link", link)]) # AddTextFieldToRecord(document, recordNode, "%.2f" % (round(float(zp), 2))) elif link: AddTextFieldToRecord(document, recordNode, "-1", [("link", link)]) else: AddTextFieldToRecord(document, recordNode, "-") tableNode.appendChild(recordNode) rootElement.appendChild(tableNode) footerNode = AddFooterNode(document) rootElement.appendChild(footerNode) document.appendChild(rootElement) ConvertDocument(self.webDir, string.lower(type), document, "calframes.xslt") ReleaseNode(document) os.chdir(self.cwd) return
def begin_build(self): self.document = implementation.createDocument(None,None,None) self.network = self.document.createElement("network") name = self._create_text_node("name", self.config.get_network_name()) uuid = self._create_text_node("uuid", self.config.get_uuid()) self.network.appendChild(name) self.network.appendChild(uuid) self.document.appendChild(self.network)
def begin_build(self): self.document = implementation.createDocument(None,None,None) self.volume = self.document.createElement("volume") name = self._create_text_node("name", self.config.get_storage_name()) uuid = self._create_text_node("uuid", self.config.get_uuid()) self.volume.appendChild(name) self.volume.appendChild(uuid) self.document.appendChild(self.volume)
def build_graphics(self): self.document = implementation.createDocument(None,None,None) self.graphics = self.document.createElement("graphics") self.graphics.setAttribute("type", self.get_type()) self.graphics.setAttribute("port", str(self.get_port())) self.graphics.setAttribute("listen", self.get_listen()) if self.get_keymap() is not None: self.graphics.setAttribute("keymap", self.get_keymap()) self.document.appendChild(self.graphics)
def begin_build(self): self.document = implementation.createDocument(None,None,None) self.pool = self.document.createElement("pool") self.pool.setAttribute('type', self.config.get_pool_type()) name = self._create_text_node("name", self.config.get_storage_name()) uuid = self._create_text_node("uuid", self.config.get_uuid()) self.pool.appendChild(name) self.pool.appendChild(uuid) self.document.appendChild(self.pool)
def begin_build(self): self.document = implementation.createDocument(None,None,None) self.domain = self.document.createElement("domain") self.domain.setAttribute("type", self.config.get_domain_type()) name = self._create_text_node("name", self.config.get_domain_name()) uuid = self._create_text_node("uuid", self.config.get_uuid()) self.domain.appendChild(name) self.domain.appendChild(uuid) if self.config.get_current_snapshot(): current_snapshot = self._create_text_node("currentSnapshot", self.config.get_current_snapshot()) self.domain.appendChild(current_snapshot) self.document.appendChild(self.domain)
def createSingleSci(self, type, frame): sciPageDir = os.path.join(self.webDir, "science_frames") document = implementation.createDocument(None, None, None) rootElement = document.createElement("document") rootElement.setAttribute("title", frame) mosaicNode = document.createElement("mosaic") mosaicNode.setAttribute("heading", "Binned Mosaic for %s" % (frame, )) status = AddImgNode(self.runDir, document, mosaicNode, type, frame[:-5], sciPageDir) if status != "ok": ReleaseNode(document) print status return rootElement.appendChild(mosaicNode) psfNode = document.createElement("mosaic") psfNode.setAttribute("heading", "PSF Pattern for %s" % (frame, )) psFile = os.path.join(self.runDir, type, "cat", "PSFcheck", frame[:-5]+".ps") status, pngPath = self.convertPSFPlot(psFile) if status != "ok": ReleaseNode(document) print status return imgNode = document.createElement("img") imgPath = os.path.join("images", os.path.split(pngPath)[1]) imgNode.setAttribute("source", imgPath) psfNode.appendChild(imgNode) rootElement.appendChild(psfNode) footerNode = AddFooterNode(document) rootElement.appendChild(footerNode) document.appendChild(rootElement) ConvertDocument(sciPageDir, string.lower(frame[:-5]), document, "calframes.xslt") ReleaseNode(document) return
def indexPage(self): document = implementation.createDocument(None, None, None) rootElement = document.createElement("document") rootElement.setAttribute("title", "Contents of run %s, filter %s" % (self.run, self.filter)) for files in ["BIAS", "DARK", "SCIENCE_%s" % (self.filter, ), "SKYFLAT_%s" % (self.filter, ), "DOMEFLAT_%s" % (self.filter, ), "STANDARD_%s" % (self.filter, )]: checkPath = os.path.join(self.webDir, string.lower(files)+".html") if not os.path.exists(checkPath): continue filesNode = document.createElement("files") filesNode.setAttribute("link", string.lower(files)+".html") textNode = document.createTextNode(files) filesNode.appendChild(textNode) rootElement.appendChild(filesNode) footerNode = AddFooterNode(document) rootElement.appendChild(footerNode) document.appendChild(rootElement) ConvertDocument(self.webDir, "index", document, "runindex.xslt") ReleaseNode(document) return
def begin_build(self): self.document = implementation.createDocument(None,None,None) self.services = self.document.createElement("services") self.document.appendChild(self.services)
def convert(self, fileIn, fileOut=None): """Parses the Magicpoint document and returns a KPresenter XML document. fileIn: path to the input file fileOut: path to the output file, or sys.stdout if omitted """ doctype=implementation.createDocumentType("DOC", "-//KDE//DTD kpresenter 1.2//EN", "http://www.koffice.org/DTD/kpresenter-1.2.dtd") self.document=implementation.createDocument("http://www.koffice.org/DTD/kpresenter", "DOC", doctype) rootElem=self.document.documentElement #the root "DOC" element rootElem.setAttribute("mime", "application/x-kpresenter") rootElem.setAttribute("syntaxVersion", "2") rootElem.setAttribute("editor", "mgp2kpr import filter, (c) Lukas Tinkl, 2002") self.__setPaper(rootElem) bgElem=self.document.createElement("BACKGROUND") objsElem=self.document.createElement("OBJECTS") self.textElem=self.document.createElement("TEXTOBJ") #default text object for line in fileinput.input(fileIn): if (line.startswith('#') or line.startswith('%%')): #skip comments continue elif (line.startswith('%')): #commands commands=string.split(string.replace(line, '%', ''),',') #list of commands, comma separated, remove '%' for command in commands: command=command.strip().lower() #print command if (command.lower().startswith('page')): #new page self.__handlePage(objsElem, bgElem) elif (command.startswith('bgrad')): #background gradient self.__setBgGradient(command) elif (command.startswith('deffont')): #default fonts self.__setupDefaultFonts(command) elif (command.startswith('default')): #document defaults TODO!!! pass elif (command.startswith('xfont')): #font self.__setFont(command) elif (command.startswith('font')): #font from default fonts self.__setFontIndirect(command) elif (command.startswith('size')): #font size self.__setFontSize(command) elif (command.startswith('left') or command.startswith('center') or command.startswith('right')): #text alignment self.__setAlign(command) elif (command.startswith('charset')): #charset self.__setCharset(command) elif (command.startswith('fore')): #font color self.__setTextColor(command) elif (command.startswith('back')): #background color self.__setBgColor(command) elif (command.startswith('bar')): #horizontal line self.__handleBar(command) elif (command.startswith('vgap')): #line spacing self.__setLineSpacing(command) elif (command.startswith('nodefault')): #use default page values? self.useDefaults=0 else: continue else: self.__handleText(line) #text self.__setBackground(bgElem) #flush the background rootElem.appendChild(bgElem) rootElem.appendChild(objsElem) self.document.appendChild(rootElem) if fileOut: PrettyPrint(self.document, open(fileOut[0], "w")) else: PrettyPrint(self.document, sys.stdout)
def calFramePage(self, type): document = implementation.createDocument(None, None, None) rootElement = document.createElement("document") rootElement.setAttribute("title", "%s frames in run %s" % (string.upper(type), self.run)) mosaicNode = document.createElement("mosaic") mosaicNode.setAttribute("heading", "Master %s frame" % (string.upper(type), )) status = self.addImgNode(document, mosaicNode, type) if status != "ok": ReleaseNode(document) print status return rootElement.appendChild(mosaicNode) masterFrameNode = AddTableToDoc(document, "Master %s frames" % (type, ), ["Frame", "mean", "median", "stdev", "min", "max"], ["left", "right", "right", "right", "right", "right"]) chipFrameNodes = [] for chip in range(1, self.noChips+1): frameName = "%s_%d.fits" % (type, chip) calFrame = os.path.join(self.runDir, type, frameName) if not os.path.exists(calFrame): print "No such calibration file: ", calFrame continue fimg=pyfits.open(calFrame) dat=fimg[0].data recordNode = document.createElement("record") AddTextFieldToRecord(document, recordNode, frameName) AddTextFieldToRecord(document, recordNode, "%.2f" % (round(dat.mean(), 2)), ) median = GetMedian(dat) AddTextFieldToRecord(document, recordNode, "%.2f" % (round(median, 2)), ) AddTextFieldToRecord(document, recordNode, "%.2f" % (round(GetCutStdev(dat), 2)), ) AddTextFieldToRecord(document, recordNode, "%.2f" % (round(dat.min(), 2)), ) AddTextFieldToRecord(document, recordNode, "%.2f" % (round(dat.max(), 2)), ) masterFrameNode.appendChild(recordNode) calDict = {} catFile = os.path.join(self.runDir, type, "cat", "chip_%d_stat.cat" % (chip, )) if os.path.exists(catFile): ftab = pyfits.open(catFile) tabHDU = ftab["STATS"] tabDat = tabHDU.data for row in range(len(tabDat)): try: exptime = tabDat[row].field("EXPTIME") except: exptime = None calDict[tabDat[row].field("FITSFILE")] = {"mode" : tabDat[row].field("Mode"), "median" : tabDat[row].field("Median"), "mean" : tabDat[row].field("Mean"), "stdev" : tabDat[row].field("Stdev"), "exptime": exptime} ftab.close() singleFrameNode = self.singleFrameTable(type, fimg[0].header, chip, calDict, document) chipFrameNodes.append(singleFrameNode) fimg.close() rootElement.appendChild(masterFrameNode) for singleFrameTable in chipFrameNodes: rootElement.appendChild(singleFrameTable) footerNode = AddFooterNode(document) rootElement.appendChild(footerNode) document.appendChild(rootElement) ConvertDocument(self.webDir, string.lower(type), document, "calframes.xslt") ReleaseNode(document) os.chdir(self.cwd) return
def initOutput(self): # Create a new document with no namespace uri, qualified name, # or document type self.document = implementation.createDocument(None,None,None) self.personnel = self.document.createElement("personnel") self.document.appendChild(self.personnel)
def createPhotPage(self, night, zp, coeff, zpChoice=None): stdPageDir = os.path.join(self.webDir, "standard") pipe = os.popen("caldate -d 31/12/1998 -i %d" % (night,)) result = pipe.read() pipe.close() civNight = string.split(result)[2] document = implementation.createDocument(None, None, None) rootElement = document.createElement("document") rootElement.setAttribute("title", "Photometric solutions for night %d (%s)" % (night, civNight)) tableNode = AddTableToDoc(document, "Photometric Solutions", ["ZP/mag", "Ext. Coeff.", "Col. Term", "Type", "Selected"], ["right", "right", "right", "left", "left"]) solFile = os.path.join(self.runDir, "STANDARD_%s" % (self.filter,), "calib", "night_%d_%s_result.asc" % (night, self.filter)) f = open(solFile, "r") i = 0 solType=["Z-K-C", "Z---C", "Z----"] for sol in f.readlines(): recordNode = document.createElement("record") zpSol, coeffSol, ctSol = string.split(sol) if not zpChoice: # It's really crappy that we have to find the accepted solution again # by comparing with all solutions. This is bound to fail at some point try: if fabs(float(zpSol)-zp) < 1e-4 and fabs(float(coeffSol)-coeff) <1e-4: selected = "yes" attr = [("mode", "b")] else: selected = "no" attr = [] # Older version did not always insert ZP and COEFF, they might be None ... except TypeError: selected = "no" attr = [] else: # New version write to the header which solution was chosen if zpChoice == i+1: selected = "yes" attr = [("mode", "b")] else: selected = "no" attr = [] AddTextFieldToRecord(document, recordNode, "%.2f" % (round(float(zpSol), 2), ), attr) AddTextFieldToRecord(document, recordNode, "%.2f" % (round(float(coeffSol), 2), ), attr) AddTextFieldToRecord(document, recordNode, "%.2f" % (round(float(ctSol), 2), ), attr) AddTextFieldToRecord(document, recordNode, solType[i], attr) AddTextFieldToRecord(document, recordNode, selected, attr) i += 1 tableNode.appendChild(recordNode) rootElement.appendChild(tableNode) plotNode = document.createElement("photcal") plotNode.setAttribute("heading", "Plot of photometric solutions") psFile = os.path.join(self.runDir, "STANDARD_%s" % (self.filter,), "calib", "night_%d_%s_result.ps" % (night, self.filter)) status, pngPath = self.convertPhotCalPlot(psFile) if status != "ok": ReleaseNode(document) print status return imgNode = document.createElement("img") imgPath = os.path.join("images", os.path.split(pngPath)[1]) imgNode.setAttribute("source", imgPath) plotNode.appendChild(imgNode) rootElement.appendChild(plotNode) footerNode = AddFooterNode(document) rootElement.appendChild(footerNode) document.appendChild(rootElement) ConvertDocument(stdPageDir, "night_%d" % (night,), document, "calframes.xslt") ReleaseNode(document) return
def makeCoaddPage(self, dir): cwd = os.getcwd() os.chdir(dir) coaddWeb = os.path.join(self.webDir, "coadd_"+self.ident) if not os.path.exists(coaddWeb): os.makedirs(coaddWeb) frameList = glob.glob("*%s.%s.fits" % (self.extension, self.ending)) fitsFile = os.path.join(dir, "%s_%s.%s.swarp.fits" % (self.field, self.filter, self.ident)) status, jpgPath = ConvertMosaicLarge(fitsFile, self.webDir, 2) if not status == "ok": print status title = "%s_%s %s" % (self.field, self.filter, self.ident) document = implementation.createDocument(None, None, None) rootElement = document.createElement("document") rootElement.setAttribute("title", title) if jpgPath: imgNode = document.createElement("img") imgPath = os.path.join("../images", os.path.split(jpgPath)[1]) imgNode.setAttribute("source", imgPath) rootElement.appendChild(imgNode) fitsFile = os.path.join(dir, "%s_%s.%s.swarp.weight.fits" % (self.field, self.filter, self.ident)) status, jpgPath = ConvertMosaicLarge(fitsFile, self.webDir, 0, levels=[0, None]) if not status == "ok": print status if jpgPath: imgNode = document.createElement("img") imgPath = os.path.join("../images", os.path.split(jpgPath)[1]) imgNode.setAttribute("source", imgPath) rootElement.appendChild(imgNode) diagNode = document.createElement("diagPlots") plotList = glob.glob("../postcoadd/plots/%s_%s.%s*" % (self.field, self.filter, self.ident)) setPlotList = glob.glob("../plots/coadd_%s*.ps" % (self.ident, )) print "setPlotList: ", setPlotList plotList = setPlotList + plotList for plot in plotList: status, pngPath = self.convertPlot(plot) if not status == "ok": print status if pngPath: imgNode = document.createElement("img") imgPath = os.path.join("../images", os.path.split(pngPath)[1]) imgNode.setAttribute("source", imgPath) diagNode.appendChild(imgNode) rootElement.appendChild(diagNode) suffix = "*_1%s.%s.fits" % (self.extension, self.ending) frameList = glob.glob(suffix) sciNode = document.createElement("runList") runList = [] frameDict = {} for frame in frameList: run = self.getRun(frame) if not run in runList: runList.append(run) frameDict[run] = [] frameDict[run].append(frame) runList.sort() tableNode = AddTableToDoc(document, "Runs and Exposures", ["No.", "Run", "Exposure"], ["right", "left", "left"]) i = 1 for run in runList: print run recordNode = document.createElement("record") AddTextFieldToRecord(document, recordNode, "") AddTextFieldToRecord(document, recordNode, run, [("link", os.path.join("..", "..", "..", self.filter, run))]) AddTextFieldToRecord(document, recordNode, "") tableNode.appendChild(recordNode) frameDict[run].sort() for frame in frameDict[run]: print frame print suffix frameEntry = frame[:-(len(suffix)-1)] # frameEntry = frame[:-12] recordNode = document.createElement("record") AddTextFieldToRecord(document, recordNode, str(i)) i += 1 AddTextFieldToRecord(document, recordNode, "") link = os.path.join("..", "..", "..", self.filter, run, "science_frames", string.lower(frameEntry)+".html") AddTextFieldToRecord(document, recordNode, frameEntry, [("link", link)]) tableNode.appendChild(recordNode) sciNode.appendChild(tableNode) footerNode = AddFooterNode(document) rootElement.appendChild(footerNode) rootElement.appendChild(sciNode) document.appendChild(rootElement) xmlFile = os.path.join(coaddWeb, "index.xml") htmlFile = os.path.join(coaddWeb, "index.html") f = open(xmlFile, "w") xml.dom.ext.PrettyPrint(document, f) f.close() ReleaseNode(document) cmd = "xsltproc %s/coaddframe.xslt %s > %s" % (PipeWWW, xmlFile, htmlFile) os.system(cmd) os.chdir(cwd) return
def makeCoaddIndex(self): cwd = os.getcwd() os.chdir(self.coaddDir) dList = glob.glob("coadd_*") dList.sort() document = implementation.createDocument(None, None, None) rootElement = document.createElement("document") title = "%s (%s-band) Co-Addition Overview" % (self.field, self.filter) rootElement.setAttribute("title", title) tableNode = AddTableToDoc(document, "Co-additions for this field", ["Identifier", "Seeing/arcsec", "ZP/mag", "Exp. Time/s", "Selection criteria"], ["left", "right", "right", "right", "left"]) for d in dList: dID = string.split(d, "_", 1)[1] recordNode = document.createElement("record") AddTextFieldToRecord(document, recordNode, d, (("link", d), )) fitsFile = "%s/%s_%s.%s.swarp.fits" % (d, self.field, self.filter, dID) val = GetHeaderVal(fitsFile, "SEEING") if val: val = round(val, 2) AddTextFieldToRecord(document, recordNode, val) val = GetHeaderVal(fitsFile, "MAGZP") if val: val = round(val, 2) AddTextFieldToRecord(document, recordNode, val) val = GetHeaderVal(fitsFile, "TEXPTIME") if val: val = round(val, 1) else: val = GetHeaderVal(fitsFile, "EXPTIME") if val: val = round(val, 1) AddTextFieldToRecord(document, recordNode, val) i = 1 cond = "" while 1: val = GetHeaderVal(fitsFile, "COND%d" % (i, )) if not val: break cond += val i += 1 AddTextFieldToRecord(document, recordNode, cond) tableNode.appendChild(recordNode) rootElement.appendChild(tableNode) diagNode = document.createElement("diagPlots") plotList = glob.glob("/%s/%s/plots/%s*.ps" % (self.fieldDir, self.filter, self.filter)) for plot in plotList: status, pngPath = self.convertPlot(plot) if not status == "ok": print status if pngPath: imgNode = document.createElement("img") imgPath = os.path.join("images", os.path.split(pngPath)[1]) imgNode.setAttribute("source", imgPath) diagNode.appendChild(imgNode) rootElement.appendChild(diagNode) footerNode = AddFooterNode(document) rootElement.appendChild(footerNode) document.appendChild(rootElement) xmlFile = os.path.join(self.webDir, "index.xml") htmlFile = os.path.join(self.webDir, "index.html") f = open(xmlFile, "w") xml.dom.ext.PrettyPrint(document, f) f.close() ReleaseNode(document) cmd = "xsltproc %s/coaddlist.xslt %s > %s" % (PipeWWW, xmlFile, htmlFile) os.system(cmd) os.chdir(cwd) return dList
# Print it # for testing, we must explicitly pass sys.stdout, as regrtest will # bind this to a different object PrettyPrint(doc, sys.stdout) # whitespace-removal currently not supported # utils.strip_whitespace(doc) # print ' With whitespace removed:' # print doc.toxml() # Builder code print 'DOM creation tests' from xml.dom.DOMImplementation import implementation d = implementation.createDocument(None, None, None) # Create the root element r = d.createElement("html") d.appendChild(r) # Create an empty 'head' element r.appendChild(d.createElement("head")) # Start the 'body' element, giving it an attribute b = d.createElement("body") b.setAttribute('background','#ffffff') r.appendChild(b) # Add a text node b.appendChild(d.createTextNode("The body text goes here."))
# Print it # for testing, we must explicitly pass sys.stdout, as regrtest will # bind this to a different object PrettyPrint(doc, sys.stdout) # whitespace-removal currently not supported # utils.strip_whitespace(doc) # print ' With whitespace removed:' # print doc.toxml() # Builder code print 'DOM creation tests' from xml.dom.DOMImplementation import implementation d = implementation.createDocument(None, None, None) # Create the root element r = d.createElement("html") d.appendChild(r) # Create an empty 'head' element r.appendChild(d.createElement("head")) # Start the 'body' element, giving it an attribute b = d.createElement("body") b.setAttribute('background', '#ffffff') r.appendChild(b) # Add a text node b.appendChild(d.createTextNode("The body text goes here."))
def begin_build(self): self.document = implementation.createDocument(None,None,None) self.interface = self.document.createElement("interface") self.interface.setAttribute("type", "bridge") self.document.appendChild(self.interface)