コード例 #1
0
    def test_fires_on_get_cmd_object(self):
        # The get_command(cmd) hook fires when commands are delivered to the
        # ui.
        commands.install_bzr_command_hooks()
        hook_calls = []

        class ACommand(commands.Command):
            __doc__ = """A sample command."""

        def get_cmd(cmd_or_None, cmd_name):
            hook_calls.append(('called', cmd_or_None, cmd_name))
            if cmd_name in ('foo', 'info'):
                return ACommand()

        commands.Command.hooks.install_named_hook("get_command", get_cmd, None)
        # create a command directly, should not fire
        cmd = ACommand()
        self.assertEqual([], hook_calls)
        # ask by name, should fire and give us our command
        cmd = commands.get_cmd_object('foo')
        self.assertEqual([('called', None, 'foo')], hook_calls)
        self.assertIsInstance(cmd, ACommand)
        del hook_calls[:]
        # ask by a name that is supplied by a builtin - the hook should still
        # fire and we still get our object, but we should see the builtin
        # passed to the hook.
        cmd = commands.get_cmd_object('info')
        self.assertIsInstance(cmd, ACommand)
        self.assertEqual(1, len(hook_calls))
        self.assertEqual('info', hook_calls[0][2])
        self.assertIsInstance(hook_calls[0][1], builtins.cmd_info)
コード例 #2
0
    def __init__(self, localdir=u".", parent=None, ui_mode=False):
        super(QBzrInitWindow, self).__init__(
                                  gettext("Initialize"),
                                  name = "init",
                                  ui_mode = ui_mode,
                                  dialog = True,
                                  parent = parent,
                                  hide_progress=True)

        self.ui = Ui_InitForm()
        self.ui.setupUi(self)
        # and add the subprocess widgets.
        for w in self.make_default_layout_widgets():
            self.layout().addWidget(w)

        # One directory picker
        self.ui.location.setText(os.path.abspath(localdir))
        hookup_directory_picker(self,
                                self.ui.location_picker,
                                self.ui.location,
                                DIRECTORYPICKER_TARGET)

        # Combo box for repo format.
        cmd = get_cmd_object('init')
        opt = cmd.options()['format']
        fill_option_combo(self.ui.combo_format, opt, 'default',
                          self.ui.format_desc)

        self.ui.but_append_only.setToolTip(cmd.options()['append-revisions-only'].help)

        cmd = get_cmd_object('init-repo')
        opt = cmd.options()['no-trees']
        self.ui.but_no_trees.setToolTip(opt.help)
コード例 #3
0
ファイル: test_commands.py プロジェクト: GymWenFLL/tpp_libs
    def test_fires_on_get_cmd_object(self):
        # The get_command(cmd) hook fires when commands are delivered to the
        # ui.
        commands.install_bzr_command_hooks()
        hook_calls = []

        class ACommand(commands.Command):
            __doc__ = """A sample command."""

        def get_cmd(cmd_or_None, cmd_name):
            hook_calls.append(("called", cmd_or_None, cmd_name))
            if cmd_name in ("foo", "info"):
                return ACommand()

        commands.Command.hooks.install_named_hook("get_command", get_cmd, None)
        # create a command directly, should not fire
        cmd = ACommand()
        self.assertEqual([], hook_calls)
        # ask by name, should fire and give us our command
        cmd = commands.get_cmd_object("foo")
        self.assertEqual([("called", None, "foo")], hook_calls)
        self.assertIsInstance(cmd, ACommand)
        del hook_calls[:]
        # ask by a name that is supplied by a builtin - the hook should still
        # fire and we still get our object, but we should see the builtin
        # passed to the hook.
        cmd = commands.get_cmd_object("info")
        self.assertIsInstance(cmd, ACommand)
        self.assertEqual(1, len(hook_calls))
        self.assertEqual("info", hook_calls[0][2])
        self.assertIsInstance(hook_calls[0][1], builtins.cmd_info)
コード例 #4
0
 def get_option_completions(self):
     try:
         command_obj = get_cmd_object(self.command)
     except BzrError:
         return []
     opts = [o+" " for o in iter_opt_completions(command_obj)]
     return list(filter_completions(opts, self.text))
