コード例 #1
0
                def mustconfirm(projrcexists):
                    """Read the projrc.confirm setting.

                    Valid values are:
                    - true: Always ask for confirmation
                    - first: Ask for confirmation when the projrc file
                             is transferred for the first time
                    - false: Do not ask for confirmation
                             (i.e. accept all projrc changes)

                    Note that you can use any valid 'boolean' value
                    instead of true and false (i.e. always, yes, on or 1
                    instead of true and never, no, off or 0 instead of false)
                    """
                    confirmchanges = ui.config(
                        'projrc', 'confirm', default=True)

                    if isinstance(confirmchanges, bool):
                        return confirmchanges
                    confirm = util.parsebool(confirmchanges)
                    if not confirm is None:
                        return confirm
                    confirmchanges = confirmchanges.lower()
                    if projrcexists and confirmchanges == "first":
                        return False
                    return True
コード例 #2
0
ファイル: pager.py プロジェクト: nermina86/docker
    def pagecmd(orig, ui, options, cmd, cmdfunc):
        p = ui.config("pager", "pager", os.environ.get("PAGER"))
        usepager = False
        always = util.parsebool(options['pager'])
        auto = options['pager'] == 'auto'

        if not p:
            pass
        elif always:
            usepager = True
        elif not auto:
            usepager = False
        else:
            attend = ui.configlist('pager', 'attend', attended)
            ignore = ui.configlist('pager', 'ignore')
            cmds, _ = cmdutil.findcmd(cmd, commands.table)

            for cmd in cmds:
                var = 'attend-%s' % cmd
                if ui.config('pager', var):
                    usepager = ui.configbool('pager', var)
                    break
                if (cmd in attend or (cmd not in ignore and not attend)):
                    usepager = True
                    break

        setattr(ui, 'pageractive', usepager)

        if usepager:
            ui.setconfig('ui', 'formatted', ui.formatted(), 'pager')
            ui.setconfig('ui', 'interactive', False, 'pager')
            if util.safehasattr(signal, "SIGPIPE"):
                signal.signal(signal.SIGPIPE, signal.SIG_DFL)
            _runpager(ui, p)
        return orig(ui, options, cmd, cmdfunc)
コード例 #3
0
ファイル: chgserver.py プロジェクト: motlin/cyg
def _setuppagercmd(ui, options, cmd):
    if not ui.formatted():
        return

    p = ui.config("pager", "pager", os.environ.get("PAGER"))
    usepager = False
    always = util.parsebool(options['pager'])
    auto = options['pager'] == 'auto'

    if not p:
        pass
    elif always:
        usepager = True
    elif not auto:
        usepager = False
    else:
        attended = ['annotate', 'cat', 'diff', 'export', 'glog', 'log', 'qdiff']
        attend = ui.configlist('pager', 'attend', attended)
        ignore = ui.configlist('pager', 'ignore')
        cmds, _ = cmdutil.findcmd(cmd, commands.table)

        for cmd in cmds:
            var = 'attend-%s' % cmd
            if ui.config('pager', var):
                usepager = ui.configbool('pager', var)
                break
            if (cmd in attend or
                (cmd not in ignore and not attend)):
                usepager = True
                break

    if usepager:
        ui.setconfig('ui', 'formatted', ui.formatted(), 'pager')
        ui.setconfig('ui', 'interactive', False, 'pager')
        return p
コード例 #4
0
ファイル: pager.py プロジェクト: ZanderZhang/Andriod-Learning
    def pagecmd(orig, ui, options, cmd, cmdfunc):
        p = ui.config("pager", "pager", os.environ.get("PAGER"))
        usepager = False
        always = util.parsebool(options['pager'])
        auto = options['pager'] == 'auto'

        if not p:
            pass
        elif always:
            usepager = True
        elif not auto:
            usepager = False
        else:
            attend = ui.configlist('pager', 'attend', attended)
            ignore = ui.configlist('pager', 'ignore')
            cmds, _ = cmdutil.findcmd(cmd, commands.table)

            for cmd in cmds:
                var = 'attend-%s' % cmd
                if ui.config('pager', var):
                    usepager = ui.configbool('pager', var)
                    break
                if (cmd in attend or
                     (cmd not in ignore and not attend)):
                    usepager = True
                    break

        if usepager:
            ui.setconfig('ui', 'formatted', ui.formatted(), 'pager')
            ui.setconfig('ui', 'interactive', False, 'pager')
            if util.safehasattr(signal, "SIGPIPE"):
                signal.signal(signal.SIGPIPE, signal.SIG_DFL)
            _runpager(ui, p)
        return orig(ui, options, cmd, cmdfunc)
