예제 #1
0
def _parse_argv():
    '''Convert argv into a usable dict. Dump usage/help and exit if necessary.'''
    help_txt = p4gf_util.read_bin_file('p4gf_init_repo.help.txt')
    if help_txt is False:
        help_txt = _("Missing '{}' file!").format(NTR('p4gf_init_repo.help.txt'))
    parser = p4gf_util.create_arg_parser(
          desc        = _('Configure and populate Git Fusion repo.')
        , epilog      = None
        , usage       = _('p4gf_init_repo.py [options] <name>')
        , help_custom = help_txt)
    parser.add_argument('--start',   metavar="")
    parser.add_argument('--noclone', action=NTR('store_true'))
    parser.add_argument('--config')
    parser.add_argument('--p4client')
    parser.add_argument(NTR('view'),      metavar=NTR('view'))
    parser.add_argument('--charset')
    parser.add_argument('--enablemismatchedrhs', action=NTR('store_true'))
    args = parser.parse_args()
    if args.noclone and args.start:
        _print_stderr(_('Cannot use both --start and --noclone'))
        sys.exit(1)
    if args.config and args.charset:
        _print_stderr(_('Cannot use both --config and --charset'))
    if args.config and args.p4client:
        _print_stderr(_('Cannot use both --config and --p4client'))
    LOG.debug("args={}".format(args))
    return args
 def __call__(self, parser, namespace, values, option_string=None):
     if help_file:
         help_txt = p4gf_util.read_bin_file(help_file)
         print(help_txt)
     else:
         print(help_custom)
     sys.exit(0)
예제 #3
0
def _parse_argv():
    '''Convert argv into a usable dict. Dump usage/help and exit if necessary.'''
    help_txt = p4gf_util.read_bin_file('p4gf_init_repo.help.txt')
    if help_txt is False:
        help_txt = _("Missing '{}' file!").format(
            NTR('p4gf_init_repo.help.txt'))
    parser = p4gf_util.create_arg_parser(
        desc=_('Configure and populate Git Fusion repo.'),
        epilog=None,
        usage=_('p4gf_init_repo.py [options] <name>'),
        help_custom=help_txt)
    parser.add_argument('--start', metavar="")
    parser.add_argument('--noclone', action=NTR('store_true'))
    parser.add_argument('--config')
    parser.add_argument('--p4client')
    parser.add_argument(NTR('view'), metavar=NTR('view'))
    parser.add_argument('--charset')
    parser.add_argument('--enablemismatchedrhs', action=NTR('store_true'))
    args = parser.parse_args()
    if args.noclone and args.start:
        _print_stderr(_('Cannot use both --start and --noclone'))
        sys.exit(1)
    if args.config and args.charset:
        _print_stderr(_('Cannot use both --config and --charset'))
    if args.config and args.p4client:
        _print_stderr(_('Cannot use both --config and --p4client'))
    LOG.debug("args={}".format(args))
    return args
예제 #4
0
def comment_header_repo():
    '''
    Return the text dump that goes at the top of a newly created per-repo
    config file.
    '''
    header = p4gf_util.read_bin_file(NTR('p4gf_config.repo.txt'))
    if header is False:
        sys.stderr.write(_("no 'p4gf_config.repo.txt' found\n"))
        header = _('# Missing p4gf_config.repo.txt file!')
    return header
예제 #5
0
def comment_header_repo():
    '''
    Return the text dump that goes at the top of a newly created per-repo
    config file.
    '''
    header = p4gf_util.read_bin_file(NTR('p4gf_config.repo.txt'))
    if header is False:
        sys.stderr.write(_("no 'p4gf_config.repo.txt' found\n"))
        header = _('# Missing p4gf_config.repo.txt file!')
    return header
