OC-2097:Fix init test. Fix classpath of oc-test
[pub/Android/ownCloud.git] / third_party / transifex-client / tx
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 from optparse import OptionParser, OptionValueError
5 import os
6 import sys
7
8 from txclib import utils
9 from txclib import get_version
10 from txclib.log import set_log_level, logger
11
12 reload(sys) # WTF? Otherwise setdefaultencoding doesn't work
13
14 # This block ensures that ^C interrupts are handled quietly.
15 try:
16 import signal
17
18 def exithandler(signum,frame):
19 signal.signal(signal.SIGINT, signal.SIG_IGN)
20 signal.signal(signal.SIGTERM, signal.SIG_IGN)
21 sys.exit(1)
22
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)
27
28 except KeyboardInterrupt:
29 sys.exit(1)
30
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')
34
35
36 def main(argv):
37 """
38 Here we parse the flags (short, long) and we instantiate the classes.
39 """
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"\
46 " command`"
47
48 parser = OptionParser(
49 usage=usage, version=get_version(), description=description
50 )
51 parser.disable_interspersed_args()
52 parser.add_option(
53 "-d", "--debug", action="store_true", dest="debug",
54 default=False, help=("enable debug messages")
55 )
56 parser.add_option(
57 "-q", "--quiet", action="store_true", dest="quiet",
58 default=False, help="don't print status messages to stdout"
59 )
60 parser.add_option(
61 "-r", "--root", action="store", dest="root_dir", type="string",
62 default=None, help="change root directory (default is cwd)"
63 )
64 parser.add_option(
65 "--traceback", action="store_true", dest="trace", default=False,
66 help="print full traceback on exceptions"
67 )
68 parser.add_option(
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"
72 )
73 (options, args) = parser.parse_args()
74
75 if len(args) < 1:
76 parser.error("No command was given")
77
78 utils.DISABLE_COLORS = options.color_disable
79
80 # set log level
81 if options.quiet:
82 set_log_level('WARNING')
83 elif options.debug:
84 set_log_level('DEBUG')
85
86 # find .tx
87 path_to_tx = options.root_dir or utils.find_dot_tx()
88
89
90 cmd = args[0]
91 try:
92 utils.exec_command(cmd, args[1:], path_to_tx)
93 except utils.UnknownCommandError:
94 logger.error("tx: Command %s not found" % cmd)
95 except SystemExit:
96 sys.exit()
97 except:
98 import traceback
99 if options.trace:
100 traceback.print_exc()
101 else:
102 formatted_lines = traceback.format_exc().splitlines()
103 logger.error(formatted_lines[-1])
104 sys.exit(1)
105
106 # Run baby :) ... run
107 if __name__ == "__main__":
108 # sys.argv[0] is the name of the script that we’re running.
109 main(sys.argv[1:])