Exemple #1
0
def main(argv=None):
    """
    Here we parse the flags (short, long) and we instantiate the classes.
    """
    parser = tx_main_parser()
    options, rest = parser.parse_known_args()
    if not options.command:
        parser.print_help()
        sys.exit(1)

    utils.DISABLE_COLORS = options.color_disable

    # set log level
    if options.quiet:
        set_log_level('WARNING')
    elif options.debug:
        set_log_level('DEBUG')

    web.cacerts_file = options.cacert

    # find .tx
    path_to_tx = options.root_dir or utils.find_dot_tx()

    cmd = options.command
    try:
        utils.exec_command(cmd, rest, path_to_tx)
    except SSLError as e:
        logger.error("SSL error %s" % e)
    except utils.UnknownCommandError:
        logger.error("Command %s not found" % cmd)
    except AuthenticationError:
        authentication_failed_message = """
Error: Authentication failed. Please make sure your credentials are valid.
For more information, visit:
https://docs.transifex.com/client/client-configuration#-transifexrc.
"""
        logger.error(authentication_failed_message)
    except Exception as e:
        import traceback
        if options.trace:
            traceback.print_exc()
        else:
            msg = "Unknown error" if not str(e) else str(e)
            logger.error(msg)
    # The else statement will be executed only if the command raised no
    # exceptions. If an exception was raised, we want to return a non-zero exit
    # code
    else:
        return
    sys.exit(1)
def main(argv=None):
    """
    Here we parse the flags (short, long) and we instantiate the classes.
    """
    parser = tx_main_parser()
    options, rest = parser.parse_known_args()
    if not options.command:
        parser.print_help()
        sys.exit(1)

    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 = options.command
    try:
        utils.exec_command(cmd, rest, path_to_tx)
    except SSLError as e:
        logger.error("SSL error %s" % e)
    except utils.UnknownCommandError:
        logger.error("Command %s not found" % cmd)
    except AuthenticationError:
        authentication_failed_message = """
Error: Authentication failed. Please make sure your credentials are valid.
For more information, visit:
https://docs.transifex.com/client/client-configuration#-transifexrc.
"""
        logger.error(authentication_failed_message)
    except Exception as e:
        import traceback
        if options.trace:
            traceback.print_exc()
        else:
            msg = "Unknown error" if not str(e) else str(e)
            logger.error(msg)
    # The else statement will be executed only if the command raised no
    # exceptions. If an exception was raised, we want to return a non-zero exit
    # code
    else:
        return
    sys.exit(1)
Exemple #3
0
def main(argv=None):
    """
    Here we parse the flags (short, long) and we instantiate the classes.
    """
    if argv is None:
        argv = sys.argv[1:]
    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=txclib.__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:
        utils.exec_command(cmd, args[1:], path_to_tx)
    except SSLError as e:
        logger.error("SSl error %s" % e)
        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)
Exemple #4
0
def main():
    """
    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`"
    argv = sys.argv[1:]
    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:
        utils.exec_command(cmd, args[1:], path_to_tx)
    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)