コード例 #5
0
    def default(self, line):
        args = shlex.split(line)
        alias_args = get_alias(args[0])
        if alias_args is not None:
            args[0] = alias_args.pop(0)

        commandname = args.pop(0)
        for char in ('|', '<', '>'):
            commandname = commandname.split(char)[0]
        if commandname[-1] in ('|', '<', '>'):
            commandname = commandname[:-1]
        try:
            if commandname in SHELL_BLACKLIST:
                raise BlackListedCommand(commandname)
            cmd_obj = get_cmd_object(commandname)
        except (BlackListedCommand, BzrError):
            return os.system(line)

        try:
            if too_complicated(line):
                return os.system("bzr "+line)
            else:
                return (cmd_obj.run_argv_aliases(args, alias_args) or 0)
        except BzrError, e:
            print e
コード例 #6
0
ファイル: help.py プロジェクト: saminigod/cygwin
def _help_commands_to_text(topic):
    """Generate the help text for the list of commands"""
    out = []
    if topic == 'hidden-commands':
        hidden = True
    else:
        hidden = False
    names = set(
        _mod_commands.builtin_command_names())  # to eliminate duplicates
    names.update(_mod_commands.plugin_command_names())
    commands = ((n, _mod_commands.get_cmd_object(n)) for n in names)
    shown_commands = [(n, o) for n, o in commands if o.hidden == hidden]
    max_name = max(len(n) for n, o in shown_commands)
    indent = ' ' * (max_name + 1)
    width = osutils.terminal_width() - 1

    for cmd_name, cmd_object in sorted(shown_commands):
        plugin_name = cmd_object.plugin_name()
        if plugin_name is None:
            plugin_name = ''
        else:
            plugin_name = ' [%s]' % plugin_name

        cmd_help = cmd_object.help()
        if cmd_help:
            firstline = cmd_help.split('\n', 1)[0]
        else:
            firstline = ''
        helpstring = '%-*s %s%s' % (max_name, cmd_name, firstline, plugin_name)
        lines = textwrap.wrap(helpstring,
                              subsequent_indent=indent,
                              width=width)
        for line in lines:
            out.append(line + '\n')
    return ''.join(out)
コード例 #7
0
ファイル: run.py プロジェクト: biji/qbzr
 def collect_command_names(self):
     """Collect names of available bzr commands."""
     from bzrlib import commands as _mod_commands
     names = list(_mod_commands.all_command_names())
     self.cmds_dict = dict(
         (n, _mod_commands.get_cmd_object(n)) for n in names)
     # Find the commands for each category, public or otherwise
     builtins = _mod_commands.builtin_command_names()
     self.all_cmds = {'All': []}
     self.public_cmds = {'All': []}
     for name, cmd in self.cmds_dict.iteritems():
         # If a command is builtin, we always put it into the Core
         # category, even if overridden in a plugin
         if name in builtins:
             category = 'Core'
         else:
             category = cmd.plugin_name()
         self.all_cmds['All'].append(name)
         self.all_cmds.setdefault(category, []).append(name)
         if not cmd.hidden:
             self.public_cmds['All'].append(name)
             self.public_cmds.setdefault(category, []).append(name)
     # Sort them
     for category in self.all_cmds:
         self.all_cmds[category].sort()
         try:
             self.public_cmds[category].sort()
         except KeyError:
             # no public commands - that's ok
             pass
コード例 #8
0
ファイル: complete.py プロジェクト: benoit-pierre/config-vim
    def complete_command(self):

        self.cmdname = self.args[0]

        alias_args = commands.get_alias(self.cmdname)
        if alias_args is not None:
            self.cmdname = alias_args.pop(0)

        try:
            self.cmdobj = commands.get_cmd_object(self.cmdname)
        except BzrCommandError:
            self.cmdobj = None

        if 0 < len(self.arglead):

            if '-' == self.arglead[0]:
                return self.complete_options()

            if '~' == self.arglead[0]:
                self.arglead = os.path.expanduser(self.arglead)

        olddir = os.getcwd()
        os.chdir(self.workdir)

        try:
            paths = glob.iglob(self.arglead + '*')
            paths = [ fix_path(path) for path in paths ]
        finally:
            os.chdir(olddir)

        return paths