コード例 #5
0
ファイル: chgserver.py プロジェクト: anydeploy/hg
def _setuppagercmd(ui, options, cmd):
    if not ui.formatted():
        return

    p = ui.config("pager", "pager", os.environ.get("PAGER"))
    usepager = False
    always = util.parsebool(options['pager'])
    auto = options['pager'] == 'auto'

    if not p:
        pass
    elif always:
        usepager = True
    elif not auto:
        usepager = False
    else:
        attended = ['annotate', 'cat', 'diff', 'export', 'glog', 'log', 'qdiff']
        attend = ui.configlist('pager', 'attend', attended)
        ignore = ui.configlist('pager', 'ignore')
        cmds, _ = cmdutil.findcmd(cmd, commands.table)

        for cmd in cmds:
            var = 'attend-%s' % cmd
            if ui.config('pager', var):
                usepager = ui.configbool('pager', var)
                break
            if (cmd in attend or
                (cmd not in ignore and not attend)):
                usepager = True
                break

    if usepager:
        ui.setconfig('ui', 'formatted', ui.formatted(), 'pager')
        ui.setconfig('ui', 'interactive', False, 'pager')
        return p
コード例 #6
0
ファイル: color.py プロジェクト: ThissDJ/designhub
 def colorcmd(orig, ui_, opts, cmd, cmdfunc):
     coloropt = opts['color']
     auto = coloropt == 'auto'
     always = util.parsebool(coloropt)
     if (always or
         (always is None and
          (auto and (os.environ.get('TERM') != 'dumb' and ui_.formatted())))):
         colorui._colormode = mode
         colorui.__bases__ = (ui_.__class__,)
         ui_.__class__ = colorui
         extstyles()
         configstyles(ui_)
     return orig(ui_, opts, cmd, cmdfunc)
コード例 #7
0
ファイル: pager.py プロジェクト: vvergu/mercurial
 def pagecmd(orig, ui, options, cmd, cmdfunc):
     p = ui.config("pager", "pager", os.environ.get("PAGER"))
     if p and sys.stdout.isatty() and "--debugger" not in sys.argv:
         attend = ui.configlist("pager", "attend", attended)
         auto = options["pager"] == "auto"
         always = util.parsebool(options["pager"])
         if always or auto and (cmd in attend or (cmd not in ui.configlist("pager", "ignore") and not attend)):
             ui.setconfig("ui", "formatted", ui.formatted())
             ui.setconfig("ui", "interactive", False)
             _runpager(p)
             if ui.configbool("pager", "quiet"):
                 signal.signal(signal.SIGPIPE, signal.SIG_DFL)
     return orig(ui, options, cmd, cmdfunc)
コード例 #8
0
 def colorcmd(orig, ui_, opts, cmd, cmdfunc):
     coloropt = opts['color']
     auto = coloropt == 'auto'
     always = util.parsebool(coloropt)
     if (always
             or (always is None and
                 (auto and
                  (os.environ.get('TERM') != 'dumb' and ui_.formatted())))):
         colorui._colormode = mode
         colorui.__bases__ = (ui_.__class__, )
         ui_.__class__ = colorui
         extstyles()
         configstyles(ui_)
     return orig(ui_, opts, cmd, cmdfunc)
コード例 #9
0
ファイル: pager.py プロジェクト: erikvanzijst/svnimporter
 def pagecmd(orig, ui, options, cmd, cmdfunc):
     p = ui.config("pager", "pager", os.environ.get("PAGER"))
     if p and sys.stdout.isatty() and '--debugger' not in sys.argv:
         attend = ui.configlist('pager', 'attend', attended)
         auto = options['pager'] == 'auto'
         always = util.parsebool(options['pager'])
         if (always or auto and
             (cmd in attend or (cmd not in ui.configlist('pager', 'ignore')
                                and not attend))):
             ui.setconfig('ui', 'formatted', ui.formatted())
             ui.setconfig('ui', 'interactive', False)
             _runpager(p)
             if ui.configbool('pager', 'quiet'):
                 signal.signal(signal.SIGPIPE, signal.SIG_DFL)
     return orig(ui, options, cmd, cmdfunc)
