def cmd_set(argv, path_to_tx):
    "Add local or remote files under transifex"
    parser = set_parser()
    (options, args) = parser.parse_args(argv)

    # Implement options/args checks
    # TODO !!!!!!!
    if options.local:
        try:
            expression = args[0]
        except IndexError:
            parser.error("Please specify an expression.")
        if not options.resource:
            parser.error("Please specify a resource")
        if not options.source_language:
            parser.error("Please specify a source language.")
        if not '<lang>' in expression:
            parser.error("The expression you have provided is not valid.")
        if not utils.valid_slug(options.resource):
            parser.error("Invalid resource slug. The format is <project_slug>"\
                ".<resource_slug> and the valid characters include [_-\w].")
        _auto_local(path_to_tx, options.resource,
            source_language=options.source_language,
            expression = expression, source_file=options.source_file,
            execute=options.execute, regex=False)
        if options.execute:
            _set_minimum_perc(options.resource, options.minimum_perc, path_to_tx)
            _set_mode(options.resource, options.mode, path_to_tx)
            _set_type(options.resource, options.i18n_type, path_to_tx)
        return

    if options.remote:
        try:
            url = args[0]
        except IndexError:
            parser.error("Please specify an remote url")
        _auto_remote(path_to_tx, url)
        _set_minimum_perc(options.resource, options.minimum_perc, path_to_tx)
        _set_mode(options.resource, options.mode, path_to_tx)
        return

    if options.is_source:
        resource = options.resource
        if not resource:
            parser.error("You must specify a resource name with the"
                " -r|--resource flag.")

        lang = options.language
        if not lang:
            parser.error("Please specify a source language.")

        if len(args) != 1:
            parser.error("Please specify a file.")

        if not utils.valid_slug(resource):
            parser.error("Invalid resource slug. The format is <project_slug>"\
                ".<resource_slug> and the valid characters include [_-\w].")

        file = args[0]
        # Calculate relative path
        path_to_file = relpath(file, path_to_tx)
        _set_source_file(path_to_tx, resource, options.language, path_to_file)
    elif options.resource or options.language:
        resource = options.resource
        lang = options.language

        if len(args) != 1:
            parser.error("Please specify a file")

        # Calculate relative path
        path_to_file = relpath(args[0], path_to_tx)

        try:
            _go_to_dir(path_to_tx)
        except UnInitializedError, e:
            utils.logger.error(e)
            return

        if not utils.valid_slug(resource):
            parser.error("Invalid resource slug. The format is <project_slug>"\
                ".<resource_slug> and the valid characters include [_-\w].")
        _set_translation(path_to_tx, resource, lang, path_to_file)
Beispiel #2
0
def cmd_set(argv, path_to_tx):
    "Add local or remote files under transifex"
    parser = set_parser()
    (options, args) = parser.parse_args(argv)

    # Implement options/args checks
    # TODO !!!!!!!
    if options.local:
        try:
            expression = args[0]
        except IndexError:
            parser.error("Please specify an expression.")
        if not options.resource:
            parser.error("Please specify a resource")
        if not options.source_language:
            parser.error("Please specify a source language.")
        if not '<lang>' in expression:
            parser.error("The expression you have provided is not valid.")
        if not utils.valid_slug(options.resource):
            parser.error("Invalid resource slug. The format is <project_slug>"\
                ".<resource_slug> and the valid characters include [_-\w].")
        _auto_local(path_to_tx,
                    options.resource,
                    source_language=options.source_language,
                    expression=expression,
                    source_file=options.source_file,
                    execute=options.execute,
                    regex=False)
        if options.execute:
            _set_minimum_perc(options.resource, options.minimum_perc,
                              path_to_tx)
            _set_mode(options.resource, options.mode, path_to_tx)
            _set_type(options.resource, options.i18n_type, path_to_tx)
        return

    if options.remote:
        try:
            url = args[0]
        except IndexError:
            parser.error("Please specify an remote url")
        _auto_remote(path_to_tx, url)
        _set_minimum_perc(options.resource, options.minimum_perc, path_to_tx)
        _set_mode(options.resource, options.mode, path_to_tx)
        return

    if options.is_source:
        resource = options.resource
        if not resource:
            parser.error("You must specify a resource name with the"
                         " -r|--resource flag.")

        lang = options.language
        if not lang:
            parser.error("Please specify a source language.")

        if len(args) != 1:
            parser.error("Please specify a file.")

        if not utils.valid_slug(resource):
            parser.error("Invalid resource slug. The format is <project_slug>"\
                ".<resource_slug> and the valid characters include [_-\w].")

        file = args[0]
        # Calculate relative path
        path_to_file = relpath(file, path_to_tx)
        _set_source_file(path_to_tx, resource, options.language, path_to_file)
    elif options.resource or options.language:
        resource = options.resource
        lang = options.language

        if len(args) != 1:
            parser.error("Please specify a file")

        # Calculate relative path
        path_to_file = relpath(args[0], path_to_tx)

        try:
            _go_to_dir(path_to_tx)
        except UnInitializedError, e:
            utils.logger.error(e)
            return

        if not utils.valid_slug(resource):
            parser.error("Invalid resource slug. The format is <project_slug>"\
                ".<resource_slug> and the valid characters include [_-\w].")
        _set_translation(path_to_tx, resource, lang, path_to_file)