コード例 #9
0
    def default(self, line):
        args = shlex.split(line)
        alias_args = get_alias(args[0])
        if alias_args is not None:
            args[0] = alias_args.pop(0)

        commandname = args.pop(0)
        for char in ('|', '<', '>'):
            commandname = commandname.split(char)[0]
        if commandname[-1] in ('|', '<', '>'):
            commandname = commandname[:-1]
        try:
            if commandname in SHELL_BLACKLIST:
                raise BlackListedCommand(commandname)
            cmd_obj = get_cmd_object(commandname)
        except (BlackListedCommand, BzrError):
            return os.system(line)

        try:
            if too_complicated(line):
                return os.system("bzr " + line)
            else:
                return (cmd_obj.run_argv_aliases(args, alias_args) or 0)
        except BzrError, e:
            print e
コード例 #10
0
 def get_option_completions(self):
     try:
         command_obj = get_cmd_object(self.command)
     except BzrError:
         return []
     opts = [o + " " for o in iter_opt_completions(command_obj)]
     return list(filter_completions(opts, self.text))
コード例 #11
0
ファイル: help.py プロジェクト: c0ns0le/cygwin
def _help_commands_to_text(topic):
    """Generate the help text for the list of commands"""
    out = []
    if topic == 'hidden-commands':
        hidden = True
    else:
        hidden = False
    names = set(_mod_commands.builtin_command_names()) # to eliminate duplicates
    names.update(_mod_commands.plugin_command_names())
    commands = ((n, _mod_commands.get_cmd_object(n)) for n in names)
    shown_commands = [(n, o) for n, o in commands if o.hidden == hidden]
    max_name = max(len(n) for n, o in shown_commands)
    indent = ' ' * (max_name + 1)
    width = osutils.terminal_width() - 1

    for cmd_name, cmd_object in sorted(shown_commands):
        plugin_name = cmd_object.plugin_name()
        if plugin_name is None:
            plugin_name = ''
        else:
            plugin_name = ' [%s]' % plugin_name

        cmd_help = cmd_object.help()
        if cmd_help:
            firstline = cmd_help.split('\n', 1)[0]
        else:
            firstline = ''
        helpstring = '%-*s %s%s' % (max_name, cmd_name, firstline, plugin_name)
        lines = textwrap.wrap(helpstring, subsequent_indent=indent,
                              width=width)
        for line in lines:
            out.append(line + '\n')
    return ''.join(out)
コード例 #12
0
 def test_invoked_as(self):
     """The command object knows the actual name used to invoke it."""
     commands.install_bzr_command_hooks()
     commands._register_builtin_commands()
     # get one from the real get_cmd_object.
     c = commands.get_cmd_object('ci')
     self.assertIsInstance(c, builtins.cmd_commit)
     self.assertEqual(c.invoked_as, 'ci')
コード例 #13
0
ファイル: test_commands.py プロジェクト: GymWenFLL/tpp_libs
 def test_invoked_as(self):
     """The command object knows the actual name used to invoke it."""
     commands.install_bzr_command_hooks()
     commands._register_builtin_commands()
     # get one from the real get_cmd_object.
     c = commands.get_cmd_object("ci")
     self.assertIsInstance(c, builtins.cmd_commit)
     self.assertEquals(c.invoked_as, "ci")
コード例 #14
0
ファイル: test_commands.py プロジェクト: GymWenFLL/tpp_libs
 def test_register_lazy(self):
     """Ensure lazy registration works"""
     commands.plugin_cmds.register_lazy("cmd_fake", [], "bzrlib.tests.fake_command")
     self.addCleanup(self.remove_fake)
     self.assertFalse(lazy_command_imported)
     fake_instance = commands.get_cmd_object("fake")
     self.assertTrue(lazy_command_imported)
     self.assertIsFakeCommand(fake_instance)
コード例 #15
0
ファイル: test_options.py プロジェクト: Distrotech/bzr
 def get_builtin_command_options(self):
     g = []
     commands.install_bzr_command_hooks()
     for cmd_name in sorted(commands.builtin_command_names()):
         cmd = commands.get_cmd_object(cmd_name)
         for opt_name, opt in sorted(cmd.options().items()):
             g.append((cmd_name, opt))
     self.assert_(g)
     return g
コード例 #16
0
 def test_fires_on_get_cmd_object(self):
     # The get_missing_command(cmd) hook fires when commands are delivered to the
     # ui.
     self.hook_missing()
     # create a command directly, should not fire
     self.cmd = self.ACommand()
     self.assertEqual([], self.hook_calls)
     # ask by name, should fire and give us our command
     cmd = commands.get_cmd_object('foo')
     self.assertEqual([('called', 'foo')], self.hook_calls)
     self.assertIsInstance(cmd, self.ACommand)
     del self.hook_calls[:]
     # ask by a name that is supplied by a builtin - the hook should not
     # fire and we still get our object.
     commands.install_bzr_command_hooks()
     cmd = commands.get_cmd_object('info')
     self.assertNotEqual(None, cmd)
     self.assertEqual(0, len(self.hook_calls))
