home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 October / maximum-cd-2011-10.iso / DiscContents / digsby_setup.exe / lib / i18n / generate.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-06-22  |  6.1 KB  |  150 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. import sys
  5. import os.path as os
  6. thisdir = os.path.dirname(os.path.abspath(__file__))
  7. DIGSBYROOT = os.path.normpath(os.path.join(thisdir, '..'))
  8. sys.path.insert(0, thisdir)
  9. sys.path.insert(0, os.path.join(DIGSBYROOT, 'build'))
  10. import buildutil
  11. import mkappfill
  12. import mki18n
  13. import langtools
  14. from path import path
  15. from collections import defaultdict
  16. FIL_PATH = os.path.join(thisdir, 'app.fil')
  17. FIL_YAML_PATH = os.path.join(thisdir, 'appyaml.fil')
  18. FIL_TENJIN_PATH = os.path.join(thisdir, 'apptenjin.fil')
  19. SOURCE_DIRS = [ os.path.join(DIGSBYROOT, p) for p in [
  20.     'src',
  21.     'ext/src'] ]
  22. YAML_SOURCE_DIRS = [ os.path.join(DIGSBYROOT, p) for p in [
  23.     'src',
  24.     'ext/src',
  25.     'res'] ]
  26. DOMAIN = 'digsby'
  27.  
  28. def download_i18n_tools():
  29.     pass
  30.  
  31.  
  32. def check_for_i18n_tools():
  33.     
  34.     def _check():
  35.         stdout = buildutil.run([
  36.             'xgettext'], expect_return_code = 1, capture_stdout = True, include_stderr = True)
  37.         if 'no input file given' not in stdout:
  38.             raise Exception('unexpected output')
  39.         'no input file given' not in stdout
  40.  
  41.     
  42.     try:
  43.         _check()
  44.     except Exception:
  45.         dir = os.path.abspath(langtools.download_i18n_tools())
  46.         os.environ['PATH'] = os.environ['PATH'] + os.pathsep + dir
  47.         _check()
  48.  
  49.  
  50. MO_DIR = None
  51. PO_DIR = os.path.join(DIGSBYROOT, 'i18n')
  52.  
  53. def rename_new_pofiles(PO_DIR):
  54.     buildutil.cd(PO_DIR).__enter__()
  55.     
  56.     try:
  57.         for p in path('.').files('*.po.new'):
  58.             pofile = path(p.namebase)
  59.             print 'renaming', p, 'to', pofile
  60.             p.rename(pofile)
  61.     finally:
  62.         pass
  63.  
  64.  
  65.  
  66. def yield_translatable_yaml_strings(filename):
  67.     import re
  68.     pattern = re.compile('\\!\\_ (.+)')
  69.     for lineno, line in enumerate(open(filename, 'rb').readlines()):
  70.         m = pattern.search(line)
  71.         if m is not None:
  72.             text = m.group(1).strip()
  73.             if (text.startswith('"') or text.endswith('"') or text.startswith("'")) and text.endswith("'"):
  74.                 text = text[1:-1]
  75.             
  76.             yield (text, lineno)
  77.             continue
  78.     
  79.  
  80. pot_location_template = '#: %(filename)s:%(lineno)s'
  81. pot_template = '%(locations)s\nmsgid "%(string)s"\nmsgstr ""\n\n'
  82.  
  83. def xgettext_yaml(filelist, outputfilename):
  84.     output = open(outputfilename, 'wb')
  85.     print output, outputfilename
  86.     strings = defaultdict(list)
  87.     for f in open(filelist, 'rb').readlines():
  88.         f = f.strip()
  89.         for s, lineno in yield_translatable_yaml_strings(f):
  90.             strings[s].append((f, lineno))
  91.         
  92.     
  93.     for s, locations in sorted(strings.iteritems()):
  94.         locations_string = '\n'.join((lambda .0: for f, lineno in .0:
  95. pot_location_template % dict(filename = f, lineno = lineno))(locations))
  96.         output.write(pot_template % dict(locations = locations_string, string = s))
  97.         output.write('\n')
  98.     
  99.  
  100.  
  101. def xgettext(input_file, output_file, *args):
  102.     buildutil.run([
  103.         'xgettext',
  104.         '-s',
  105.         '-k_',
  106.         '--no-wrap'] + list(args) + [
  107.         '--files-from=%s' % input_file,
  108.         '--output=%s' % output_file])
  109.  
  110.  
  111. def doit(opts):
  112.     check_for_i18n_tools()
  113.     if opts.appfil is None and opts.po is None:
  114.         pass
  115.     doall = opts.mo is None
  116.     if doall or opts.appfil:
  117.         mkappfill.generate_fil_file(FIL_PATH, SOURCE_DIRS)
  118.         mkappfill.generate_fil_file(FIL_YAML_PATH, YAML_SOURCE_DIRS, extensions = [
  119.             '.yaml'])
  120.         mkappfill.generate_fil_file(FIL_TENJIN_PATH, SOURCE_DIRS, extensions = [
  121.             '.tenjin',
  122.             '.py.xml'])
  123.     
  124.     if doall or opts.mo:
  125.         mki18n.makeMO(DIGSBYROOT, MO_DIR, DOMAIN, True, poDir = PO_DIR)
  126.     
  127.  
  128.  
  129. def options():
  130.     import optparse
  131.     parser = optparse.OptionParser()
  132.     parser.add_option('-a', action = 'store_true', dest = 'appfil')
  133.     parser.add_option('-p', action = 'store_true', dest = 'po')
  134.     parser.add_option('-m', action = 'store_true', dest = 'mo')
  135.     (opts, args) = parser.parse_args()
  136.     return (opts, args)
  137.  
  138.  
  139. def main():
  140.     (opts, args) = options()
  141.     origdir = os.getcwd()
  142.     os.chdir(DIGSBYROOT)
  143.     
  144.     try:
  145.         doit(opts)
  146.     finally:
  147.         os.chdir(origdir)
  148.  
  149.  
  150.