mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-19 06:43:58 -07:00
It includes the translation template files (POT) as well as translation files (PO) developer through the Transifex platform by our awesome translators. It also includes tools to generate the translation template files, generate a special translation file with the longest strigns of all translations, and a tool to download translations from Transifex into the right game folders automatically. Fixes #67 This was SVN commit r14955.
119 lines
3.7 KiB
Python
119 lines
3.7 KiB
Python
#!/usr/bin/env python
|
||
# -*- coding: utf-8 -*-
|
||
|
||
from optparse import OptionParser, OptionValueError
|
||
import os
|
||
import sys
|
||
import ssl
|
||
import errno
|
||
from txclib import utils
|
||
from txclib import get_version
|
||
from txclib.log import set_log_level, logger
|
||
|
||
reload(sys) # WTF? Otherwise setdefaultencoding doesn't work
|
||
|
||
# This block ensures that ^C interrupts are handled quietly.
|
||
try:
|
||
import signal
|
||
|
||
def exithandler(signum,frame):
|
||
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
||
signal.signal(signal.SIGTERM, signal.SIG_IGN)
|
||
sys.exit(1)
|
||
|
||
signal.signal(signal.SIGINT, exithandler)
|
||
signal.signal(signal.SIGTERM, exithandler)
|
||
if hasattr(signal, 'SIGPIPE'):
|
||
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
|
||
|
||
except KeyboardInterrupt:
|
||
sys.exit(1)
|
||
|
||
# When we open file with f = codecs.open we specifi FROM what encoding to read
|
||
# This sets the encoding for the strings which are created with f.read()
|
||
sys.setdefaultencoding('utf-8')
|
||
|
||
|
||
def main(argv):
|
||
"""
|
||
Here we parse the flags (short, long) and we instantiate the classes.
|
||
"""
|
||
usage = "usage: %prog [options] command [cmd_options]"
|
||
description = "This is the Transifex command line client which"\
|
||
" allows you to manage your translations locally and sync"\
|
||
" them with the master Transifex server.\nIf you'd like to"\
|
||
" check the available commands issue `%prog help` or if you"\
|
||
" just want help with a specific command issue `%prog help"\
|
||
" command`"
|
||
|
||
parser = OptionParser(
|
||
usage=usage, version=get_version(), description=description
|
||
)
|
||
parser.disable_interspersed_args()
|
||
parser.add_option(
|
||
"-d", "--debug", action="store_true", dest="debug",
|
||
default=False, help=("enable debug messages")
|
||
)
|
||
parser.add_option(
|
||
"-q", "--quiet", action="store_true", dest="quiet",
|
||
default=False, help="don't print status messages to stdout"
|
||
)
|
||
parser.add_option(
|
||
"-r", "--root", action="store", dest="root_dir", type="string",
|
||
default=None, help="change root directory (default is cwd)"
|
||
)
|
||
parser.add_option(
|
||
"--traceback", action="store_true", dest="trace", default=False,
|
||
help="print full traceback on exceptions"
|
||
)
|
||
parser.add_option(
|
||
"--disable-colors", action="store_true", dest="color_disable",
|
||
default=(os.name == 'nt' or not sys.stdout.isatty()),
|
||
help="disable colors in the output of commands"
|
||
)
|
||
(options, args) = parser.parse_args()
|
||
|
||
if len(args) < 1:
|
||
parser.error("No command was given")
|
||
|
||
utils.DISABLE_COLORS = options.color_disable
|
||
|
||
# set log level
|
||
if options.quiet:
|
||
set_log_level('WARNING')
|
||
elif options.debug:
|
||
set_log_level('DEBUG')
|
||
|
||
# find .tx
|
||
path_to_tx = options.root_dir or utils.find_dot_tx()
|
||
|
||
|
||
cmd = args[0]
|
||
try:
|
||
print "utils.exec_command(" + str(cmd) + ", " + str(args[1:]) + ", " + path_to_tx + ")"
|
||
utils.exec_command(cmd, args[1:], path_to_tx)
|
||
except ssl.SSLError as e:
|
||
if 'certificate verify failed' in e.strerror:
|
||
logger.error(
|
||
'Error: Could not verify the SSL certificate of the remote host'
|
||
)
|
||
else:
|
||
logger.error(errno.errorcode[e.errno])
|
||
sys.exit(1)
|
||
except utils.UnknownCommandError:
|
||
logger.error("tx: Command %s not found" % cmd)
|
||
except SystemExit:
|
||
sys.exit()
|
||
except:
|
||
import traceback
|
||
if options.trace:
|
||
traceback.print_exc()
|
||
else:
|
||
formatted_lines = traceback.format_exc().splitlines()
|
||
logger.error(formatted_lines[-1])
|
||
sys.exit(1)
|
||
|
||
# Run baby :) ... run
|
||
if __name__ == "__main__":
|
||
# sys.argv[0] is the name of the script that we’re running.
|
||
main(sys.argv[1:])
|