コード例 #17
0
ファイル: test_commands.py プロジェクト: GymWenFLL/tpp_libs
 def test_fires_on_get_cmd_object(self):
     # The get_missing_command(cmd) hook fires when commands are delivered to the
     # ui.
     self.hook_missing()
     # create a command directly, should not fire
     self.cmd = self.ACommand()
     self.assertEqual([], self.hook_calls)
     # ask by name, should fire and give us our command
     cmd = commands.get_cmd_object("foo")
     self.assertEqual([("called", "foo")], self.hook_calls)
     self.assertIsInstance(cmd, self.ACommand)
     del self.hook_calls[:]
     # ask by a name that is supplied by a builtin - the hook should not
     # fire and we still get our object.
     commands.install_bzr_command_hooks()
     cmd = commands.get_cmd_object("info")
     self.assertNotEqual(None, cmd)
     self.assertEqual(0, len(self.hook_calls))
コード例 #18
0
def colordiff(check_style, *args, **kwargs):
    real_stdout = sys.stdout
    dw = DiffWriter(real_stdout, check_style)
    sys.stdout = dw
    try:
        get_cmd_object('diff').run(*args, **kwargs)
    finally:
        sys.stdout = real_stdout
    if check_style:
        if dw.added_trailing_whitespace > 0:
            trace.warning('%d new line(s) have trailing whitespace.' %
                          dw.added_trailing_whitespace)
        if dw.long_lines > 0:
            trace.warning('%d new line(s) exceed(s) %d columns.' %
                          (dw.long_lines, dw.max_line_len))
        if dw.spurious_whitespace > 0:
            trace.warning('%d line(s) have spurious whitespace changes' %
                          dw.spurious_whitespace)
コード例 #19
0
 def get_builtin_command_options(self):
     g = []
     commands.install_bzr_command_hooks()
     for cmd_name in sorted(commands.builtin_command_names()):
         cmd = commands.get_cmd_object(cmd_name)
         for opt_name, opt in sorted(cmd.options().items()):
             g.append((cmd_name, opt))
     self.assertTrue(g)
     return g
コード例 #20
0
 def test_register_lazy(self):
     """Ensure lazy registration works"""
     commands.plugin_cmds.register_lazy('cmd_fake', [],
                                        'bzrlib.tests.fake_command')
     self.addCleanup(self.remove_fake)
     self.assertFalse(lazy_command_imported)
     fake_instance = commands.get_cmd_object('fake')
     self.assertTrue(lazy_command_imported)
     self.assertIsFakeCommand(fake_instance)
コード例 #21
0
    def __init__(self,
                 from_location,
                 to_location=None,
                 revision=None,
                 bind=False,
                 parent_dir=None,
                 ui_mode=True,
                 parent=None):
        super(QBzrBranchWindow, self).__init__(name=self.NAME,
                                               ui_mode=ui_mode,
                                               parent=parent)

        # Unless instructed otherwise, use the current directory as
        # the parent directory.
        if parent_dir is None:
            parent_dir = os.getcwdu()
        self.parent_dir = parent_dir

        # Layout the form, adding the subprocess widgets
        self.ui = Ui_BranchForm()
        self.setupUi(self.ui)
        self.cmd_branch_options = get_cmd_object('branch').options()
        if 'bind' not in self.cmd_branch_options:
            self.ui.bind.setVisible(False)
        for w in self.make_default_layout_widgets():
            self.layout().addWidget(w)

        # Setup smart setting of fields as others are edited.
        QtCore.QObject.connect(
            self.ui.from_location,
            QtCore.SIGNAL("editTextChanged(const QString&)"),
            self.from_changed)

        # Initialise the fields
        fill_combo_with(self.ui.from_location, u'',
                        iter_saved_pull_locations())
        if from_location:
            self.ui.from_location.setEditText(from_location)
        if to_location:
            self.ui.to_location.setEditText(to_location)
        if bind:
            self.ui.bind.setChecked(True)
        if revision:
            self.ui.revision.setText(revision)

        # Hook up our directory pickers
        hookup_directory_picker(self, self.ui.from_picker,
                                self.ui.from_location, DIRECTORYPICKER_SOURCE)
        hookup_directory_picker(self, self.ui.to_picker, self.ui.to_location,
                                DIRECTORYPICKER_TARGET)

        # Put the focus on the To location if From is already set
        if from_location:
            self.ui.to_location.setFocus()
        else:
            self.ui.from_location.setFocus()