コード例 #10
0
ファイル: pager.py プロジェクト: ThissDJ/designhub
 def pagecmd(orig, ui, options, cmd, cmdfunc):
     p = ui.config("pager", "pager", os.environ.get("PAGER"))
     if p and sys.stdout.isatty() and '--debugger' not in sys.argv:
         attend = ui.configlist('pager', 'attend', attended)
         auto = options['pager'] == 'auto'
         always = util.parsebool(options['pager'])
         if (always or auto and
             (cmd in attend or
              (cmd not in ui.configlist('pager', 'ignore') and not attend))):
             ui.setconfig('ui', 'formatted', ui.formatted())
             ui.setconfig('ui', 'interactive', False)
             _runpager(p)
             if ui.configbool('pager', 'quiet'):
                 signal.signal(signal.SIGPIPE, signal.SIG_DFL)
     return orig(ui, options, cmd, cmdfunc)
コード例 #11
0
ファイル: util.py プロジェクト: davidshepherd7/dotfiles
def runworker(ui, fn, wargs, items):
    # 0.4 is the cost per argument. So if we have at least 100 files
    # on a 4 core machine than our linear cost outweights the
    # drawback of spwaning. We are overwritign this if we force a
    # worker to run with a ridiculous high number.
    weight = 0.0  # disable worker
    useworker = ui.config('p4fastimport', 'useworker')
    if useworker == 'force':
        weight = 100000.0  # force worker
    elif util.parsebool(useworker or ''):
        weight = 0.04  # normal weight

    # Fix duplicated messages before
    # https://www.mercurial-scm.org/repo/hg-committed/rev/9d3d56aa1a9f
    ui.flush()
    return worker.worker(ui, weight, fn, wargs, items)
コード例 #12
0
    def pagecmd(orig, ui, options, cmd, cmdfunc):
        p = ui.config("pager", "pager", os.environ.get("PAGER"))

        if p:
            attend = ui.configlist('pager', 'attend', attended)
            auto = options['pager'] == 'auto'
            always = util.parsebool(options['pager'])
            if (always or auto and
                (cmd in attend or (cmd not in ui.configlist('pager', 'ignore')
                                   and not attend))):
                ui.setconfig('ui', 'formatted', ui.formatted())
                ui.setconfig('ui', 'interactive', False)
                if util.safehasattr(signal, "SIGPIPE"):
                    signal.signal(signal.SIGPIPE, signal.SIG_DFL)
                _runpager(p)
        return orig(ui, options, cmd, cmdfunc)
コード例 #13
0
ファイル: pager.py プロジェクト: Pelonza/Learn2Mine-Main
    def pagecmd(orig, ui, options, cmd, cmdfunc):
        p = ui.config("pager", "pager", os.environ.get("PAGER"))

        if p:
            attend = ui.configlist('pager', 'attend', attended)
            auto = options['pager'] == 'auto'
            always = util.parsebool(options['pager'])
            if (always or auto and
                (cmd in attend or
                 (cmd not in ui.configlist('pager', 'ignore') and not attend))):
                ui.setconfig('ui', 'formatted', ui.formatted())
                ui.setconfig('ui', 'interactive', False)
                if util.safehasattr(signal, "SIGPIPE"):
                    signal.signal(signal.SIGPIPE, signal.SIG_DFL)
                _runpager(p)
        return orig(ui, options, cmd, cmdfunc)
