Beispiel #1
0
def run_special_command(view, p4, user):
    """If view is a special command run it and return True; otherwise return False"""

    # @help: dump contents of help.txt, if file exists
    if p4gf_const.P4GF_UNREPO_HELP == view:
        helppath = os.path.join(os.path.dirname(__file__), 'help.txt')
        if not os.path.exists(helppath):
            sys.stderr.write("no help.txt found\n")
        else:
            with open(helppath, "r") as helpfile:
                for line in helpfile:
                    sys.stderr.write(line)
        return True

    # @info: dump info to stderr
    if p4gf_const.P4GF_UNREPO_INFO == view:
        sys.stderr.write(p4gf_version.as_string())
        sys.stderr.write("Server address: {}\n".format(p4.port))
        return True

    # @list: dump list of repos to stderr
    if p4gf_const.P4GF_UNREPO_LIST == view:
        repos = RepoList.list_for_user(p4, user).repos
        if len(repos):
            width = max([len(r[0]) for r in repos])
            sys.stderr.write("\n".join([
                "{name:<{width}} {perm}".format(
                    width=width, name=r[0], perm=r[1]) for r in repos
            ]) + "\n")
        else:
            sys.stderr.write("no repositories found\n")
        return True

    return False
def run_special_command(view, p4, user):
    """If view is a special command run it and return True; otherwise return False"""

    # @help: dump contents of help.txt, if file exists
    if p4gf_const.P4GF_UNREPO_HELP == view:
        helppath = os.path.join(os.path.dirname(__file__), 'help.txt')
        if not os.path.exists(helppath):
            sys.stderr.write("no help.txt found\n")
        else:
            with open(helppath, "r") as helpfile:
                for line in helpfile:
                    sys.stderr.write(line)
        return True

    # @info: dump info to stderr
    if p4gf_const.P4GF_UNREPO_INFO == view:
        sys.stderr.write(p4gf_version.as_string())
        sys.stderr.write("Server address: {}\n".format(p4.port))
        return True

    # @list: dump list of repos to stderr
    if p4gf_const.P4GF_UNREPO_LIST == view:
        repos = RepoList.list_for_user(p4, user).repos
        if len(repos):
            width = max([len(r[0]) for r in repos])
            sys.stderr.write("\n".join(["{name:<{width}} {perm}".format(width=width,
                                                                        name=r[0],
                                                                        perm=r[1])
                                        for r in repos]) + "\n")
        else:
            sys.stderr.write("no repositories found\n")
        return True

    return False
def run_special_command(view, p4, user):
    """If view is a special command run it and return True; otherwise return False"""

    # @help: dump contents of help.txt, if file exists
    if p4gf_const.P4GF_UNREPO_HELP == view:
        help_text = p4gf_util.read_bin_file('help.txt')
        if help_text == False:
            sys.stderr.write(_("file 'help.txt' not found\n"))
        else:
            sys.stderr.write(help_text)
        return True

    # @info: dump info to stderr
    if p4gf_const.P4GF_UNREPO_INFO == view:
        sys.stderr.write(p4gf_version.as_string())
        sys.stderr.write(_('Server address: {}\n').format(p4.port))
        return True

    # @list: dump list of repos to stderr
    if p4gf_const.P4GF_UNREPO_LIST == view:
        repos = RepoList.list_for_user(p4, user).repos
        if len(repos):
            width = max(len(r[0]) for r in repos)
            sys.stderr.write("\n".join(["{name:<{width}} {perm} {charset:<10} {desc}".format(
                width=width, name=p4gf_translate.TranslateReponame.repo_to_git(r[0]),
                perm=r[1], charset=r[2], desc=r[3])
                                        for r in repos]) + "\n")
        else:
            sys.stderr.write(_('no repositories found\n'))
        return True

    if p4gf_const.P4GF_UNREPO_MIRROR_WAIT == view:
        while p4gf_gitmirror.copying_trees():
            sys.stderr.write(_('waiting for mirror..\n'))
            sys.stderr.flush()
            time.sleep(1)
        sys.stderr.write(_('mirror up-to-date\n'))
        return True

    if p4gf_const.P4GF_UNREPO_MIRROR_STATUS == view:
        if p4gf_gitmirror.copying_trees():
            sys.stderr.write(_('mirroring trees\n'))
        else:
            sys.stderr.write(_('mirror up-to-date\n'))
        return True

        # clone @features just gives list of all available features
    if p4gf_const.P4GF_UNREPO_FEATURES == view:
        sys.stderr.write(_('Available features:\n'))
        for k in p4gf_config.configurable_features():
            sys.stderr.write("{} : {}\n".format(k, p4gf_config.FEATURE_KEYS[k]))
        return True

    # clone @features@repo tells which features are enabled for a repo
    if view.startswith(p4gf_const.P4GF_UNREPO_FEATURES+'@'):
        view = view[len(p4gf_const.P4GF_UNREPO_FEATURES)+1:]
        sys.stderr.write(_("Enabled features for repo '{}':\n").format(view))
        config = p4gf_config.get_repo(p4, view)
        for k in p4gf_config.configurable_features():
            sys.stderr.write("{} : {}\n"
                .format(k, p4gf_config.is_feature_enabled(config, k)))
        return True

    # If no previous match and view starts with '@'
    # then return list of special commands to client - no error
    if view.startswith('@'):
        special_cmds = ' '.join(p4gf_const.P4GF_UNREPO)
        sys.stderr.write(
                _('Git Fusion: unrecognized special command.\nValid commands are: {}') + '\n'.
                format(special_cmds))
        return True

    return False
 def __call__(self, parser, namespace, values, option_string=None):
     print(p4gf_version.as_string())
     exit(0)