コード例 #22
0
ファイル: test_commands.py プロジェクト: GymWenFLL/tpp_libs
 def test_all_commands_have_help(self):
     commands._register_builtin_commands()
     commands_without_help = set()
     base_doc = inspect.getdoc(commands.Command)
     for cmd_name in commands.all_command_names():
         cmd = commands.get_cmd_object(cmd_name)
         cmd_help = cmd.help()
         if not cmd_help or cmd_help == base_doc:
             commands_without_help.append(cmd_name)
     self.assertLength(0, commands_without_help)
コード例 #23
0
 def test_all_commands_have_help(self):
     commands._register_builtin_commands()
     commands_without_help = set()
     base_doc = inspect.getdoc(commands.Command)
     for cmd_name in commands.all_command_names():
         cmd = commands.get_cmd_object(cmd_name)
         cmd_help = cmd.help()
         if not cmd_help or cmd_help == base_doc:
             commands_without_help.append(cmd_name)
     self.assertLength(0, commands_without_help)
コード例 #24
0
    def test_fires_on_get_cmd_object(self):
        # The extend_command(cmd) hook fires when commands are delivered to the
        # ui, not simply at registration (because lazy registered plugin
        # commands are registered).
        # when they are simply created.
        hook_calls = []
        commands.install_bzr_command_hooks()
        commands.Command.hooks.install_named_hook("extend_command",
                                                  hook_calls.append, None)

        # create a command, should not fire
        class cmd_test_extend_command_hook(commands.Command):
            __doc__ = """A sample command."""

        self.assertEqual([], hook_calls)
        # -- as a builtin
        # register the command class, should not fire
        try:
            commands.builtin_command_registry.register(
                cmd_test_extend_command_hook)
            self.assertEqual([], hook_calls)
            # and ask for the object, should fire
            cmd = commands.get_cmd_object('test-extend-command-hook')
            # For resilience - to ensure all code paths hit it - we
            # fire on everything returned in the 'cmd_dict', which is currently
            # all known commands, so assert that cmd is in hook_calls
            self.assertSubset([cmd], hook_calls)
            del hook_calls[:]
        finally:
            commands.builtin_command_registry.remove(
                'test-extend-command-hook')
        # -- as a plugin lazy registration
        try:
            # register the command class, should not fire
            commands.plugin_cmds.register_lazy('cmd_fake', [],
                                               'bzrlib.tests.fake_command')
            self.assertEqual([], hook_calls)
            # and ask for the object, should fire
            cmd = commands.get_cmd_object('fake')
            self.assertEqual([cmd], hook_calls)
        finally:
            commands.plugin_cmds.remove('fake')
コード例 #25
0
def _command_helps(exporter, plugin_name=None):
    """Extract docstrings from path.

    This respects the Bazaar cmdtable/table convention and will
    only extract docstrings from functions mentioned in these tables.
    """
    from glob import glob

    # builtin commands
    for cmd_name in _mod_commands.builtin_command_names():
        command = _mod_commands.get_cmd_object(cmd_name, False)
        if command.hidden:
            continue
        if plugin_name is not None:
            # only export builtins if we are not exporting plugin commands
            continue
        note(gettext("Exporting messages from builtin command: %s"), cmd_name)
        _write_command_help(exporter, command)

    plugin_path = plugin.get_core_plugin_path()
    core_plugins = glob(plugin_path + '/*/__init__.py')
    core_plugins = [os.path.basename(os.path.dirname(p)) for p in core_plugins]
    # plugins
    for cmd_name in _mod_commands.plugin_command_names():
        command = _mod_commands.get_cmd_object(cmd_name, False)
        if command.hidden:
            continue
        if plugin_name is not None and command.plugin_name() != plugin_name:
            # if we are exporting plugin commands, skip plugins we have not specified.
            continue
        if plugin_name is None and command.plugin_name() not in core_plugins:
            # skip non-core plugins
            # TODO: Support extracting from third party plugins.
            continue
        note(
            gettext(
                "Exporting messages from plugin command: {0} in {1}").format(
                    cmd_name, command.plugin_name()))
        _write_command_help(exporter, command)