コード例 #14
0
def _modesetup(ui, coloropt):
    global _terminfo_params

    if coloropt == 'debug':
        return 'debug'

    auto = (coloropt == 'auto')
    always = not auto and util.parsebool(coloropt)
    if not always and not auto:
        return None

    formatted = always or (os.environ.get('TERM') != 'dumb' and ui.formatted())

    mode = ui.config('color', 'mode', 'auto')
    realmode = mode
    if mode == 'auto':
        if os.name == 'nt' and 'TERM' not in os.environ:
            # looks line a cmd.exe console, use win32 API or nothing
            realmode = 'win32'
        else:
            realmode = 'ansi'

    if realmode == 'win32':
        _terminfo_params = {}
        if not w32effects:
            if mode == 'win32':
                # only warn if color.mode is explicitly set to win32
                ui.warn(_('warning: failed to set color mode to %s\n') % mode)
            return None
        _effects.update(w32effects)
    elif realmode == 'ansi':
        _terminfo_params = {}
    elif realmode == 'terminfo':
        _terminfosetup(ui, mode)
        if not _terminfo_params:
            if mode == 'terminfo':
                ## FIXME Shouldn't we return None in this case too?
                # only warn if color.mode is explicitly set to win32
                ui.warn(_('warning: failed to set color mode to %s\n') % mode)
            realmode = 'ansi'
    else:
        return None

    if always or (auto and formatted):
        return realmode
    return None
コード例 #15
0
ファイル: color.py プロジェクト: ZanderZhang/Andriod-Learning
def _modesetup(ui, coloropt):
    global _terminfo_params

    if coloropt == 'debug':
        return 'debug'

    auto = (coloropt == 'auto')
    always = not auto and util.parsebool(coloropt)
    if not always and not auto:
        return None

    formatted = always or (os.environ.get('TERM') != 'dumb' and ui.formatted())

    mode = ui.config('color', 'mode', 'auto')
    realmode = mode
    if mode == 'auto':
        if os.name == 'nt' and 'TERM' not in os.environ:
            # looks line a cmd.exe console, use win32 API or nothing
            realmode = 'win32'
        else:
            realmode = 'ansi'

    if realmode == 'win32':
        _terminfo_params = {}
        if not w32effects:
            if mode == 'win32':
                # only warn if color.mode is explicitly set to win32
                ui.warn(_('warning: failed to set color mode to %s\n') % mode)
            return None
        _effects.update(w32effects)
    elif realmode == 'ansi':
        _terminfo_params = {}
    elif realmode == 'terminfo':
        _terminfosetup(ui, mode)
        if not _terminfo_params:
            if mode == 'terminfo':
                ## FIXME Shouldn't we return None in this case too?
                # only warn if color.mode is explicitly set to win32
                ui.warn(_('warning: failed to set color mode to %s\n') % mode)
            realmode = 'ansi'
    else:
        return None

    if always or (auto and formatted):
        return realmode
    return None
コード例 #16
0
ファイル: color.py プロジェクト: guitao/hg-stable
def _modesetup(ui, coloropt):
    global _terminfo_params

    auto = coloropt == "auto"
    always = not auto and util.parsebool(coloropt)
    if not always and not auto:
        return None

    formatted = always or (os.environ.get("TERM") != "dumb" and ui.formatted())

    mode = ui.config("color", "mode", "auto")
    realmode = mode
    if mode == "auto":
        if os.name == "nt" and "TERM" not in os.environ:
            # looks line a cmd.exe console, use win32 API or nothing
            realmode = "win32"
        else:
            realmode = "ansi"

    if realmode == "win32":
        _terminfo_params = {}
        if not w32effects:
            if mode == "win32":
                # only warn if color.mode is explicitly set to win32
                ui.warn(_("warning: failed to set color mode to %s\n") % mode)
            return None
        _effects.update(w32effects)
    elif realmode == "ansi":
        _terminfo_params = {}
    elif realmode == "terminfo":
        _terminfosetup(ui, mode)
        if not _terminfo_params:
            if mode == "terminfo":
                ## FIXME Shouldn't we return None in this case too?
                # only warn if color.mode is explicitly set to win32
                ui.warn(_("warning: failed to set color mode to %s\n") % mode)
            realmode = "ansi"
    else:
        return None

    if always or (auto and formatted):
        return realmode
    return None
コード例 #17
0
 def mustupdateonincoming():
     default = 'false'
     updateonincoming = ui.config('projrc', 'updateonincoming',
         default=default)
     if (updateonincoming == ''):
         # prompt for confirmation when the field is set but empty
         # The reason is that it is reasonable for a user to expect
         # to be ableto update the projrc file when it sets
         # a field called 'updateonincoming'
         return 'prompt'
     if util.parsebool(updateonincoming) == False:
         # we don't want to get here when None!
         return 'false'
     updateonincoming = updateonincoming.lower()
     if not updateonincoming in ('auto', 'prompt'):
          ui.warn(_('invalid projrc.updateonincoming value (%s).\n'
             'using default projrc.updateonincoming value instead '
             '(%s)\n' % (updateonincoming, default)))
          return default
     return updateonincoming
