~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Patch Queue Manager
  • Date: 2011-12-12 13:05:24 UTC
  • mfrom: (6352.1.5 mkdir-p)
  • Revision ID: pqm@pqm.ubuntu.com-20111212130524-l9s3fwxxy1pujx7t
(jelmer) Add -p option to 'bzr mkdir'. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
753
753
    """
754
754
 
755
755
    takes_args = ['dir+']
 
756
    takes_options = [
 
757
        Option(
 
758
            'parents',
 
759
            help='No error if existing, make parent directories as needed.',
 
760
            short_name='p'
 
761
            )
 
762
        ]
756
763
    encoding_type = 'replace'
757
764
 
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)
 
765
    @classmethod
 
766
    def add_file_with_parents(cls, wt, relpath):
 
767
        if wt.path2id(relpath) is not None:
 
768
            return
 
769
        cls.add_file_with_parents(wt, osutils.dirname(relpath))
 
770
        wt.add([relpath])
 
771
 
 
772
    @classmethod
 
773
    def add_file_single(cls, wt, relpath):
 
774
        wt.add([relpath])
 
775
 
 
776
    def run(self, dir_list, parents=False):
 
777
        if parents:
 
778
            add_file = self.add_file_with_parents
 
779
        else:
 
780
            add_file = self.add_file_single
 
781
        for dir in dir_list:
 
782
            wt, relpath = WorkingTree.open_containing(dir)
 
783
            if parents:
 
784
                os.makedirs(dir)
768
785
            else:
769
 
                raise errors.NotVersionedError(path=base)
 
786
                os.mkdir(dir)
 
787
            add_file(wt, relpath)
 
788
            if not is_quiet():
 
789
                self.outf.write(gettext('added %s\n') % dir)
770
790
 
771
791
 
772
792
class cmd_relpath(Command):