コード例 #26
0
def _command_helps(exporter, plugin_name=None):
    """Extract docstrings from path.

    This respects the Bazaar cmdtable/table convention and will
    only extract docstrings from functions mentioned in these tables.
    """
    from glob import glob

    # builtin commands
    for cmd_name in _mod_commands.builtin_command_names():
        command = _mod_commands.get_cmd_object(cmd_name, False)
        if command.hidden:
            continue
        if plugin_name is not None:
            # only export builtins if we are not exporting plugin commands
            continue
        note(gettext("Exporting messages from builtin command: %s"), cmd_name)
        _write_command_help(exporter, command)

    plugin_path = plugin.get_core_plugin_path()
    core_plugins = glob(plugin_path + '/*/__init__.py')
    core_plugins = [os.path.basename(os.path.dirname(p))
                        for p in core_plugins]
    # plugins
    for cmd_name in _mod_commands.plugin_command_names():
        command = _mod_commands.get_cmd_object(cmd_name, False)
        if command.hidden:
            continue
        if plugin_name is not None and command.plugin_name() != plugin_name:
            # if we are exporting plugin commands, skip plugins we have not specified.
            continue
        if plugin_name is None and command.plugin_name() not in core_plugins:
            # skip non-core plugins
            # TODO: Support extracting from third party plugins.
            continue
        note(gettext("Exporting messages from plugin command: {0} in {1}").format(
             cmd_name, command.plugin_name() ))
        _write_command_help(exporter, command)
コード例 #27
0
ファイル: commands.py プロジェクト: biji/qbzr
def bzr_option(cmd_name, opt_name):
    """Helper so we can 'borrow' options from bzr itself without needing to
    duplicate the help text etc.  Pass the builtin bzr command name and an
    option name.

    eg:
      takes_options = [bzr_option("push", "create-prefix")]

    would give a command the exact same '--create-prefix' option as bzr's
    push command has, including help text, parsing, etc.
    """
    from bzrlib.commands import get_cmd_object
    cmd = get_cmd_object(cmd_name, False)
    return cmd.options()[opt_name]
コード例 #28
0
ファイル: test_commands.py プロジェクト: GymWenFLL/tpp_libs
    def test_fires_on_get_cmd_object(self):
        # The extend_command(cmd) hook fires when commands are delivered to the
        # ui, not simply at registration (because lazy registered plugin
        # commands are registered).
        # when they are simply created.
        hook_calls = []
        commands.install_bzr_command_hooks()
        commands.Command.hooks.install_named_hook("extend_command", hook_calls.append, None)
        # create a command, should not fire
        class cmd_test_extend_command_hook(commands.Command):
            __doc__ = """A sample command."""

        self.assertEqual([], hook_calls)
        # -- as a builtin
        # register the command class, should not fire
        try:
            commands.builtin_command_registry.register(cmd_test_extend_command_hook)
            self.assertEqual([], hook_calls)
            # and ask for the object, should fire
            cmd = commands.get_cmd_object("test-extend-command-hook")
            # For resilience - to ensure all code paths hit it - we
            # fire on everything returned in the 'cmd_dict', which is currently
            # all known commands, so assert that cmd is in hook_calls
            self.assertSubset([cmd], hook_calls)
            del hook_calls[:]
        finally:
            commands.builtin_command_registry.remove("test-extend-command-hook")
        # -- as a plugin lazy registration
        try:
            # register the command class, should not fire
            commands.plugin_cmds.register_lazy("cmd_fake", [], "bzrlib.tests.fake_command")
            self.assertEqual([], hook_calls)
            # and ask for the object, should fire
            cmd = commands.get_cmd_object("fake")
            self.assertEqual([cmd], hook_calls)
        finally:
            commands.plugin_cmds.remove("fake")