예제 #6
0
def check_and_create_default_p4gf_env_config():
    """If p4gf_env_config threw the MissingConfigPath exception,
    because P4GF_ENV names a non-existing filepath
    then save the required (two) default items
    into the user configured P4GF_ENV environment config file.
    """
    if not Create_P4GF_CONFIG:
        LOG.debug('not creating configuration file')
        return
    LOG.debug('creating missing configuration file')
    Verbosity.report(
        Verbosity.INFO, _("Git Fusion environment var P4GF_ENV = {path} names a non-existing file.")
        .format(path=p4gf_const.P4GF_ENV))
    Verbosity.report(
        Verbosity.INFO, _("Creating {path} with the default required items.")
        .format(path=p4gf_const.P4GF_ENV))
    Verbosity.report(
        Verbosity.INFO, _("Review the file's comments and edit as needed."))
    Verbosity.report(
        Verbosity.INFO, _("You may unset P4GF_ENV to use no config file.")
        .format(p4gf_const.P4GF_ENV))
    config = configparser.ConfigParser(interpolation  = None,
                                       allow_no_value = True)
    config.optionxform = str
    config.add_section(p4gf_const.SECTION_ENVIRONMENT)
    config.set(p4gf_const.SECTION_ENVIRONMENT, p4gf_const.P4GF_HOME_NAME, p4gf_const.P4GF_HOME)
    Verbosity.report(
        Verbosity.INFO, _("Setting {home_name} = {home} in {env}.")
        .format(home_name=p4gf_const.P4GF_HOME_NAME,
                home=p4gf_const.P4GF_HOME,
                env=p4gf_const.P4GF_ENV))
    config.set(p4gf_const.SECTION_ENVIRONMENT, NTR('P4PORT'), P4PORT)
    Verbosity.report(
        Verbosity.INFO, _("Setting {p4port} = {p4port_value} in {env}.")
        .format(p4port=NTR('P4PORT'),
                p4port_value=P4PORT,
                env=p4gf_const.P4GF_ENV))
    header = p4gf_util.read_bin_file(NTR('p4gf_env_config.txt'))
    if header is False:
        sys.stderr.write(_('no p4gf_env_config.txt found\n'))
        header = _('# Missing p4gf_env_config.txt file!')
    out = io.StringIO()
    out.write(header)
    config.write(out)
    file_content = out.getvalue()
    out.close()
    p4gf_util.ensure_dir(p4gf_util.parent_dir(p4gf_const.P4GF_ENV))
    with open(p4gf_const.P4GF_ENV, 'w') as f:
        f.write(file_content)
    LOG.debug('created configuration file %s', p4gf_const.P4GF_ENV)
예제 #7
0
def check_and_create_default_p4gf_env_config():
    '''If p4gf_env_config threw the MissingConfigPath exception,
    because P4GF_ENV names a non-existing filepath
    then save the required (two) default items
    into the user configured P4GF_ENV environment config file.
    '''
    if not Create_P4GF_CONFIG:
        return
    Verbosity.report(Verbosity.INFO,
            _("Git Fusion environment var P4GF_ENV = {0} names a non-existing file.")
            .format(p4gf_const.P4GF_ENV))
    Verbosity.report(Verbosity.INFO, _("Creating {0} with the default required items.")
            .format(p4gf_const.P4GF_ENV))
    Verbosity.report(Verbosity.INFO, _("Review the file's comments and edit as needed."))
    Verbosity.report(Verbosity.INFO, _("You may unset P4GF_ENV to use no config file.")
            .format(p4gf_const.P4GF_ENV))
    config = configparser.ConfigParser(interpolation  = None,
                                       allow_no_value = True)
    config.optionxform = str
    config.add_section(p4gf_const.SECTION_ENVIRONMENT)
    config.set(p4gf_const.SECTION_ENVIRONMENT, p4gf_const.P4GF_HOME_NAME, p4gf_const.P4GF_HOME)
    Verbosity.report(Verbosity.INFO, _("Setting {0} = {1} in {2}.")
            .format(p4gf_const.P4GF_HOME_NAME, p4gf_const.P4GF_HOME, p4gf_const.P4GF_ENV))
    config.set(p4gf_const.SECTION_ENVIRONMENT, NTR('P4PORT'), P4PORT)
    Verbosity.report(Verbosity.INFO, _("Setting {0} = {1} in {2}.")
        .format(NTR('P4PORT'), P4PORT, p4gf_const.P4GF_ENV))
    header = p4gf_util.read_bin_file(NTR('p4gf_env_config.txt'))
    if header is False:
        sys.stderr.write(_('no p4gf_env_config.txt found\n'))
        header = _('# Missing p4gf_env_config.txt file!')
    out = io.StringIO()
    out.write(header)
    config.write(out)
    file_content = out.getvalue()
    out.close()
    p4gf_util.ensure_dir(p4gf_util.parent_dir(p4gf_const.P4GF_ENV))
    with open(p4gf_const.P4GF_ENV, 'w') as f:
        f.write(file_content)
예제 #8
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
예제 #9
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