fix dos format

This commit is contained in:
Marcos Pinto 2007-11-01 05:49:06 +00:00
parent c446d60ecd
commit 3c94a2039d
3 changed files with 228 additions and 228 deletions

438
msgfmt.py
View File

@ -1,219 +1,219 @@
# -*- coding: iso-8859-1 -*- # -*- coding: iso-8859-1 -*-
# Written by Martin v. Lwis <loewis@informatik.hu-berlin.de> # Written by Martin v. Lwis <loewis@informatik.hu-berlin.de>
# Plural forms support added by alexander smishlajev <alex@tycobka.lv> # Plural forms support added by alexander smishlajev <alex@tycobka.lv>
""" """
Generate binary message catalog from textual translation description. Generate binary message catalog from textual translation description.
This program converts a textual Uniforum-style message catalog (.po file) into This program converts a textual Uniforum-style message catalog (.po file) into
a binary GNU catalog (.mo file). This is essentially the same function as the a binary GNU catalog (.mo file). This is essentially the same function as the
GNU msgfmt program, however, it is a simpler implementation. GNU msgfmt program, however, it is a simpler implementation.
Usage: msgfmt.py [OPTIONS] filename.po Usage: msgfmt.py [OPTIONS] filename.po
Options: Options:
-o file -o file
--output-file=file --output-file=file
Specify the output file to write to. If omitted, output will go to a Specify the output file to write to. If omitted, output will go to a
file named filename.mo (based off the input file name). file named filename.mo (based off the input file name).
-h -h
--help --help
Print this message and exit. Print this message and exit.
-V -V
--version --version
Display version information and exit. Display version information and exit.
""" """
import sys import sys
import os import os
import getopt import getopt
import struct import struct
import array import array
__version__ = "1.1" __version__ = "1.1"
MESSAGES = {} MESSAGES = {}
def usage (ecode, msg=''): def usage (ecode, msg=''):
""" """
Print usage and msg and exit with given code. Print usage and msg and exit with given code.
""" """
print >> sys.stderr, __doc__ print >> sys.stderr, __doc__
if msg: if msg:
print >> sys.stderr, msg print >> sys.stderr, msg
sys.exit(ecode) sys.exit(ecode)
def add (msgid, transtr, fuzzy): def add (msgid, transtr, fuzzy):
""" """
Add a non-fuzzy translation to the dictionary. Add a non-fuzzy translation to the dictionary.
""" """
global MESSAGES global MESSAGES
if not fuzzy and transtr and not transtr.startswith('\0'): if not fuzzy and transtr and not transtr.startswith('\0'):
MESSAGES[msgid] = transtr MESSAGES[msgid] = transtr
def generate (): def generate ():
""" """
Return the generated output. Return the generated output.
""" """
global MESSAGES global MESSAGES
keys = MESSAGES.keys() keys = MESSAGES.keys()
# the keys are sorted in the .mo file # the keys are sorted in the .mo file
keys.sort() keys.sort()
offsets = [] offsets = []
ids = strs = '' ids = strs = ''
for _id in keys: for _id in keys:
# For each string, we need size and file offset. Each string is NUL # For each string, we need size and file offset. Each string is NUL
# terminated; the NUL does not count into the size. # terminated; the NUL does not count into the size.
offsets.append((len(ids), len(_id), len(strs), len(MESSAGES[_id]))) offsets.append((len(ids), len(_id), len(strs), len(MESSAGES[_id])))
ids += _id + '\0' ids += _id + '\0'
strs += MESSAGES[_id] + '\0' strs += MESSAGES[_id] + '\0'
output = '' output = ''
# The header is 7 32-bit unsigned integers. We don't use hash tables, so # The header is 7 32-bit unsigned integers. We don't use hash tables, so
# the keys start right after the index tables. # the keys start right after the index tables.
# translated string. # translated string.
keystart = 7*4+16*len(keys) keystart = 7*4+16*len(keys)
# and the values start after the keys # and the values start after the keys
valuestart = keystart + len(ids) valuestart = keystart + len(ids)
koffsets = [] koffsets = []
voffsets = [] voffsets = []
# The string table first has the list of keys, then the list of values. # The string table first has the list of keys, then the list of values.
# Each entry has first the size of the string, then the file offset. # Each entry has first the size of the string, then the file offset.
for o1, l1, o2, l2 in offsets: for o1, l1, o2, l2 in offsets:
koffsets += [l1, o1+keystart] koffsets += [l1, o1+keystart]
voffsets += [l2, o2+valuestart] voffsets += [l2, o2+valuestart]
offsets = koffsets + voffsets offsets = koffsets + voffsets
output = struct.pack("Iiiiiii", output = struct.pack("Iiiiiii",
0x950412deL, # Magic 0x950412deL, # Magic
0, # Version 0, # Version
len(keys), # # of entries len(keys), # # of entries
7*4, # start of key index 7*4, # start of key index
7*4+len(keys)*8, # start of value index 7*4+len(keys)*8, # start of value index
0, 0) # size and offset of hash table 0, 0) # size and offset of hash table
output += array.array("i", offsets).tostring() output += array.array("i", offsets).tostring()
output += ids output += ids
output += strs output += strs
return output return output
def make (filename, outfile): def make (filename, outfile):
ID = 1 ID = 1
STR = 2 STR = 2
global MESSAGES global MESSAGES
MESSAGES = {} MESSAGES = {}
# Compute .mo name from .po name and arguments # Compute .mo name from .po name and arguments
if filename.endswith('.po'): if filename.endswith('.po'):
infile = filename infile = filename
else: else:
infile = filename + '.po' infile = filename + '.po'
if outfile is None: if outfile is None:
outfile = os.path.splitext(infile)[0] + '.mo' outfile = os.path.splitext(infile)[0] + '.mo'
try: try:
lines = open(infile).readlines() lines = open(infile).readlines()
except IOError, msg: except IOError, msg:
print >> sys.stderr, msg print >> sys.stderr, msg
sys.exit(1) sys.exit(1)
section = None section = None
fuzzy = 0 fuzzy = 0
# Parse the catalog # Parse the catalog
msgid = msgstr = '' msgid = msgstr = ''
lno = 0 lno = 0
for l in lines: for l in lines:
lno += 1 lno += 1
# If we get a comment line after a msgstr, this is a new entry # If we get a comment line after a msgstr, this is a new entry
if l[0] == '#' and section == STR: if l[0] == '#' and section == STR:
add(msgid, msgstr, fuzzy) add(msgid, msgstr, fuzzy)
section = None section = None
fuzzy = 0 fuzzy = 0
# Record a fuzzy mark # Record a fuzzy mark
if l[:2] == '#,' and (l.find('fuzzy') >= 0): if l[:2] == '#,' and (l.find('fuzzy') >= 0):
fuzzy = 1 fuzzy = 1
# Skip comments # Skip comments
if l[0] == '#': if l[0] == '#':
continue continue
# Start of msgid_plural section, separate from singular form with \0 # Start of msgid_plural section, separate from singular form with \0
if l.startswith('msgid_plural'): if l.startswith('msgid_plural'):
msgid += '\0' msgid += '\0'
l = l[12:] l = l[12:]
# Now we are in a msgid section, output previous section # Now we are in a msgid section, output previous section
elif l.startswith('msgid'): elif l.startswith('msgid'):
if section == STR: if section == STR:
add(msgid, msgstr, fuzzy) add(msgid, msgstr, fuzzy)
section = ID section = ID
l = l[5:] l = l[5:]
msgid = msgstr = '' msgid = msgstr = ''
# Now we are in a msgstr section # Now we are in a msgstr section
elif l.startswith('msgstr'): elif l.startswith('msgstr'):
section = STR section = STR
l = l[6:] l = l[6:]
# Check for plural forms # Check for plural forms
if l.startswith('['): if l.startswith('['):
# Separate plural forms with \0 # Separate plural forms with \0
if not l.startswith('[0]'): if not l.startswith('[0]'):
msgstr += '\0' msgstr += '\0'
# Ignore the index - must come in sequence # Ignore the index - must come in sequence
l = l[l.index(']') + 1:] l = l[l.index(']') + 1:]
# Skip empty lines # Skip empty lines
l = l.strip() l = l.strip()
if not l: if not l:
continue continue
# XXX: Does this always follow Python escape semantics? # XXX: Does this always follow Python escape semantics?
l = eval(l) l = eval(l)
if section == ID: if section == ID:
msgid += l msgid += l
elif section == STR: elif section == STR:
msgstr += l msgstr += l
else: else:
print >> sys.stderr, 'Syntax error on %s:%d' % (infile, lno), \ print >> sys.stderr, 'Syntax error on %s:%d' % (infile, lno), \
'before:' 'before:'
print >> sys.stderr, l print >> sys.stderr, l
sys.exit(1) sys.exit(1)
# Add last entry # Add last entry
if section == STR: if section == STR:
add(msgid, msgstr, fuzzy) add(msgid, msgstr, fuzzy)
# Compute output # Compute output
output = generate() output = generate()
try: try:
open(outfile,"wb").write(output) open(outfile,"wb").write(output)
except IOError,msg: except IOError,msg:
print >> sys.stderr, msg print >> sys.stderr, msg
def main (): def main ():
try: try:
opts, args = getopt.getopt(sys.argv[1:], 'hVo:', opts, args = getopt.getopt(sys.argv[1:], 'hVo:',
['help', 'version', 'output-file=']) ['help', 'version', 'output-file='])
except getopt.error, msg: except getopt.error, msg:
usage(1, msg) usage(1, msg)
outfile = None outfile = None
# parse options # parse options
for opt, arg in opts: for opt, arg in opts:
if opt in ('-h', '--help'): if opt in ('-h', '--help'):
usage(0) usage(0)
elif opt in ('-V', '--version'): elif opt in ('-V', '--version'):
print >> sys.stderr, "msgfmt.py", __version__ print >> sys.stderr, "msgfmt.py", __version__
sys.exit(0) sys.exit(0)
elif opt in ('-o', '--output-file'): elif opt in ('-o', '--output-file'):
outfile = arg outfile = arg
# do it # do it
if not args: if not args:
print >> sys.stderr, 'No input file given' print >> sys.stderr, 'No input file given'
print >> sys.stderr, "Try `msgfmt --help' for more information." print >> sys.stderr, "Try `msgfmt --help' for more information."
return return
for filename in args: for filename in args:
make(filename, outfile) make(filename, outfile)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -194,11 +194,11 @@ if not OS == "win":
sources = sources) sources = sources)
else: else:
sources.remove('libtorrent\\src\\file.cpp') sources.remove('libtorrent\\src\\file.cpp')
deluge_core = Extension('deluge_core', deluge_core = Extension('deluge_core',
include_dirs = includedirs, include_dirs = includedirs,
libraries = librariestype, libraries = librariestype,
extra_compile_args = EXTRA_COMPILE_ARGS, extra_compile_args = EXTRA_COMPILE_ARGS,
extra_link_args = EXTRA_LINK_ARGS, extra_link_args = EXTRA_LINK_ARGS,
sources = sources) sources = sources)
# Thanks to Iain Nicol for code to save the location for installed prefix # Thanks to Iain Nicol for code to save the location for installed prefix

View File

@ -45,13 +45,13 @@ def windows_check():
return False return False
import sys import sys
if hasattr(sys, "frozen"): if hasattr(sys, "frozen"):
INSTALL_PREFIX = '' INSTALL_PREFIX = ''
os.chdir(os.path.dirname(unicode(sys.executable, sys.getfilesystemencoding( )))) os.chdir(os.path.dirname(unicode(sys.executable, sys.getfilesystemencoding( ))))
sys.stdout = open("deluge.stdout.log", "w") sys.stdout = open("deluge.stdout.log", "w")
sys.stderr = open("deluge.stderr.log", "w") sys.stderr = open("deluge.stderr.log", "w")
else: else:
# the necessary substitutions are made at installation time # the necessary substitutions are made at installation time
INSTALL_PREFIX = '@datadir@' INSTALL_PREFIX = '@datadir@'
if windows_check(): if windows_check():