Beispiel #3
0
def cmd_set(argv, path_to_tx):
    "Add local or remote files under transifex"

    class EpilogParser(OptionParser):
       def format_epilog(self, formatter):
           return self.epilog

    usage="usage: %prog [tx_options] set [options] [args]"
    description="This command can be used to create a mapping between files"\
        " and projects either using local files or using files from a remote"\
        " Transifex server."
    epilog="\nExamples:\n"\
        " To set the source file:\n  $ tx set -r project.resource --source -l en <file>\n\n"\
        " To set a single translation file:\n  $ tx set -r project.resource -l de <file>\n\n"\
        " To automatically detect and assign translation files:\n"\
        "  $ tx set --auto-local -r project.resource 'expr'\n\n"\
        " To automatically detect and assign the source files and translations:\n"\
        "  $ tx set --auto-local -r project.resource 'expr' --source-lang en\n\n"\
        " To set a specific file as a source and auto detect translations:\n"\
        "  $ tx set --auto-local -r project.resource 'expr' --source-lang en"\
        " --source-file <file>\n\n"\
        " To set a remote release/resource/project:\n"\
        "  $ tx set --auto-remote <transifex-url>\n"
    parser = EpilogParser(usage=usage, description=description, epilog=epilog)
    parser.add_option("--auto-local", action="store_true", dest="local",
        default=False, help="Used when auto configuring local project.")
    parser.add_option("--auto-remote", action="store_true", dest="remote",
        default=False, help="Used when adding remote files from Transifex"
        " server.")
    parser.add_option("-r","--resource", action="store", dest="resource",
        default=None, help="Specify the slug of the resource that you're"
            " setting up (This must be in the following format:"
            " `project_slug.resource_slug`).")
    parser.add_option("--source", action="store_true", dest="is_source",
        default=False, help="Specify that added file a source file [doesn't"
        " work with the --auto-* commands].")
    parser.add_option("-l","--language", action="store", dest="language",
        default=None, help="Specify which translations you want to pull"
        " [doesn't work with the --auto-* commands].")
    group = OptionGroup(parser, "Extended options", "These options can only be"
        " used with the --auto-local command.")
    group.add_option("-s","--source-language", action="store",
        dest="source_language",
        default=None, help="Specify the source language of a resource"
        " [requires --auto-local].")
    group.add_option("-f","--source-file", action="store", dest="source_file",
        default=None, help="Specify the source file of a resource [requires"
        " --auto-local].")
    group.add_option("--execute", action="store_true", dest="execute",
        default=False, help="Execute commands [requires --auto-local].")
    parser.add_option_group(group)

    (options, args) = parser.parse_args(argv)

    # Implement options/args checks
    # TODO !!!!!!!

    # if --auto is true
    if options.local:
        try:
            expression = args[0]
        except IndexError:
            parser.error("Please specify an expression.")
        if not options.resource:
            parser.error("Please specify a resource")
        if not options.source_language:
            parser.error("Please specify a source language.")
        if not '<lang>' in expression:
            parser.error("The expression you have provided is not valid.")
        if not utils.valid_slug(options.resource):
            parser.error("Invalid resource slug. The format is <project_slug>"\
                ".<resource_slug> and the valid characters include [_-\w].")
        _auto_local(path_to_tx, options.resource,
            source_language=options.source_language,
            expression = expression, source_file=options.source_file,
            execute=options.execute, nosource=False, regex=False)
    elif options.remote:
        try:
            url = args[0]
        except IndexError:
            parser.error("Please specify an remote url")
        _auto_remote(path_to_tx, url)
    # if we have --source, we set source
    elif options.is_source:
        resource = options.resource
        if not resource:
            parser.error("You must specify a resource name with the"
                " -r|--resource flag.")

        lang = options.language
        if not lang:
            parser.error("Please specify a source language.")

        if len(args) != 1:
            parser.error("Please specify a file.")

        if not utils.valid_slug(resource):
            parser.error("Invalid resource slug. The format is <project_slug>"\
                ".<resource_slug> and the valid characters include [_-\w].")

        file = args[0]
        # Calculate relative path
        path_to_file = relpath(file, path_to_tx)
        _set_source_file(path_to_tx, resource, options.language, path_to_file)

    else:
        resource = options.resource
        lang = options.language

        if not resource or not lang:
            parser.error("You need to specify a resource and a language for the"
                " translation")

        if len(args) != 1:
            parser.error("Please specify a file")

        # Calculate relative path
        path_to_file = relpath(args[0], path_to_tx)

        try:
            _go_to_dir(path_to_tx)
        except UnInitializedError, e:
            utils.ERRMSG(e)
            return

        if not utils.valid_slug(resource):
            parser.error("Invalid resource slug. The format is <project_slug>"\
                ".<resource_slug> and the valid characters include [_-\w].")

        _set_translation(path_to_tx, resource, lang, path_to_file)
