~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzr.py

  • Committer: mbp at sourcefrog
  • Date: 2005-03-09 07:40:07 UTC
  • Revision ID: mbp@sourcefrog.net-20050309074007-597831f212ecfc90
allow --option=ARG syntax

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
"""
64
64
 
65
65
# not currently working:
 
66
#  bzr check
 
67
#       Run internal consistency checks.
66
68
#  bzr info
67
69
#       Show some information about this branch.
68
70
 
113
115
## TODO: Perhaps make UUIDs predictable in test mode to make it easier
114
116
## to compare output?
115
117
 
116
 
## TODO: Some kind of global code to generate the right Branch object
117
 
## to work on.  Almost, but not quite all, commands need one, and it
118
 
## can be taken either from their parameters or their working
119
 
## directory.
120
 
 
 
118
 
 
119
 
 
120
 
 
121
######################################################################
 
122
# check status
121
123
 
122
124
 
123
125
def cmd_status(all=False):
139
141
    Branch('.').get_revision(revision_id).write_xml(sys.stdout)
140
142
 
141
143
 
 
144
def cmd_get_inventory(inventory_id):
 
145
    """Return inventory in XML by hash"""
 
146
    Branch('.').get_inventory(inventory_hash).write_xml(sys.stdout)
 
147
 
 
148
 
 
149
def cmd_get_revision_inventory(revision_id):
 
150
    """Output inventory for a revision."""
 
151
    b = Branch('.')
 
152
    b.get_revision_inventory(revision_id).write_xml(sys.stdout)
 
153
 
 
154
 
142
155
def cmd_get_file_text(text_id):
143
156
    """Get contents of a file by hash."""
144
157
    sf = Branch('.').text_store[text_id]
181
194
def cmd_info():
182
195
    b = Branch('.')
183
196
    print 'branch format:', b.controlfile('branch-format', 'r').readline().rstrip('\n')
184
 
 
185
 
    def plural(n, base='', pl=None):
186
 
        if n == 1:
187
 
            return base
188
 
        elif pl is not None:
189
 
            return pl
190
 
        else:
191
 
            return 's'
192
 
 
193
 
    count_version_dirs = 0
194
 
 
195
 
    count_status = {'A': 0, 'D': 0, 'M': 0, 'R': 0, '?': 0, 'I': 0, '.': 0}
196
 
    for st_tup in bzrlib.diff_trees(b.basis_tree(), b.working_tree()):
197
 
        fs = st_tup[0]
198
 
        count_status[fs] += 1
199
 
        if fs not in ['I', '?'] and st_tup[4] == 'directory':
200
 
            count_version_dirs += 1
201
 
 
202
 
    print
203
 
    print 'in the working tree:'
204
 
    for name, fs in (('unchanged', '.'),
205
 
                     ('modified', 'M'), ('added', 'A'), ('removed', 'D'),
206
 
                     ('renamed', 'R'), ('unknown', '?'), ('ignored', 'I'),
207
 
                     ):
208
 
        print '  %5d %s' % (count_status[fs], name)
209
 
    print '  %5d versioned subdirector%s' % (count_version_dirs,
210
 
                                             plural(count_version_dirs, 'y', 'ies'))
211
 
 
212
 
    print
213
 
    print 'branch history:'
214
 
    history = b.revision_history()
215
 
    revno = len(history)
216
 
    print '  %5d revision%s' % (revno, plural(revno))
217
 
    committers = Set()
218
 
    for rev in history:
219
 
        committers.add(b.get_revision(rev).committer)
220
 
    print '  %5d committer%s' % (len(committers), plural(len(committers)))
221
 
    if revno > 0:
222
 
        firstrev = b.get_revision(history[0])
223
 
        age = int((time.time() - firstrev.timestamp) / 3600 / 24)
224
 
        print '  %5d day%s old' % (age, plural(age))
225
 
        print '  first revision: %s' % format_date(firstrev.timestamp,
226
 
                                                 firstrev.timezone)
227
 
 
228
 
        lastrev = b.get_revision(history[-1])
229
 
        print '  latest revision: %s' % format_date(lastrev.timestamp,
230
 
                                                    lastrev.timezone)
231
 
        
232
 
    
 
197
    print 'revision number:', b.revno()
 
198
    print 'number of versioned files:', len(b.read_working_inventory())
233
199
 
234
200
 
235
201
def cmd_remove(file_list, verbose=False):
581
547
    lookup table, something about the available options, what optargs
582
548
    they take, and which commands will accept them.
583
549
 
584
 
    >>> parse_args('--help'.split())
 
550
    >>> parse_args('bzr --help'.split())
585
551
    ([], {'help': True})
586
 
    >>> parse_args('--version'.split())
 
552
    >>> parse_args('bzr --version'.split())
587
553
    ([], {'version': True})
588
 
    >>> parse_args('status --all'.split())
 
554
    >>> parse_args('bzr status --all'.split())
589
555
    (['status'], {'all': True})
590
 
    >>> parse_args('commit --message=biter'.split())
 
556
    >>> parse_args('bzr commit --message=biter'.split())
591
557
    (['commit'], {'message': u'biter'})
592
558
    """
593
559
    args = []
595
561
 
596
562
    # TODO: Maybe handle '--' to end options?
597
563
 
598
 
    while argv:
599
 
        a = argv.pop(0)
 
564
    it = iter(argv[1:])
 
565
    while it:
 
566
        a = it.next()
600
567
        if a[0] == '-':
601
568
            optarg = None
602
569
            if a[1] == '-':
620
587
            optargfn = OPTIONS[optname]
621
588
            if optargfn:
622
589
                if optarg == None:
623
 
                    if not argv:
 
590
                    if not it:
624
591
                        bailout('option %r needs an argument' % a)
625
592
                    else:
626
 
                        optarg = argv.pop(0)
 
593
                        optarg = it.next()
627
594
                opts[optname] = optargfn(optarg)
628
595
                mutter("    option argument %r" % opts[optname])
629
596
            else:
654
621
    argdict = {}
655
622
    # TODO: Need a way to express 'cp SRC... DEST', where it matches
656
623
    # all but one.
657
 
 
658
624
    for ap in argform:
659
625
        argname = ap[:-1]
660
626
        if ap[-1] == '?':
692
658
    logging and error handling.
693
659
    """
694
660
    try:
695
 
        args, opts = parse_args(argv[1:])
 
661
        args, opts = parse_args(argv)
696
662
        if 'help' in opts:
697
663
            # TODO: pass down other arguments in case they asked for
698
664
            # help on a command name?
736
702
    ## than just a backtrace.
737
703
 
738
704
    try:
739
 
        # TODO: Lift into separate function in trace.py
740
 
        # TODO: Also show contents of /etc/lsb-release, if it can be parsed.
741
 
        #       Perhaps that should eventually go into the platform library?
742
 
        # TODO: If the file doesn't exist, add a note describing it.
743
705
        t = bzrlib.trace._tracefile
744
706
        t.write('-' * 60 + '\n')
745
707
        t.write('bzr invoked at %s\n' % format_date(time.time()))
746
 
        t.write('  by %s on %s\n' % (bzrlib.osutils.username(), socket.getfqdn()))
 
708
        t.write('  by %s on %s\n' % (bzrlib.osutils.username(), socket.gethostname()))
747
709
        t.write('  arguments: %r\n' % argv)
748
710
 
749
711
        starttime = os.times()[4]