コード例 #18
0
ファイル: qtlib.py プロジェクト: seewindcn/tortoisehg
    option.initFrom(widget)
    option.rect = style.subElementRect(style.SE_CheckBoxIndicator, option)
    option.rect.moveTo(1, 1)
    option.state |= state
    style.drawPrimitive(style.PE_IndicatorCheckBox, option, painter)
    return pix


# On machines with a retina display running OSX (i.e. "darwin"), most icons are
# too big because Qt4 does not support retina displays very well.
# To fix that we let users force tortoishg to use smaller icons by setting a
# THG_RETINA environment variable to True (or any value that mercurial parses
# as True.
IS_RETINA = False
if sys.platform == 'darwin':
    IS_RETINA = util.parsebool(os.environ.get('THG_RETINA', '0'))


def _fixIconSizeForRetinaDisplay(s):
    if IS_RETINA and s > 1:
        s /= 2
    return s

def smallIconSize():
    style = QApplication.style()
    s = style.pixelMetric(QStyle.PM_SmallIconSize)
    s = _fixIconSizeForRetinaDisplay(s)
    return QSize(s, s)

def toolBarIconSize():
    if sys.platform == 'darwin':
コード例 #19
0
    option.rect.moveTo(1, 1)
    option.state |= state
    style.drawPrimitive(style.PE_IndicatorCheckBox, option, painter)
    return pix


# On machines with a retina display running OSX (i.e. "darwin"), most icons are
# too big because Qt4 does not support retina displays very well.
# To fix that we let users force tortoishg to use smaller icons by setting a
# THG_RETINA environment variable to True (or any value that mercurial parses
# as True.
# Whereas on Linux, Qt4 has no support for high dpi displays at all causing
# icons to be rendered unusably small. The workaround for that is to render
# the icons at double the normal size.
# TODO: Remove this hack after upgrading to Qt5.
IS_RETINA = util.parsebool(os.environ.get('THG_RETINA', '0'))


def _fixIconSizeForRetinaDisplay(s):
    if IS_RETINA:
        if sys.platform == 'darwin':
            if s > 1:
                s /= 2
        elif sys.platform == 'linux2':
            s *= 2
    return s


def smallIconSize():
    style = QApplication.style()
    s = style.pixelMetric(QStyle.PM_SmallIconSize)
コード例 #20
0
def _modesetup(ui, coloropt):
    global _terminfo_params

    if coloropt == 'debug':
        return 'debug'

    auto = (coloropt == 'auto')
    always = not auto and util.parsebool(coloropt)
    if not always and not auto:
        return None

    formatted = always or (os.environ.get('TERM') != 'dumb' and ui.formatted())

    mode = ui.config('color', 'mode', 'auto')

    # If pager is active, color.pagermode overrides color.mode.
    if getattr(ui, 'pageractive', False):
        mode = ui.config('color', 'pagermode', mode)

    realmode = mode
    if mode == 'auto':
        if os.name == 'nt':
            term = os.environ.get('TERM')
            # TERM won't be defined in a vanilla cmd.exe environment.

            # UNIX-like environments on Windows such as Cygwin and MSYS will
            # set TERM. They appear to make a best effort attempt at setting it
            # to something appropriate. However, not all environments with TERM
            # defined support ANSI. Since "ansi" could result in terminal
            # gibberish, we error on the side of selecting "win32". However, if
            # w32effects is not defined, we almost certainly don't support
            # "win32", so don't even try.
            if (term and 'xterm' in term) or not w32effects:
                realmode = 'ansi'
            else:
                realmode = 'win32'
        else:
            realmode = 'ansi'

    def modewarn():
        # only warn if color.mode was explicitly set and we're in
        # an interactive terminal
        if mode == realmode and ui.interactive():
            ui.warn(_('warning: failed to set color mode to %s\n') % mode)

    if realmode == 'win32':
        _terminfo_params = {}
        if not w32effects:
            modewarn()
            return None
        _effects.update(w32effects)
    elif realmode == 'ansi':
        _terminfo_params = {}
    elif realmode == 'terminfo':
        _terminfosetup(ui, mode)
        if not _terminfo_params:
            ## FIXME Shouldn't we return None in this case too?
            modewarn()
            realmode = 'ansi'
    else:
        return None

    if always or (auto and formatted):
        return realmode
    return None