コード例 #29
0
ファイル: test_commands.py プロジェクト: GymWenFLL/tpp_libs
    def test_fires_on_all_command_names(self):
        # The list_commands() hook fires when all_command_names() is invoked.
        hook_calls = []
        commands.install_bzr_command_hooks()

        def list_my_commands(cmd_names):
            hook_calls.append("called")
            cmd_names.update(["foo", "bar"])
            return cmd_names

        commands.Command.hooks.install_named_hook("list_commands", list_my_commands, None)
        # Get a command, which should not trigger the hook.
        cmd = commands.get_cmd_object("info")
        self.assertEqual([], hook_calls)
        # Get all command classes (for docs and shell completion).
        cmds = list(commands.all_command_names())
        self.assertEqual(["called"], hook_calls)
        self.assertSubset(["foo", "bar"], cmds)
コード例 #30
0
ファイル: complete.py プロジェクト: benoit-pierre/config-vim
    def complete_cmdname(self):

        cmds = []

        for cmdname in commands.all_command_names():
            cmdclass = commands.get_cmd_object(cmdname)
            if not complete_hidden_commands and cmdclass.hidden:
                continue
            cmds.append(cmdname)
            if complete_command_aliases:
                for alias in cmdclass.aliases:
                    if cmdname.startswith(alias):
                        continue
                    cmds.append(alias)

        for alias in config.GlobalConfig().get_aliases().keys():
            cmds.append(alias)

        return add_extra_space(self.filter(cmds))
コード例 #31
0
    def test_fires_on_all_command_names(self):
        # The list_commands() hook fires when all_command_names() is invoked.
        hook_calls = []
        commands.install_bzr_command_hooks()

        def list_my_commands(cmd_names):
            hook_calls.append('called')
            cmd_names.update(['foo', 'bar'])
            return cmd_names

        commands.Command.hooks.install_named_hook("list_commands",
                                                  list_my_commands, None)
        # Get a command, which should not trigger the hook.
        cmd = commands.get_cmd_object('info')
        self.assertEqual([], hook_calls)
        # Get all command classes (for docs and shell completion).
        cmds = list(commands.all_command_names())
        self.assertEqual(['called'], hook_calls)
        self.assertSubset(['foo', 'bar'], cmds)
コード例 #32
0
ファイル: bashcomp.py プロジェクト: pombreda/dist-packages
    def command(self, name):
        cmd = commands.get_cmd_object(name)
        cmd_data = CommandData(name)

        plugin_name = cmd.plugin_name()
        if plugin_name is not None:
            if (self.selected_plugins is not None
                    and plugin not in self.selected_plugins):
                return None
            plugin_data = self.data.plugins.get(plugin_name)
            if plugin_data is None:
                plugin_data = PluginData(plugin_name)
                self.data.plugins[plugin_name] = plugin_data
            cmd_data.plugin = plugin_data
        self.data.commands.append(cmd_data)

        # Find all aliases to the command; both cmd-defined and user-defined.
        # We assume a user won't override one command with a different one,
        # but will choose completely new names or add options to existing
        # ones while maintaining the actual command name unchanged.
        cmd_data.aliases.extend(cmd.aliases)
        cmd_data.aliases.extend(
            sorted([
                useralias for cmdalias in cmd_data.aliases
                if cmdalias in self.user_aliases
                for useralias in self.user_aliases[cmdalias]
                if useralias not in cmd_data.aliases
            ]))

        opts = cmd.options()
        for optname, opt in sorted(opts.iteritems()):
            cmd_data.options.extend(self.option(opt))

        if 'help' == name or 'help' in cmd.aliases:
            cmd_data.fixed_words = (
                '($cmds %s)' %
                " ".join(sorted(help_topics.topic_registry.keys())))

        return cmd_data
コード例 #33
0
ファイル: help.py プロジェクト: pombreda/dist-packages
def _help_commands_to_text(topic):
    """Generate the help text for the list of commands"""
    out = []
    if topic == 'hidden-commands':
        hidden = True
    else:
        hidden = False
    names = list(_mod_commands.all_command_names())
    commands = ((n, _mod_commands.get_cmd_object(n)) for n in names)
    shown_commands = [(n, o) for n, o in commands if o.hidden == hidden]
    max_name = max(len(n) for n, o in shown_commands)
    indent = ' ' * (max_name + 1)
    width = osutils.terminal_width()
    if width is None:
        width = osutils.default_terminal_width
    # we need one extra space for terminals that wrap on last char
    width = width - 1

    for cmd_name, cmd_object in sorted(shown_commands):
        plugin_name = cmd_object.plugin_name()
        if plugin_name is None:
            plugin_name = ''
        else:
            plugin_name = ' [%s]' % plugin_name

        cmd_help = cmd_object.help()
        if cmd_help:
            firstline = cmd_help.split('\n', 1)[0]
        else:
            firstline = ''
        helpstring = '%-*s %s%s' % (max_name, cmd_name, firstline, plugin_name)
        lines = utextwrap.wrap(
            helpstring, subsequent_indent=indent,
            width=width,
            break_long_words=False)
        for line in lines:
            out.append(line + '\n')
    return ''.join(out)
