home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.6)
-
- import sys
- import os.path as os
- thisdir = os.path.dirname(os.path.abspath(__file__))
- DIGSBYROOT = os.path.normpath(os.path.join(thisdir, '..'))
- sys.path.insert(0, thisdir)
- sys.path.insert(0, os.path.join(DIGSBYROOT, 'build'))
- import buildutil
- import mkappfill
- import mki18n
- import langtools
- from path import path
- from collections import defaultdict
- FIL_PATH = os.path.join(thisdir, 'app.fil')
- FIL_YAML_PATH = os.path.join(thisdir, 'appyaml.fil')
- FIL_TENJIN_PATH = os.path.join(thisdir, 'apptenjin.fil')
- SOURCE_DIRS = [ os.path.join(DIGSBYROOT, p) for p in [
- 'src',
- 'ext/src'] ]
- YAML_SOURCE_DIRS = [ os.path.join(DIGSBYROOT, p) for p in [
- 'src',
- 'ext/src',
- 'res'] ]
- DOMAIN = 'digsby'
-
- def download_i18n_tools():
- pass
-
-
- def check_for_i18n_tools():
-
- def _check():
- stdout = buildutil.run([
- 'xgettext'], expect_return_code = 1, capture_stdout = True, include_stderr = True)
- if 'no input file given' not in stdout:
- raise Exception('unexpected output')
- 'no input file given' not in stdout
-
-
- try:
- _check()
- except Exception:
- dir = os.path.abspath(langtools.download_i18n_tools())
- os.environ['PATH'] = os.environ['PATH'] + os.pathsep + dir
- _check()
-
-
- MO_DIR = None
- PO_DIR = os.path.join(DIGSBYROOT, 'i18n')
-
- def rename_new_pofiles(PO_DIR):
- buildutil.cd(PO_DIR).__enter__()
-
- try:
- for p in path('.').files('*.po.new'):
- pofile = path(p.namebase)
- print 'renaming', p, 'to', pofile
- p.rename(pofile)
- finally:
- pass
-
-
-
- def yield_translatable_yaml_strings(filename):
- import re
- pattern = re.compile('\\!\\_ (.+)')
- for lineno, line in enumerate(open(filename, 'rb').readlines()):
- m = pattern.search(line)
- if m is not None:
- text = m.group(1).strip()
- if (text.startswith('"') or text.endswith('"') or text.startswith("'")) and text.endswith("'"):
- text = text[1:-1]
-
- yield (text, lineno)
- continue
-
-
- pot_location_template = '#: %(filename)s:%(lineno)s'
- pot_template = '%(locations)s\nmsgid "%(string)s"\nmsgstr ""\n\n'
-
- def xgettext_yaml(filelist, outputfilename):
- output = open(outputfilename, 'wb')
- print output, outputfilename
- strings = defaultdict(list)
- for f in open(filelist, 'rb').readlines():
- f = f.strip()
- for s, lineno in yield_translatable_yaml_strings(f):
- strings[s].append((f, lineno))
-
-
- for s, locations in sorted(strings.iteritems()):
- locations_string = '\n'.join((lambda .0: for f, lineno in .0:
- pot_location_template % dict(filename = f, lineno = lineno))(locations))
- output.write(pot_template % dict(locations = locations_string, string = s))
- output.write('\n')
-
-
-
- def xgettext(input_file, output_file, *args):
- buildutil.run([
- 'xgettext',
- '-s',
- '-k_',
- '--no-wrap'] + list(args) + [
- '--files-from=%s' % input_file,
- '--output=%s' % output_file])
-
-
- def doit(opts):
- check_for_i18n_tools()
- if opts.appfil is None and opts.po is None:
- pass
- doall = opts.mo is None
- if doall or opts.appfil:
- mkappfill.generate_fil_file(FIL_PATH, SOURCE_DIRS)
- mkappfill.generate_fil_file(FIL_YAML_PATH, YAML_SOURCE_DIRS, extensions = [
- '.yaml'])
- mkappfill.generate_fil_file(FIL_TENJIN_PATH, SOURCE_DIRS, extensions = [
- '.tenjin',
- '.py.xml'])
-
- if doall or opts.mo:
- mki18n.makeMO(DIGSBYROOT, MO_DIR, DOMAIN, True, poDir = PO_DIR)
-
-
-
- def options():
- import optparse
- parser = optparse.OptionParser()
- parser.add_option('-a', action = 'store_true', dest = 'appfil')
- parser.add_option('-p', action = 'store_true', dest = 'po')
- parser.add_option('-m', action = 'store_true', dest = 'mo')
- (opts, args) = parser.parse_args()
- return (opts, args)
-
-
- def main():
- (opts, args) = options()
- origdir = os.getcwd()
- os.chdir(DIGSBYROOT)
-
- try:
- doit(opts)
- finally:
- os.chdir(origdir)
-
-
-