示例#1
0
文件: hgcfg.py 项目: jimfuqua/tutorW
def getconfigs(ui, repo):
    """
    Get a sequence of possible configuration files, including local
    (repository), user, and global.

    Each item in the returned sequence is a dictionary with the following keys:

    `scope`
        One of 'local', 'user', or 'global'.

    `path`
        The filesystem path to the config file.

    `exists`
        A `bool` indicating whether or not the file currently exists on the
        filesystem.

    `writeable`
        A `bool` indicating whether or not the file is writeable by the
        current user.
            
    """
    allconfigs = rcpath()
    local_config = localrc(repo)
    if local_config is not None:
        # rcpath() returns a reference to a global list, must not modify
        # it in place by "+=" but instead create a copy by "+".
        allconfigs = allconfigs + [local_config]
    userconfigs = set(userrcpath())

    configs = []
    paths = set()

    # for all global configs
    for f in allconfigs:
        if f in paths:
            continue
        paths.add(f)

        if f == local_config:
            scope = 'local'
        elif f in userconfigs:
            scope = 'user'
        else:
            scope = 'global'
        if not os.path.exists(f):
            exists = False
            writeable = False
        else:
            exists = True
            if os.access(f, os.W_OK):
                writeable = True
            else:
                writeable = False
        configs.append({'scope': scope, 'path': f, 'exists': exists,
            'writeable': writeable})

    return configs
示例#2
0
def user_config():
    """Read the Mercurial user configuration

    This is typically ~/.hgrc on POSIX.  This is returned
    as a Mercurial.config.config object.
    """
    hgrc = config()
    for cfg in userrcpath():
        if not os.path.exists(cfg):
            log("NOT reading missing cfg: " + cfg)
            continue
        log("Reading config: " + cfg)
        hgrc.read(cfg)
    return hgrc
示例#3
0
文件: util.py 项目: RavenB/gitifyhg
def user_config():
    """Read the Mercurial user configuration

    This is typically ~/.hgrc on POSIX.  This is returned
    as a Mercurial.config.config object.
    """
    hgrc = config()
    for cfg in userrcpath():
        if not os.path.exists(cfg):
            log("NOT reading missing cfg: " + cfg)
            continue
        log("Reading config: " + cfg)
        hgrc.read(cfg)
    return hgrc
示例#4
0
def classifycfgpath(path):
    """assign sort order to configuration file in path

    >>> classifycfgpath("/etc/mercurial/hgrc")
    1
    >>> classifycfgpath("repo/.hg/projrc")
    2
    >>> classifycfgpath(util.expandpath("~/.hgrc"))
    3
    >>> classifycfgpath("repo/.hg/hgrc")
    4
    """
    path = path.rsplit(":", 1)[0]
    if path in classifycfgpath.systemrcpath:
        return SYSTEMRC
    if util.pconvert(path).endswith(".hg/projrc"):
        return PROJRC
    if path in userrcpath():
        return USERRC
    # .hg/hgrc, file in $HGRCPATH, or an included file
    return HGRC
示例#5
0
def configwizard(ui, repo, statedir=None, **opts):
    """Ensure your Mercurial configuration is up to date."""
    runsteps = set(wizardsteps)

    # Mercurial <1.7 had a bug where monkeypatching ui.__class__
    # during uisetup() doesn't work. So we do our own ui.hasconfig()
    # here. Other uses of ui.hasconfig() are allowed, as they will
    # have a properly monkeypatched ui.__class__.
    if 'steps' in ui._data(False)._data.get('configwizard', {}):
        runsteps = set(ui.configlist('configwizard', 'steps'))

    hgversion = util.versiontuple(n=3)

    if hgversion < MINIMUM_SUPPORTED_VERSION:
        ui.warn(VERSION_TOO_OLD % (
            hgversion[0], hgversion[1],
            MINIMUM_SUPPORTED_VERSION[0], MINIMUM_SUPPORTED_VERSION[1],
        ))
        raise error.Abort('upgrade Mercurial then run again')

    uiprompt(ui, INITIAL_MESSAGE, default='<RETURN>')

    configpaths = [p for p in scmutil.userrcpath() if os.path.exists(p)]
    path = configpaths[0] if configpaths else scmutil.userrcpath()[0]
    cw = configobjwrapper(path)

    if 'hgversion' in runsteps:
        if _checkhgversion(ui, hgversion):
            return 1

    if 'username' in runsteps:
        _checkusername(ui, cw)

    if 'diff' in runsteps:
        _checkdiffsettings(ui, cw)

    if 'color' in runsteps:
        _promptnativeextension(ui, cw, 'color', 'Enable color output to your terminal')

    if 'pager' in runsteps:
        _checkpager(ui, cw)

    if 'curses' in runsteps:
        _checkcurses(ui, cw)

    if 'historyediting' in runsteps:
        _checkhistoryediting(ui, cw)

    if 'fsmonitor' in runsteps:
        _checkfsmonitor(ui, cw, hgversion)

    if 'blackbox' in runsteps:
        _promptnativeextension(ui, cw, 'blackbox',
                               'Enable logging of commands to help diagnose bugs '
                               'and performance problems')

    if 'security' in runsteps:
        _checksecurity(ui, cw, hgversion)

    if 'firefoxtree' in runsteps:
        _promptvctextension(ui, cw, 'firefoxtree', FIREFOXTREE_INFO)

    if 'wip' in runsteps:
        _checkwip(ui, cw)

    if 'codereview' in runsteps:
        _checkcodereview(ui, cw)

    if 'pushtotry' in runsteps:
        _promptvctextension(ui, cw, 'push-to-try', PUSHTOTRY_INFO)

    if 'multiplevct' in runsteps:
        _checkmultiplevct(ui, cw)

    if 'configchange' in runsteps:
        _handleconfigchange(ui, cw)

    if 'permissions' in runsteps:
        _checkpermissions(ui, cw)

    return 0
示例#6
0
def getconfigs(ui, repo):
    """
    Get a sequence of possible configuration files, including local
    (repository), user, and global.

    Each item in the returned sequence is a dictionary with the following keys:

    `scope`
        One of 'local', 'user', or 'global'.

    `path`
        The filesystem path to the config file.

    `exists`
        A `bool` indicating whether or not the file currently exists on the
        filesystem.

    `writeable`
        A `bool` indicating whether or not the file is writeable by the
        current user.

    """
    allconfigs = rcpath()
    # From 4.2 rcpath(rcutil.rccomponents) returns a tuple
    # Not checking here on isinstance, If return type changes, this will probably break instead of silently ignoring
    # this and treating the output as a string like before 4.2.
    if util.version() >= b'4.2':
        allconfigs = [c[1] for c in allconfigs if c[0] == b'path']
    local_config = localrc(repo)
    if local_config is not None:
        # rcpath() returns a reference to a global list, must not modify
        # it in place by "+=" but instead create a copy by "+".
        allconfigs = allconfigs + [local_config]
    userconfigs = set(userrcpath())

    configs = []
    paths = set()

    # for all global configs
    for f in allconfigs:
        if f in paths:
            continue
        paths.add(f)

        if f == local_config:
            scope = b'local'
        elif f in userconfigs:
            scope = b'user'
        else:
            scope = b'global'
        if not os.path.exists(f):
            exists = False
            writeable = False
        else:
            exists = True
            if os.access(f, os.W_OK):
                writeable = True
            else:
                writeable = False
        configs.append({b'scope': scope, b'path': f, b'exists': exists,
                        b'writeable': writeable})

    return configs