2 # -*- coding: utf-8 -*-
4 from optparse
import OptionParser
, OptionValueError
8 from txclib
import utils
9 from txclib
import get_version
10 from txclib
.log
import set_log_level
, logger
12 reload(sys
) # WTF? Otherwise setdefaultencoding doesn't work
14 # This block ensures that ^C interrupts are handled quietly.
18 def exithandler(signum
,frame
):
19 signal
.signal(signal
.SIGINT
, signal
.SIG_IGN
)
20 signal
.signal(signal
.SIGTERM
, signal
.SIG_IGN
)
23 signal
.signal(signal
.SIGINT
, exithandler
)
24 signal
.signal(signal
.SIGTERM
, exithandler
)
25 if hasattr(signal
, 'SIGPIPE'):
26 signal
.signal(signal
.SIGPIPE
, signal
.SIG_DFL
)
28 except KeyboardInterrupt:
31 # When we open file with f = codecs.open we specifi FROM what encoding to read
32 # This sets the encoding for the strings which are created with f.read()
33 sys
.setdefaultencoding('utf-8')
38 Here we parse the flags (short, long) and we instantiate the classes.
40 usage
= "usage: %prog [options] command [cmd_options]"
41 description
= "This is the Transifex command line client which"\
42 " allows you to manage your translations locally and sync"\
43 " them with the master Transifex server.\nIf you'd like to"\
44 " check the available commands issue `%prog help` or if you"\
45 " just want help with a specific command issue `%prog help"\
48 parser
= OptionParser(
49 usage
=usage
, version
=get_version(), description
=description
51 parser
.disable_interspersed_args()
53 "-d", "--debug", action
="store_true", dest
="debug",
54 default
=False, help=("enable debug messages")
57 "-q", "--quiet", action
="store_true", dest
="quiet",
58 default
=False, help="don't print status messages to stdout"
61 "-r", "--root", action
="store", dest
="root_dir", type="string",
62 default
=None, help="change root directory (default is cwd)"
65 "--traceback", action
="store_true", dest
="trace", default
=False,
66 help="print full traceback on exceptions"
69 "--disable-colors", action
="store_true", dest
="color_disable",
70 default
=(os
.name
== 'nt' or not sys
.stdout
.isatty()),
71 help="disable colors in the output of commands"
73 (options
, args
) = parser
.parse_args()
76 parser
.error("No command was given")
78 utils
.DISABLE_COLORS
= options
.color_disable
82 set_log_level('WARNING')
84 set_log_level('DEBUG')
87 path_to_tx
= options
.root_dir
or utils
.find_dot_tx()
92 utils
.exec_command(cmd
, args
[1:], path_to_tx
)
93 except utils
.UnknownCommandError
:
94 logger
.error("tx: Command %s not found" % cmd
)
100 traceback
.print_exc()
102 formatted_lines
= traceback
.format_exc().splitlines()
103 logger
.error(formatted_lines
[-1])
106 # Run baby :) ... run
107 if __name__
== "__main__":
108 # sys.argv[0] is the name of the script that we’re running.