Beispiel #5
0
def run_special_command(view, p4, user):
    """If view is a special command run it and return True; otherwise return False"""

    # @help: dump contents of help.txt, if file exists
    if p4gf_const.P4GF_UNREPO_HELP == view:
        help_text = p4gf_util.read_bin_file('help.txt')
        if help_text == False:
            sys.stderr.write(_("file 'help.txt' not found\n"))
        else:
            sys.stderr.write(help_text)
        return True

    # @info: dump info to stderr
    if p4gf_const.P4GF_UNREPO_INFO == view:
        sys.stderr.write(p4gf_version.as_string())
        sys.stderr.write(_('Server address: {}\n').format(p4.port))
        return True

    # @list: dump list of repos to stderr
    if p4gf_const.P4GF_UNREPO_LIST == view:
        repos = RepoList.list_for_user(p4, user).repos
        if len(repos):
            width = max(len(r[0]) for r in repos)
            sys.stderr.write("\n".join([
                "{name:<{width}} {perm} {charset:<10} {desc}".format(
                    width=width,
                    name=p4gf_translate.TranslateReponame.repo_to_git(r[0]),
                    perm=r[1],
                    charset=r[2],
                    desc=r[3]) for r in repos
            ]) + "\n")
        else:
            sys.stderr.write(_('no repositories found\n'))
        return True

    if p4gf_const.P4GF_UNREPO_MIRROR_WAIT == view:
        while p4gf_gitmirror.copying_trees():
            sys.stderr.write(_('waiting for mirror..\n'))
            sys.stderr.flush()
            time.sleep(1)
        sys.stderr.write(_('mirror up-to-date\n'))
        return True

    if p4gf_const.P4GF_UNREPO_MIRROR_STATUS == view:
        if p4gf_gitmirror.copying_trees():
            sys.stderr.write(_('mirroring trees\n'))
        else:
            sys.stderr.write(_('mirror up-to-date\n'))
        return True

        # clone @features just gives list of all available features
    if p4gf_const.P4GF_UNREPO_FEATURES == view:
        sys.stderr.write(_('Available features:\n'))
        for k in p4gf_config.configurable_features():
            sys.stderr.write("{} : {}\n".format(k,
                                                p4gf_config.FEATURE_KEYS[k]))
        return True

    # clone @features@repo tells which features are enabled for a repo
    if view.startswith(p4gf_const.P4GF_UNREPO_FEATURES + '@'):
        view = view[len(p4gf_const.P4GF_UNREPO_FEATURES) + 1:]
        sys.stderr.write(_("Enabled features for repo '{}':\n").format(view))
        config = p4gf_config.get_repo(p4, view)
        for k in p4gf_config.configurable_features():
            sys.stderr.write("{} : {}\n".format(
                k, p4gf_config.is_feature_enabled(config, k)))
        return True

    # If no previous match and view starts with '@'
    # then return list of special commands to client - no error
    if view.startswith('@'):
        special_cmds = ' '.join(p4gf_const.P4GF_UNREPO)
        sys.stderr.write(
            _('Git Fusion: unrecognized special command.\nValid commands are: {}'
              ) + '\n'.format(special_cmds))
        return True

    return False
Beispiel #6
0
 def __call__(self, parser, namespace, values, option_string=None):
     print(p4gf_version.as_string())
     exit(0)