~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Jelmer Vernooij
  • Date: 2011-12-19 19:15:58 UTC
  • mfrom: (6388 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6404.
  • Revision ID: jelmer@canonical.com-20111219191558-p1k7cvhjq8l6v2gm
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""builtin bzr commands"""
18
18
 
 
19
from __future__ import absolute_import
 
20
 
19
21
import os
20
22
 
21
23
import bzrlib.bzrdir
23
25
from bzrlib.lazy_import import lazy_import
24
26
lazy_import(globals(), """
25
27
import cStringIO
 
28
import errno
26
29
import sys
27
30
import time
28
31
 
753
756
    """
754
757
 
755
758
    takes_args = ['dir+']
 
759
    takes_options = [
 
760
        Option(
 
761
            'parents',
 
762
            help='No error if existing, make parent directories as needed.',
 
763
            short_name='p'
 
764
            )
 
765
        ]
756
766
    encoding_type = 'replace'
757
767
 
758
 
    def run(self, dir_list):
759
 
        for d in dir_list:
760
 
            wt, dd = WorkingTree.open_containing(d)
761
 
            base = os.path.dirname(dd)
762
 
            id = wt.path2id(base)
763
 
            if id != None:
764
 
                os.mkdir(d)
765
 
                wt.add([dd])
766
 
                if not is_quiet():
767
 
                    self.outf.write(gettext('added %s\n') % d)
 
768
    @classmethod
 
769
    def add_file_with_parents(cls, wt, relpath):
 
770
        if wt.path2id(relpath) is not None:
 
771
            return
 
772
        cls.add_file_with_parents(wt, osutils.dirname(relpath))
 
773
        wt.add([relpath])
 
774
 
 
775
    @classmethod
 
776
    def add_file_single(cls, wt, relpath):
 
777
        wt.add([relpath])
 
778
 
 
779
    def run(self, dir_list, parents=False):
 
780
        if parents:
 
781
            add_file = self.add_file_with_parents
 
782
        else:
 
783
            add_file = self.add_file_single
 
784
        for dir in dir_list:
 
785
            wt, relpath = WorkingTree.open_containing(dir)
 
786
            if parents:
 
787
                try:
 
788
                    os.makedirs(dir)
 
789
                except OSError, e:
 
790
                    if e.errno != errno.EEXIST:
 
791
                        raise
768
792
            else:
769
 
                raise errors.NotVersionedError(path=base)
 
793
                os.mkdir(dir)
 
794
            add_file(wt, relpath)
 
795
            if not is_quiet():
 
796
                self.outf.write(gettext('added %s\n') % dir)
770
797
 
771
798
 
772
799
class cmd_relpath(Command):
3686
3713
            if directory is None:
3687
3714
                # use branch if we're inside one; otherwise global config
3688
3715
                try:
3689
 
                    c = Branch.open_containing(u'.')[0].get_config()
 
3716
                    c = Branch.open_containing(u'.')[0].get_config_stack()
3690
3717
                except errors.NotBranchError:
3691
 
                    c = _mod_config.GlobalConfig()
 
3718
                    c = _mod_config.GlobalStack()
3692
3719
            else:
3693
 
                c = Branch.open(directory).get_config()
 
3720
                c = Branch.open(directory).get_config_stack()
 
3721
            identity = c.get('email')
3694
3722
            if email:
3695
 
                self.outf.write(c.user_email() + '\n')
 
3723
                self.outf.write(_mod_config.extract_email_address(identity)
 
3724
                                + '\n')
3696
3725
            else:
3697
 
                self.outf.write(c.username() + '\n')
 
3726
                self.outf.write(identity + '\n')
3698
3727
            return
3699
3728
 
3700
3729
        if email:
3711
3740
        # use global config unless --branch given
3712
3741
        if branch:
3713
3742
            if directory is None:
3714
 
                c = Branch.open_containing(u'.')[0].get_config()
 
3743
                c = Branch.open_containing(u'.')[0].get_config_stack()
3715
3744
            else:
3716
 
                c = Branch.open(directory).get_config()
 
3745
                c = Branch.open(directory).get_config_stack()
3717
3746
        else:
3718
 
            c = _mod_config.GlobalConfig()
3719
 
        c.set_user_option('email', name)
 
3747
            c = _mod_config.GlobalStack()
 
3748
        c.set('email', name)
3720
3749
 
3721
3750
 
3722
3751
class cmd_nick(Command):
5030
5059
 
5031
5060
    def _run(self, b, revision_id_list, revision):
5032
5061
        import bzrlib.gpg as gpg
5033
 
        gpg_strategy = gpg.GPGStrategy(b.get_config())
 
5062
        gpg_strategy = gpg.GPGStrategy(b.get_config_stack())
5034
5063
        if revision_id_list is not None:
5035
5064
            b.repository.start_write_group()
5036
5065
            try:
6550
6579
    takes_options = [Option('plugin', 
6551
6580
                            help='Export help text from named command '\
6552
6581
                                 '(defaults to all built in commands).',
6553
 
                            type=str)]
 
6582
                            type=str),
 
6583
                     Option('include-duplicates',
 
6584
                            help='Output multiple copies of the same msgid '
 
6585
                                 'string if it appears more than once.'),
 
6586
                            ]
6554
6587
 
6555
 
    def run(self, plugin=None):
 
6588
    def run(self, plugin=None, include_duplicates=False):
6556
6589
        from bzrlib.export_pot import export_pot
6557
 
        export_pot(self.outf, plugin)
 
6590
        export_pot(self.outf, plugin, include_duplicates)
6558
6591
 
6559
6592
 
6560
6593
def _register_lazy_builtins():