Exemplo n.º 1
0
    def run(self, filename, all=False, plain=False, line='1', revision=None):
        Gtk = open_display()

        try:
            line = int(line)
        except ValueError:
            raise BzrCommandError('Line argument ("%s") is not a number.' % 
                                  line)

        from annotate.gannotate import GAnnotateWindow
        from annotate.config import GAnnotateConfig
        from bzrlib.bzrdir import BzrDir

        wt, br, path = BzrDir.open_containing_tree_or_branch(filename)
        if wt is not None:
            tree = wt
        else:
            tree = br.basis_tree()

        file_id = tree.path2id(path)

        if file_id is None:
            raise NotVersionedError(filename)
        if revision is not None:
            if len(revision) != 1:
                raise BzrCommandError("Only 1 revion may be specified.")
            revision_id = revision[0].as_revision_id(br)
            tree = br.repository.revision_tree(revision_id)
        else:
            revision_id = getattr(tree, 'get_revision_id', lambda: None)()

        window = GAnnotateWindow(all, plain, branch=br)
        window.connect("destroy", lambda w: Gtk.main_quit())
        config = GAnnotateConfig(window)
        window.show()
        br.lock_read()
        if wt is not None:
            wt.lock_read()
        try:
            window.annotate(tree, br, file_id)
            window.jump_to_line(line)
            Gtk.main()
        finally:
            br.unlock()
            if wt is not None:
                wt.unlock()
Exemplo n.º 2
0
    def run(self, command_list, externals_only=False, shell=False, dry_run=False):
        # TODO: support setting the base location with -d
        externals.disable_hooks = True
        (tree, branch, relpath) = BzrDir.open_containing_tree_or_branch('.')

        global _main_base
        if _main_base is None:
            _main_base = branch.base

        ex = externals.Externals(branch, branch.last_revision(),
            root=tree.basedir)
        if ex.read_config():
            # run ecmd command in each externals for multilevel
            ecmd = ['ecmd']
            if shell:
                ecmd += ['--shell']
            if dry_run:
                ecmd += ['--dry-run']
            ex.adjust_verbosity(ecmd)

            for location, rel_path, revision in ex.branch_iterator(): #@UnusedVariable
                os.chdir(os.path.join(ex.cwd, rel_path))
                run_bzr_catch_user_errors(ecmd + ['--'] + command_list)

        if not externals_only:
            # parse arguments of command and execute
            if not is_quiet():
                if branch.base != _main_base:
                    note('Run command in external: ' + self._relpath(ex.root))
                else:
                    note('Run command in main branch:')
            command_list = self._substitute_in_commandlist(
                command_list, self._relpath(ex.root))
            ex.adjust_verbosity(command_list)
            if not dry_run:
                os.chdir(ex.root)
                if shell:
                    os.system(' '.join(command_list))
                else:
                    run_bzr_catch_user_errors(command_list)

        os.chdir(ex.cwd)