コード例 #34
0
ファイル: bashcomp.py プロジェクト: GymWenFLL/tpp_libs
    def command(self, name):
        cmd = commands.get_cmd_object(name)
        cmd_data = CommandData(name)

        plugin_name = cmd.plugin_name()
        if plugin_name is not None:
            if (self.selected_plugins is not None and
                plugin not in self.selected_plugins):
                return None
            plugin_data = self.data.plugins.get(plugin_name)
            if plugin_data is None:
                plugin_data = PluginData(plugin_name)
                self.data.plugins[plugin_name] = plugin_data
            cmd_data.plugin = plugin_data
        self.data.commands.append(cmd_data)

        # Find all aliases to the command; both cmd-defined and user-defined.
        # We assume a user won't override one command with a different one,
        # but will choose completely new names or add options to existing
        # ones while maintaining the actual command name unchanged.
        cmd_data.aliases.extend(cmd.aliases)
        cmd_data.aliases.extend(sorted([useralias
            for cmdalias in cmd_data.aliases
            if cmdalias in self.user_aliases
            for useralias in self.user_aliases[cmdalias]
            if useralias not in cmd_data.aliases]))

        opts = cmd.options()
        for optname, opt in sorted(opts.iteritems()):
            cmd_data.options.extend(self.option(opt))

        if 'help' == name or 'help' in cmd.aliases:
            cmd_data.fixed_words = ('($cmds %s)' %
                " ".join(sorted(help_topics.topic_registry.keys())))

        return cmd_data
コード例 #35
0
ファイル: pull.py プロジェクト: biji/qbzr
 def do_start(self):
     if self.tree:
         dest = self.tree.basedir
     else:
         dest = self.branch.base
     args = []
     if dest != osutils.getcwd():
         args.extend(('--directory', dest))
     if self.ui.overwrite.isChecked():
         args.append('--overwrite')
     if self.ui.remember.isChecked():
         args.append('--remember')
     if self.ui.create_prefix.isChecked():
         args.append('--create-prefix')
     if self.ui.use_existing_dir.isChecked():
         args.append('--use-existing-dir')
     if 'strict' in get_cmd_object('push').options() and self._no_strict:
         # force --no-strict because we checking blocking conditions
         # in validate method (see below).
         args.append('--no-strict')
     location = unicode(self.ui.location.currentText())
     if location and location != self.default_location:
         args.insert(0, location)
     self.process_widget.do_start(None, 'push', *args)
コード例 #36
0
ファイル: test_commands.py プロジェクト: GymWenFLL/tpp_libs
 def test_get_unrelated_does_not_import(self):
     commands.plugin_cmds.register_lazy("cmd_fake", [], "bzrlib.tests.fake_command")
     self.addCleanup(self.remove_fake)
     commands.get_cmd_object("status")
     self.assertFalse(lazy_command_imported)
コード例 #37
0
ファイル: test_commands.py プロジェクト: GymWenFLL/tpp_libs
 def test_aliases(self):
     commands.plugin_cmds.register_lazy("cmd_fake", ["fake_alias"], "bzrlib.tests.fake_command")
     self.addCleanup(self.remove_fake)
     fake_instance = commands.get_cmd_object("fake_alias")
     self.assertIsFakeCommand(fake_instance)
コード例 #38
0
 def test_get_unrelated_does_not_import(self):
     commands.plugin_cmds.register_lazy('cmd_fake', [],
                                        'bzrlib.tests.fake_command')
     self.addCleanup(self.remove_fake)
     commands.get_cmd_object('status')
     self.assertFalse(lazy_command_imported)
コード例 #39
0
 def test_aliases(self):
     commands.plugin_cmds.register_lazy('cmd_fake', ['fake_alias'],
                                        'bzrlib.tests.fake_command')
     self.addCleanup(self.remove_fake)
     fake_instance = commands.get_cmd_object('fake_alias')
     self.assertIsFakeCommand(fake_instance)