[Pkg-bazaar-commits] ./bzr/unstable r77: - split info command out into separate file

mbp at sourcefrog.net mbp at sourcefrog.net
Fri Apr 10 07:51:04 UTC 2009


------------------------------------------------------------
revno: 77
committer: mbp at sourcefrog.net
timestamp: Thu 2005-03-24 11:13:07 +1100
message:
  - split info command out into separate file
added:
  bzrlib/info.py
modified:
  bzrlib/commands.py
-------------- next part --------------
=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py	2005-03-23 23:54:45 +0000
+++ b/bzrlib/commands.py	2005-03-24 00:13:07 +0000
@@ -1,6 +1,3 @@
-#! /usr/bin/python
-
-
 # Copyright (C) 2004, 2005 by Martin Pool
 # Copyright (C) 2005 by Canonical Ltd
 
@@ -212,56 +209,8 @@
 
 
 def cmd_info():
-    b = Branch('.')
-    print 'branch format:', b.controlfile('branch-format', 'r').readline().rstrip('\n')
-
-    def plural(n, base='', pl=None):
-        if n == 1:
-            return base
-        elif pl is not None:
-            return pl
-        else:
-            return 's'
-
-    count_version_dirs = 0
-
-    count_status = {'A': 0, 'D': 0, 'M': 0, 'R': 0, '?': 0, 'I': 0, '.': 0}
-    for st_tup in bzrlib.diff_trees(b.basis_tree(), b.working_tree()):
-        fs = st_tup[0]
-        count_status[fs] += 1
-        if fs not in ['I', '?'] and st_tup[4] == 'directory':
-            count_version_dirs += 1
-
-    print
-    print 'in the working tree:'
-    for name, fs in (('unchanged', '.'),
-                     ('modified', 'M'), ('added', 'A'), ('removed', 'D'),
-                     ('renamed', 'R'), ('unknown', '?'), ('ignored', 'I'),
-                     ):
-        print '  %5d %s' % (count_status[fs], name)
-    print '  %5d versioned subdirector%s' % (count_version_dirs,
-                                             plural(count_version_dirs, 'y', 'ies'))
-
-    print
-    print 'branch history:'
-    history = b.revision_history()
-    revno = len(history)
-    print '  %5d revision%s' % (revno, plural(revno))
-    committers = Set()
-    for rev in history:
-        committers.add(b.get_revision(rev).committer)
-    print '  %5d committer%s' % (len(committers), plural(len(committers)))
-    if revno > 0:
-        firstrev = b.get_revision(history[0])
-        age = int((time.time() - firstrev.timestamp) / 3600 / 24)
-        print '  %5d day%s old' % (age, plural(age))
-        print '  first revision: %s' % format_date(firstrev.timestamp,
-                                                 firstrev.timezone)
-
-        lastrev = b.get_revision(history[-1])
-        print '  latest revision: %s' % format_date(lastrev.timestamp,
-                                                    lastrev.timezone)
-        
+    import info
+    info.show_info(Branch('.'))        
     
 
 

=== added file 'bzrlib/info.py'
--- a/bzrlib/info.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/info.py	2005-03-24 00:13:07 +0000
@@ -0,0 +1,73 @@
+# Copyright (C) 2004, 2005 by Martin Pool
+# Copyright (C) 2005 by Canonical Ltd
+
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+from sets import Set
+import time
+
+import bzrlib
+from osutils import format_date
+
+def show_info(b):
+    print 'branch format:', b.controlfile('branch-format', 'r').readline().rstrip('\n')
+
+    def plural(n, base='', pl=None):
+        if n == 1:
+            return base
+        elif pl is not None:
+            return pl
+        else:
+            return 's'
+
+    count_version_dirs = 0
+
+    count_status = {'A': 0, 'D': 0, 'M': 0, 'R': 0, '?': 0, 'I': 0, '.': 0}
+    for st_tup in bzrlib.diff_trees(b.basis_tree(), b.working_tree()):
+        fs = st_tup[0]
+        count_status[fs] += 1
+        if fs not in ['I', '?'] and st_tup[4] == 'directory':
+            count_version_dirs += 1
+
+    print
+    print 'in the working tree:'
+    for name, fs in (('unchanged', '.'),
+                     ('modified', 'M'), ('added', 'A'), ('removed', 'D'),
+                     ('renamed', 'R'), ('unknown', '?'), ('ignored', 'I'),
+                     ):
+        print '  %5d %s' % (count_status[fs], name)
+    print '  %5d versioned subdirector%s' % (count_version_dirs,
+                                             plural(count_version_dirs, 'y', 'ies'))
+
+    print
+    print 'branch history:'
+    history = b.revision_history()
+    revno = len(history)
+    print '  %5d revision%s' % (revno, plural(revno))
+    committers = Set()
+    for rev in history:
+        committers.add(b.get_revision(rev).committer)
+    print '  %5d committer%s' % (len(committers), plural(len(committers)))
+    if revno > 0:
+        firstrev = b.get_revision(history[0])
+        age = int((time.time() - firstrev.timestamp) / 3600 / 24)
+        print '  %5d day%s old' % (age, plural(age))
+        print '  first revision: %s' % format_date(firstrev.timestamp,
+                                                   firstrev.timezone)
+
+        lastrev = b.get_revision(history[-1])
+        print '  latest revision: %s' % format_date(lastrev.timestamp,
+                                                    lastrev.timezone)



More information about the Pkg-bazaar-commits mailing list