Beispiel #4
0
def cmd_set(argv, path_to_tx):
    "Add local or remote files under transifex"

    class EpilogParser(OptionParser):
        def format_epilog(self, formatter):
            return self.epilog

    usage = "usage: %prog [tx_options] set [options] [args]"
    description="This command can be used to create a mapping between files"\
        " and projects either using local files or using files from a remote"\
        " Transifex server."
    epilog="\nExamples:\n"\
        " To set the source file:\n  $ tx set -r project.resource --source -l en <file>\n\n"\
        " To set a single translation file:\n  $ tx set -r project.resource -l de <file>\n\n"\
        " To automatically detect and assign translation files:\n"\
        "  $ tx set --auto-local -r project.resource 'expr'\n\n"\
        " To automatically detect and assign the source files and translations:\n"\
        "  $ tx set --auto-local -r project.resource 'expr' --source-lang en\n\n"\
        " To set a specific file as a source and auto detect translations:\n"\
        "  $ tx set --auto-local -r project.resource 'expr' --source-lang en"\
        " --source-file <file>\n\n"\
        " To set a remote release/resource/project:\n"\
        "  $ tx set --auto-remote <transifex-url>\n"
    parser = EpilogParser(usage=usage, description=description, epilog=epilog)
    parser.add_option("--auto-local",
                      action="store_true",
                      dest="local",
                      default=False,
                      help="Used when auto configuring local project.")
    parser.add_option("--auto-remote",
                      action="store_true",
                      dest="remote",
                      default=False,
                      help="Used when adding remote files from Transifex"
                      " server.")
    parser.add_option("-r",
                      "--resource",
                      action="store",
                      dest="resource",
                      default=None,
                      help="Specify the slug of the resource that you're"
                      " setting up (This must be in the following format:"
                      " `project_slug.resource_slug`).")
    parser.add_option("--source",
                      action="store_true",
                      dest="is_source",
                      default=False,
                      help="Specify that added file a source file [doesn't"
                      " work with the --auto-* commands].")
    parser.add_option("-l",
                      "--language",
                      action="store",
                      dest="language",
                      default=None,
                      help="Specify which translations you want to pull"
                      " [doesn't work with the --auto-* commands].")
    group = OptionGroup(
        parser, "Extended options", "These options can only be"
        " used with the --auto-local command.")
    group.add_option("-s",
                     "--source-language",
                     action="store",
                     dest="source_language",
                     default=None,
                     help="Specify the source language of a resource"
                     " [requires --auto-local].")
    group.add_option("-f",
                     "--source-file",
                     action="store",
                     dest="source_file",
                     default=None,
                     help="Specify the source file of a resource [requires"
                     " --auto-local].")
    group.add_option("--execute",
                     action="store_true",
                     dest="execute",
                     default=False,
                     help="Execute commands [requires --auto-local].")
    parser.add_option_group(group)

    (options, args) = parser.parse_args(argv)

    # Implement options/args checks
    # TODO !!!!!!!

    # if --auto is true
    if options.local:
        try:
            expression = args[0]
        except IndexError:
            parser.error("Please specify an expression.")
        if not options.resource:
            parser.error("Please specify a resource")
        if not options.source_language:
            parser.error("Please specify a source language.")
        if not '<lang>' in expression:
            parser.error("The expression you have provided is not valid.")
        if not utils.valid_slug(options.resource):
            parser.error("Invalid resource slug. The format is <project_slug>"\
                ".<resource_slug> and the valid characters include [_-\w].")
        _auto_local(path_to_tx,
                    options.resource,
                    source_language=options.source_language,
                    expression=expression,
                    source_file=options.source_file,
                    execute=options.execute,
                    nosource=False,
                    regex=False)
    elif options.remote:
        try:
            url = args[0]
        except IndexError:
            parser.error("Please specify an remote url")
        _auto_remote(path_to_tx, url)
    # if we have --source, we set source
    elif options.is_source:
        resource = options.resource
        if not resource:
            parser.error("You must specify a resource name with the"
                         " -r|--resource flag.")

        lang = options.language
        if not lang:
            parser.error("Please specify a source language.")

        if len(args) != 1:
            parser.error("Please specify a file.")

        if not utils.valid_slug(resource):
            parser.error("Invalid resource slug. The format is <project_slug>"\
                ".<resource_slug> and the valid characters include [_-\w].")

        file = args[0]
        # Calculate relative path
        path_to_file = relpath(file, path_to_tx)
        _set_source_file(path_to_tx, resource, options.language, path_to_file)

    else:
        resource = options.resource
        lang = options.language

        if not resource or not lang:
            parser.error(
                "You need to specify a resource and a language for the"
                " translation")

        if len(args) != 1:
            parser.error("Please specify a file")

        # Calculate relative path
        path_to_file = relpath(args[0], path_to_tx)

        try:
            _go_to_dir(path_to_tx)
        except UnInitializedError, e:
            utils.ERRMSG(e)
            return

        if not utils.valid_slug(resource):
            parser.error("Invalid resource slug. The format is <project_slug>"\
                ".<resource_slug> and the valid characters include [_-\w].")

        _set_translation(path_to_tx, resource, lang, path_to_file)