コード例 #21
0
def tortoisehgtools(uiorconfig, selectedlocation=None):
    """Parse 'tortoisehg-tools' section of ini file.

    >>> from pprint import pprint
    >>> from mercurial import config
    >>> class memui(uimod.ui):
    ...     def readconfig(self, filename, root=None, trust=False,
    ...                    sections=None, remap=None):
    ...         pass  # avoid reading settings from file-system

    Changes:

    >>> hgrctext = '''
    ... [tortoisehg-tools]
    ... update_to_tip.icon = hg-update
    ... update_to_tip.command = hg update tip
    ... update_to_tip.tooltip = Update to tip
    ... '''
    >>> uiobj = memui()
    >>> uiobj._tcfg.parse('<hgrc>', hgrctext)

    into the following dictionary

    >>> tools, toollist = tortoisehgtools(uiobj)
    >>> pprint(tools) #doctest: +NORMALIZE_WHITESPACE
    {'update_to_tip': {'command': 'hg update tip',
                       'icon': 'hg-update',
                       'tooltip': 'Update to tip'}}
    >>> toollist
    ['update_to_tip']

    If selectedlocation is set, only return those tools that have been
    configured to be shown at the given "location".
    Tools are added to "locations" by adding them to one of the
    "extension lists", which are lists of tool names, which follow the same
    format as the workbench.task-toolbar setting, i.e. a list of tool names,
    separated by spaces or "|" to indicate separators.

    >>> hgrctext_full = hgrctext + '''
    ... update_to_null.icon = hg-update
    ... update_to_null.command = hg update null
    ... update_to_null.tooltip = Update to null
    ... explore_wd.command = explorer.exe /e,{ROOT}
    ... explore_wd.enable = iswd
    ... explore_wd.label = Open in explorer
    ... explore_wd.showoutput = True
    ...
    ... [tortoisehg]
    ... workbench.custom-toolbar = update_to_tip | explore_wd
    ... workbench.revdetails.custom-menu = update_to_tip update_to_null
    ... '''
    >>> uiobj = memui()
    >>> uiobj._tcfg.parse('<hgrc>', hgrctext_full)

    >>> tools, toollist = tortoisehgtools(
    ...     uiobj, selectedlocation='workbench.custom-toolbar')
    >>> sorted(tools.keys())
    ['explore_wd', 'update_to_tip']
    >>> toollist
    ['update_to_tip', '|', 'explore_wd']

    >>> tools, toollist = tortoisehgtools(
    ...     uiobj, selectedlocation='workbench.revdetails.custom-menu')
    >>> sorted(tools.keys())
    ['update_to_null', 'update_to_tip']
    >>> toollist
    ['update_to_tip', 'update_to_null']

    Valid "locations lists" are:
        - workbench.custom-toolbar
        - workbench.revdetails.custom-menu

    >>> tortoisehgtools(uiobj, selectedlocation='invalid.location')
    Traceback (most recent call last):
      ...
    ValueError: invalid location 'invalid.location'

    This function can take a ui object or a config object as its input.

    >>> cfg = config.config()
    >>> cfg.parse('<hgrc>', hgrctext)
    >>> tools, toollist = tortoisehgtools(cfg)
    >>> pprint(tools) #doctest: +NORMALIZE_WHITESPACE
    {'update_to_tip': {'command': 'hg update tip',
                       'icon': 'hg-update',
                       'tooltip': 'Update to tip'}}
    >>> toollist
    ['update_to_tip']

    >>> cfg = config.config()
    >>> cfg.parse('<hgrc>', hgrctext_full)
    >>> tools, toollist = tortoisehgtools(
    ...     cfg, selectedlocation='workbench.custom-toolbar')
    >>> sorted(tools.keys())
    ['explore_wd', 'update_to_tip']
    >>> toollist
    ['update_to_tip', '|', 'explore_wd']

    No error for empty config:

    >>> emptycfg = config.config()
    >>> tortoisehgtools(emptycfg)
    ({}, [])
    >>> tortoisehgtools(emptycfg, selectedlocation='workbench.custom-toolbar')
    ({}, [])
    """
    if isinstance(uiorconfig, uimod.ui):
        configitems = uiorconfig.configitems
        configlist = uiorconfig.configlist
    else:
        configitems = uiorconfig.items

        def configlist(section, name):
            return uiorconfig.get(section, name, '').split()

    tools = {}
    for key, value in configitems('tortoisehg-tools'):
        toolname, field = key.split('.', 1)
        if toolname not in tools:
            tools[toolname] = {}
        bvalue = util.parsebool(value)
        if bvalue is not None:
            value = bvalue
        tools[toolname][field] = value

    if selectedlocation is None:
        return tools, sorted(tools.keys())

    # Only return the tools that are linked to the selected location
    if selectedlocation not in dict(tortoisehgtoollocations):
        raise ValueError('invalid location %r' % selectedlocation)

    guidef = configlist('tortoisehg', selectedlocation) or []
    toollist = []
    selectedtools = {}
    for name in guidef:
        if name != '|':
            info = tools.get(name, None)
            if info is None:
                continue
            selectedtools[name] = info
        toollist.append(name)
    return selectedtools, toollist
