home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import sys
- import os
- import struct
- import array
- __version__ = '1.2'
-
- def usage(code, msg = ''):
- print >>sys.stderr, __doc__
- if msg:
- print >>sys.stderr, msg
-
- sys.exit(code)
-
-
- def add(id, str, fuzzy, MESSAGES):
- if not fuzzy and str:
- MESSAGES[id] = str
-
-
-
- def generate(MESSAGES):
- keys = MESSAGES.keys()
- keys.sort()
- offsets = []
- ids = strs = ''
- for id in keys:
- offsets.append((len(ids), len(id), len(strs), len(MESSAGES[id])))
- ids += id + '\x00'
- strs += MESSAGES[id] + '\x00'
-
- keystart = 28 + 16 * len(keys)
- valuestart = keystart + len(ids)
- koffsets = []
- voffsets = []
- for o1, l1, o2, l2 in offsets:
- koffsets += [
- l1,
- o1 + keystart]
- voffsets += [
- l2,
- o2 + valuestart]
-
- offsets = koffsets + voffsets
- output = struct.pack('Iiiiiii', 0x950412DEL, 0, len(keys), 28, 28 + len(keys) * 8, 0, 0)
- output += array.array('i', offsets).tostring()
- output += ids
- output += strs
- return output
-
-
- def make(filename, outfile):
- MESSAGES = { }
- ID = 1
- STR = 2
- if filename.endswith('.po'):
- infile = filename
- else:
- infile = filename + '.po'
- if outfile is None:
- outfile = os.path.splitext(infile)[0] + '.mo'
-
-
- try:
- lines = open(infile).readlines()
- except IOError:
- msg = None
- print >>sys.stderr, msg
- sys.exit(1)
-
- section = None
- fuzzy = 0
- lno = 0
- msgid = msgstr = ''
- for l in lines:
- lno += 1
- if l[0] == '#' and section == STR:
- add(msgid, msgstr, fuzzy, MESSAGES)
- section = None
- fuzzy = 0
-
- if l[:2] == '#,' and 'fuzzy' in l:
- fuzzy = 1
-
- if l[0] == '#':
- continue
-
- if l.startswith('msgid'):
- if section == STR:
- add(msgid, msgstr, fuzzy, MESSAGES)
-
- section = ID
- l = l[5:]
- msgid = msgstr = ''
- elif l.startswith('msgstr'):
- section = STR
- l = l[6:]
-
- l = l.strip()
- if not l:
- continue
-
- l = eval(l)
- if section == ID:
- msgid += l
- continue
- if section == STR:
- msgstr += l
- continue
- print >>sys.stderr, 'Syntax error on %s:%d' % (infile, lno), 'before:'
- print >>sys.stderr, l
- sys.exit(1)
-
- if section == STR:
- add(msgid, msgstr, fuzzy, MESSAGES)
-
- output = generate(MESSAGES)
-
- try:
- outfile.write(output)
- except IOError:
- msg = None
- print >>sys.stderr, msg
-
-
-
- def main(outfile, args = sys.argv[1:]):
- for filename in args:
- make(filename, outfile)
-
- return 0
-
- if __name__ == '__main__':
- sys.exit(main(sys.stdout))
-
-