def convert(self, image): "Convert an image to PNG" if not ImageConverter.active or Options.noconvert: return if image.origin.path == image.destination.path: return if image.destination.exists(): if image.origin.getmtime() <= image.destination.getmtime(): # file has not changed; do not convert return image.destination.createdirs() if Options.copyimages: Trace.debug('Copying ' + image.origin.path + ' to ' + image.destination.path) shutil.copy2(image.origin.path, image.destination.path) return converter, command = self.buildcommand(image) try: Trace.debug(converter + ' command: "' + command + '"') result = os.system(command.encode(sys.getfilesystemencoding())) if result != 0: Trace.error(converter + ' not installed; images will not be processed') ImageConverter.active = False return Trace.message('Converted ' + str(image.origin) + ' to ' + str(image.destination)) except OSError as exception: Trace.error('Error while converting image ' + str(image.origin) + ': ' + str(exception))
def convert(self, image): "Convert an image to PNG" if not ImageConverter.active or Options.noconvert: return if image.origin.path == image.destination.path: return if image.destination.exists(): if image.origin.getmtime() <= image.destination.getmtime(): # file has not changed; do not convert return image.destination.createdirs() if Options.copyimages: Trace.debug('Copying ' + image.origin.path + ' to ' + image.destination.path) shutil.copy2(image.origin.path, image.destination.path) return converter, command = self.buildcommand(image) try: Trace.debug(converter + ' command: "' + command + '"') result = os.system(command.encode(sys.getfilesystemencoding())) if result != 0: Trace.error(converter + ' not installed; images will not be processed') ImageConverter.active = False return Trace.message('Converted ' + unicode(image.origin) + ' to ' + unicode(image.destination)) except OSError, exception: Trace.error('Error while converting image ' + unicode(image.origin) + ': ' + unicode(exception))
def main(): "Main function, called if invoked from elyxer.the command line" args = sys.argv Options().parseoptions(args) if len(args) != 1: Trace.error('Usage: math2html.py escaped_string') exit() result = math2html(args[0]) Trace.message(result)
def readline(self): "Read a line from elyxer.file" self.current = self.file.readline() if not isinstance(self.file, codecs.StreamReaderWriter): self.current = self.current.decode('utf-8') if len(self.current) == 0: self.depleted = True self.current = self.current.rstrip('\n\r') self.linenumber += 1 self.mustread = False Trace.prefix = 'Line ' + unicode(self.linenumber) + ': ' if self.linenumber % 1000 == 0: Trace.message('Parsing')
def process(self): "Read all bibtex files and process them." self.entries = [] self.contents = [self.createheader()] bibliography = Translator.translate("bibliography") files = self.getparameterlist("bibfiles") showall = False if self.getparameter("btprint") == "btPrintAll": showall = True for file in files: bibfile = BibFile(file, showall) bibfile.parse() self.entries += bibfile.entries Trace.message("Parsed " + unicode(bibfile)) self.entries.sort(key=unicode) self.applystyle()
def process(self): "Read all bibtex files and process them." self.entries = [] self.contents = [self.createheader()] bibliography = Translator.translate('bibliography') files = self.getparameterlist('bibfiles') showall = False if self.getparameter('btprint') == 'btPrintAll': showall = True for file in files: bibfile = BibFile(file, showall) bibfile.parse() self.entries += bibfile.entries Trace.message('Parsed ' + str(bibfile)) self.entries.sort(key = str) self.applystyle()
def process(self): "Read all bibtex files and process them." self.entries = [] self.contents = [self.createheader()] bibliography = Translator.translate('bibliography') files = self.getparameterlist('bibfiles') showall = False if self.getparameter('btprint') == 'btPrintAll': showall = True for file in files: bibfile = BibFile(file, showall) bibfile.parse() self.entries += bibfile.entries Trace.message('Parsed ' + unicode(bibfile)) self.entries.sort(key = unicode) self.applystyle()
def mix(self, reader, addreader): "Mix two configuration files" Trace.message('--- new content follows ---') for name, object in addreader.objects.items(): Trace.message('') Trace.message('[' + name + ']') equiv = reader.objects[name] for key, value in object.items(): if not key in equiv: equiv[key] = value Trace.message(key + ':' + str(value))
def mix(self, reader, addreader): "Mix two configuration files" Trace.message('--- new content follows ---') for name, object in addreader.objects.iteritems(): Trace.message('') Trace.message('[' + name + ']') equiv = reader.objects[name] for key, value in object.iteritems(): if not key in equiv: equiv[key] = value Trace.message(key + ':' + unicode(value))
def processall(args): "Process all arguments" del args[0] if len(args) < 3: Trace.error('Usage: textchange.py original changed [file...]') return original = args[0] del args[0] changed = args[0] del args[0] Trace.message('Replacing ' + original + '->' + changed) change = TextChange(original, changed) total = 0 while len(args) > 0: pythonfile = BulkFile(args[0]) reader, writer = pythonfile.getfiles() del args[0] counter = process(reader, writer, change) total += counter Trace.message(' ' + str(counter) + ' occurrences in ' + str(pythonfile)) pythonfile.swaptemp() Trace.message('Total replacements: ' + str(total))
def processall(args): "Process all arguments" del args[0] if len(args) < 3: Trace.error('Usage: textchange.py original changed [file...]') return original = args[0] del args[0] changed = args[0] del args[0] Trace.message('Replacing ' + original + '->' + changed) change = TextChange(original, changed) total = 0 while len(args) > 0: pythonfile = BulkFile(args[0]) reader, writer = pythonfile.getfiles() del args[0] counter = process(reader, writer, change) total += counter Trace.message(' ' + unicode(counter) + ' occurrences in ' + unicode(pythonfile)) pythonfile.swaptemp() Trace.message('Total replacements: ' + unicode(total))
def readargs(args): "Read arguments from the command line" del args[0] if len(args) == 0: usage() return inputfile = args[0] del args[0] outputfile = os.path.splitext(inputfile)[0].lower() + '.py' if len(args) > 0: outputfile = args[0] del args[0] if len(args) > 0: usage() return return inputfile, outputfile def usage(): Trace.error('Usage: javatopy.py filein.java [fileout.py]') return inputfile, outputfile = readargs(sys.argv) Trace.debugmode = True Trace.showlinesmode = True if inputfile: JavaPorter().topy(FilePosition(inputfile), LineWriter(outputfile)) Trace.message('Conversion done, running ' + outputfile) os.system('python ' + outputfile)
def process(self): self.type = 'title' self.output.tag = 'h1 class="title"' title = self.extracttext() DocumentTitle.title = title Trace.message('Title: ' + title)
def readargs(args): "Read arguments from the command line" del args[0] if len(args) == 0: usage() return inputfile = args[0] del args[0] outputfile = os.path.splitext(inputfile)[0].lower() + ".py" if len(args) > 0: outputfile = args[0] del args[0] if len(args) > 0: usage() return return inputfile, outputfile def usage(): Trace.error("Usage: javatopy.py filein.java [fileout.py]") return inputfile, outputfile = readargs(sys.argv) Trace.debugmode = True Trace.showlinesmode = True if inputfile: JavaPorter().topy(FilePosition(inputfile), LineWriter(outputfile)) Trace.message("Conversion done, running " + outputfile) os.system("python " + outputfile)