コード例 #22
0
ファイル: hglib.py プロジェクト: seewindcn/tortoisehg
def tortoisehgtools(uiorconfig, selectedlocation=None):
    """Parse 'tortoisehg-tools' section of ini file.

    >>> from pprint import pprint
    >>> from mercurial import config
    >>> class memui(ui.ui):
    ...     def readconfig(self, filename, root=None, trust=False,
    ...                    sections=None, remap=None):
    ...         pass  # avoid reading settings from file-system

    Changes:

    >>> hgrctext = '''
    ... [tortoisehg-tools]
    ... update_to_tip.icon = hg-update
    ... update_to_tip.command = hg update tip
    ... update_to_tip.tooltip = Update to tip
    ... '''
    >>> uiobj = memui()
    >>> uiobj._tcfg.parse('<hgrc>', hgrctext)

    into the following dictionary

    >>> tools, toollist = tortoisehgtools(uiobj)
    >>> pprint(tools) #doctest: +NORMALIZE_WHITESPACE
    {'update_to_tip': {'command': 'hg update tip',
                       'icon': 'hg-update',
                       'tooltip': 'Update to tip'}}
    >>> toollist
    ['update_to_tip']

    If selectedlocation is set, only return those tools that have been
    configured to be shown at the given "location".
    Tools are added to "locations" by adding them to one of the
    "extension lists", which are lists of tool names, which follow the same
    format as the workbench.task-toolbar setting, i.e. a list of tool names,
    separated by spaces or "|" to indicate separators.

    >>> hgrctext_full = hgrctext + '''
    ... update_to_null.icon = hg-update
    ... update_to_null.command = hg update null
    ... update_to_null.tooltip = Update to null
    ... explore_wd.command = explorer.exe /e,{ROOT}
    ... explore_wd.enable = iswd
    ... explore_wd.label = Open in explorer
    ... explore_wd.showoutput = True
    ...
    ... [tortoisehg]
    ... workbench.custom-toolbar = update_to_tip | explore_wd
    ... workbench.revdetails.custom-menu = update_to_tip update_to_null
    ... '''
    >>> uiobj = memui()
    >>> uiobj._tcfg.parse('<hgrc>', hgrctext_full)

    >>> tools, toollist = tortoisehgtools(
    ...     uiobj, selectedlocation='workbench.custom-toolbar')
    >>> sorted(tools.keys())
    ['explore_wd', 'update_to_tip']
    >>> toollist
    ['update_to_tip', '|', 'explore_wd']

    >>> tools, toollist = tortoisehgtools(
    ...     uiobj, selectedlocation='workbench.revdetails.custom-menu')
    >>> sorted(tools.keys())
    ['update_to_null', 'update_to_tip']
    >>> toollist
    ['update_to_tip', 'update_to_null']

    Valid "locations lists" are:
        - workbench.custom-toolbar
        - workbench.revdetails.custom-menu

    >>> tortoisehgtools(uiobj, selectedlocation='invalid.location')
    Traceback (most recent call last):
      ...
    ValueError: invalid location 'invalid.location'

    This function can take a ui object or a config object as its input.

    >>> cfg = config.config()
    >>> cfg.parse('<hgrc>', hgrctext)
    >>> tools, toollist = tortoisehgtools(cfg)
    >>> pprint(tools) #doctest: +NORMALIZE_WHITESPACE
    {'update_to_tip': {'command': 'hg update tip',
                       'icon': 'hg-update',
                       'tooltip': 'Update to tip'}}
    >>> toollist
    ['update_to_tip']

    >>> cfg = config.config()
    >>> cfg.parse('<hgrc>', hgrctext_full)
    >>> tools, toollist = tortoisehgtools(
    ...     cfg, selectedlocation='workbench.custom-toolbar')
    >>> sorted(tools.keys())
    ['explore_wd', 'update_to_tip']
    >>> toollist
    ['update_to_tip', '|', 'explore_wd']

    No error for empty config:

    >>> emptycfg = config.config()
    >>> tortoisehgtools(emptycfg)
    ({}, [])
    >>> tortoisehgtools(emptycfg, selectedlocation='workbench.custom-toolbar')
    ({}, [])
    """
    if isinstance(uiorconfig, ui.ui):
        configitems = uiorconfig.configitems
        configlist = uiorconfig.configlist
    else:
        configitems = uiorconfig.items
        def configlist(section, name):
            return uiorconfig.get(section, name, '').split()

    tools = {}
    for key, value in configitems('tortoisehg-tools'):
        toolname, field = key.split('.')
        if toolname not in tools:
            tools[toolname] = {}
        bvalue = util.parsebool(value)
        if bvalue is not None:
            value = bvalue
        tools[toolname][field] = value

    if selectedlocation is None:
        return tools, sorted(tools.keys())

    # Only return the tools that are linked to the selected location
    if selectedlocation not in dict(tortoisehgtoollocations):
        raise ValueError('invalid location %r' % selectedlocation)

    guidef = configlist('tortoisehg', selectedlocation) or []
    toollist = []
    selectedtools = {}
    for name in guidef:
        if name != '|':
            info = tools.get(name, None)
            if info is None:
                continue
            selectedtools[name] = info
        toollist.append(name)
    return selectedtools, toollist
