示例#1
0
文件: image.py 项目: ccpaging/elyxer
 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))
示例#2
0
 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))
示例#3
0
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)
示例#4
0
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)
示例#5
0
 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')
示例#6
0
 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')
示例#7
0
文件: tex.py 项目: hainm/elyxer
 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()
示例#8
0
文件: tex.py 项目: ccpaging/elyxer
 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()
示例#9
0
文件: tex.py 项目: gitGNU/gnu_elyxer
 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()
示例#10
0
 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))
示例#11
0
 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))
示例#12
0
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))
示例#13
0
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))
示例#14
0
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)
示例#15
0
 def process(self):
     self.type = 'title'
     self.output.tag = 'h1 class="title"'
     title = self.extracttext()
     DocumentTitle.title = title
     Trace.message('Title: ' + title)
示例#16
0
文件: javatopy.py 项目: hainm/elyxer
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)
示例#17
0
 def process(self):
   self.type = 'title'
   self.output.tag = 'h1 class="title"'
   title = self.extracttext()
   DocumentTitle.title = title
   Trace.message('Title: ' + title)