コード例 #23
0
ファイル: color.py プロジェクト: cmjonze/mercurial
def _modesetup(ui, coloropt):
    global _terminfo_params

    if coloropt == 'debug':
        return 'debug'

    auto = (coloropt == 'auto')
    always = not auto and util.parsebool(coloropt)
    if not always and not auto:
        return None

    formatted = always or (os.environ.get('TERM') != 'dumb' and ui.formatted())

    mode = ui.config('color', 'mode', 'auto')

    # If pager is active, color.pagermode overrides color.mode.
    if getattr(ui, 'pageractive', False):
        mode = ui.config('color', 'pagermode', mode)

    realmode = mode
    if mode == 'auto':
        if os.name == 'nt':
            term = os.environ.get('TERM')
            # TERM won't be defined in a vanilla cmd.exe environment.

            # UNIX-like environments on Windows such as Cygwin and MSYS will
            # set TERM. They appear to make a best effort attempt at setting it
            # to something appropriate. However, not all environments with TERM
            # defined support ANSI. Since "ansi" could result in terminal
            # gibberish, we error on the side of selecting "win32". However, if
            # w32effects is not defined, we almost certainly don't support
            # "win32", so don't even try.
            if (term and 'xterm' in term) or not w32effects:
                realmode = 'ansi'
            else:
                realmode = 'win32'
        else:
            realmode = 'ansi'

    def modewarn():
        # only warn if color.mode was explicitly set and we're in
        # an interactive terminal
        if mode == realmode and ui.interactive():
            ui.warn(_('warning: failed to set color mode to %s\n') % mode)

    if realmode == 'win32':
        _terminfo_params = {}
        if not w32effects:
            modewarn()
            return None
        _effects.update(w32effects)
    elif realmode == 'ansi':
        _terminfo_params = {}
    elif realmode == 'terminfo':
        _terminfosetup(ui, mode)
        if not _terminfo_params:
            ## FIXME Shouldn't we return None in this case too?
            modewarn()
            realmode = 'ansi'
    else:
        return None

    if always or (auto and formatted):
        return realmode
    return None