Rev 2973: (Lukas Lalinksy) Unicode-safe output from ``bzr info`` in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Tue Nov 6 11:11:23 GMT 2007
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 2973
revision-id: pqm at pqm.ubuntu.com-20071106111118-y3bzab49xldvajyh
parent: pqm at pqm.ubuntu.com-20071106101850-9tqmz90mna2r67zk
parent: bialix at ukr.net-20071106090025-v1xkcnh8i0pex4ax
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2007-11-06 11:11:18 +0000
message:
(Lukas Lalinksy) Unicode-safe output from ``bzr info``
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/info.py info.py-20050323235939-6bbfe7d9700b0b9b
bzrlib/tests/blackbox/test_non_ascii.py test_non_ascii.py-20060105214030-68010be784a5d854
------------------------------------------------------------
revno: 2968.2.1
merged: bialix at ukr.net-20071106090025-v1xkcnh8i0pex4ax
parent: pqm at pqm.ubuntu.com-20071106070621-hu1s7o5fphvhxw8m
parent: lalinsky at gmail.com-20071015114443-zkeiyt83jb1utnec
committer: Alexander Belchenko <bialix at ukr.net>
branch nick: lukas
timestamp: Tue 2007-11-06 11:00:25 +0200
message:
Unicode-safe output from ``bzr info``
------------------------------------------------------------
revno: 2904.3.2
merged: lalinsky at gmail.com-20071015114443-zkeiyt83jb1utnec
parent: lalinsky at gmail.com-20071012102138-02vel0txfdfb34b2
committer: Lukáš Lalinský <lalinsky at gmail.com>
branch nick: unicode-info
timestamp: Mon 2007-10-15 13:44:43 +0200
message:
More details in NEWS and use full self.run_bzr_decode name in the test.
------------------------------------------------------------
revno: 2904.3.1
merged: lalinsky at gmail.com-20071012102138-02vel0txfdfb34b2
parent: pqm at pqm.ubuntu.com-20071010085229-7x5al1tirr29mq0l
committer: Lukáš Lalinský <lalinsky at gmail.com>
branch nick: unicode-info
timestamp: Fri 2007-10-12 12:21:38 +0200
message:
Unicode-safe output from ``bzr info``.
This includes two changes:
- Use stdout encoded with the terminal_encoding, not plain sys.stdout.
- Replace undisplayable characters by '?'.
=== modified file 'NEWS'
--- a/NEWS 2007-11-06 07:40:44 +0000
+++ b/NEWS 2007-11-06 11:11:18 +0000
@@ -57,6 +57,10 @@
* Reconcile now shows progress bars. (Robert Collins, #159351)
+ * Unicode-safe output from ``bzr info``. The output will be encoded
+ using the terminal encoding and unrepresentable characters will be
+ replaced by '?'. (Lukáš Lalinský, #151844)
+
* Wrap medusa ftp test server as an FTPServer feature.
(Vincent Ladeuil, #157752)
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2007-11-06 07:40:44 +0000
+++ b/bzrlib/builtins.py 2007-11-06 11:11:18 +0000
@@ -1062,6 +1062,7 @@
_see_also = ['revno', 'working-trees', 'repositories']
takes_args = ['location?']
takes_options = ['verbose']
+ encoding_type = 'replace'
@display_command
def run(self, location=None, verbose=False):
@@ -1071,7 +1072,7 @@
noise_level = 0
from bzrlib.info import show_bzrdir_info
show_bzrdir_info(bzrdir.BzrDir.open_containing(location)[0],
- verbose=noise_level)
+ verbose=noise_level, outfile=self.outf)
class cmd_remove(Command):
=== modified file 'bzrlib/info.py'
--- a/bzrlib/info.py 2007-10-16 16:02:01 +0000
+++ b/bzrlib/info.py 2007-11-06 09:00:25 +0000
@@ -128,13 +128,14 @@
return [(n, locs[n]) for n in order if n in locs]
-def _show_location_info(locs):
+def _show_location_info(locs, outfile):
"""Show known locations for working, branch and repository."""
- print 'Location:'
+ outfile.write('Location:\n')
path_list = LocationList(osutils.getcwd())
for name, loc in locs:
path_list.add_url(name, loc)
- sys.stdout.writelines(path_list.get_lines())
+ outfile.writelines(path_list.get_lines())
+
def _gather_related_branches(branch):
locs = LocationList(osutils.getcwd())
@@ -144,6 +145,7 @@
locs.add_url('submit branch', branch.get_submit_branch())
return locs
+
def _show_related_info(branch, outfile):
"""Show parent and push location of branch."""
locs = _gather_related_branches(branch)
@@ -153,60 +155,66 @@
outfile.writelines(locs.get_lines())
-def _show_format_info(control=None, repository=None, branch=None, working=None):
+def _show_format_info(control=None, repository=None, branch=None,
+ working=None, outfile=None):
"""Show known formats for control, working, branch and repository."""
- print
- print 'Format:'
+ outfile.write('\n')
+ outfile.write('Format:\n')
if control:
- print ' control: %s' % control._format.get_format_description()
+ outfile.write(' control: %s\n' %
+ control._format.get_format_description())
if working:
- print ' working tree: %s' % working._format.get_format_description()
+ outfile.write(' working tree: %s\n' %
+ working._format.get_format_description())
if branch:
- print ' branch: %s' % branch._format.get_format_description()
+ outfile.write(' branch: %s\n' %
+ branch._format.get_format_description())
if repository:
- print ' repository: %s' % repository._format.get_format_description()
-
-
-def _show_locking_info(repository, branch=None, working=None):
+ outfile.write(' repository: %s\n' %
+ repository._format.get_format_description())
+
+
+def _show_locking_info(repository, branch=None, working=None, outfile=None):
"""Show locking status of working, branch and repository."""
if (repository.get_physical_lock_status() or
(branch and branch.get_physical_lock_status()) or
(working and working.get_physical_lock_status())):
- print
- print 'Lock status:'
+ outfile.write('\n')
+ outfile.write('Lock status:\n')
if working:
if working.get_physical_lock_status():
status = 'locked'
else:
status = 'unlocked'
- print ' working tree: %s' % status
+ outfile.write(' working tree: %s\n' % status)
if branch:
if branch.get_physical_lock_status():
status = 'locked'
else:
status = 'unlocked'
- print ' branch: %s' % status
+ outfile.write(' branch: %s\n' % status)
if repository:
if repository.get_physical_lock_status():
status = 'locked'
else:
status = 'unlocked'
- print ' repository: %s' % status
-
-
-def _show_missing_revisions_branch(branch):
+ outfile.write(' repository: %s\n' % status)
+
+
+def _show_missing_revisions_branch(branch, outfile):
"""Show missing master revisions in branch."""
# Try with inaccessible branch ?
master = branch.get_master_branch()
if master:
local_extra, remote_extra = find_unmerged(branch, master)
if remote_extra:
- print
- print 'Branch is out of date: missing %d revision%s.' % (
- len(remote_extra), plural(len(remote_extra)))
-
-
-def _show_missing_revisions_working(working):
+ outfile.write('\n')
+ outfile.write(('Branch is out of date: missing %d '
+ 'revision%s.\n') % (len(remote_extra),
+ plural(len(remote_extra))))
+
+
+def _show_missing_revisions_working(working, outfile):
"""Show missing revisions in working tree."""
branch = working.branch
basis = working.basis_tree()
@@ -220,24 +228,24 @@
if branch_revno and tree_last_id != branch_last_revision:
tree_last_revno = branch.revision_id_to_revno(tree_last_id)
missing_count = branch_revno - tree_last_revno
- print
- print 'Working tree is out of date: missing %d revision%s.' % (
- missing_count, plural(missing_count))
-
-
-def _show_working_stats(working):
+ outfile.write('\n')
+ outfile.write(('Working tree is out of date: missing %d '
+ 'revision%s.\n') % (missing_count, plural(missing_count)))
+
+
+def _show_working_stats(working, outfile):
"""Show statistics about a working tree."""
basis = working.basis_tree()
work_inv = working.inventory
delta = working.changes_from(basis, want_unchanged=True)
- print
- print 'In the working tree:'
- print ' %8s unchanged' % len(delta.unchanged)
- print ' %8d modified' % len(delta.modified)
- print ' %8d added' % len(delta.added)
- print ' %8d removed' % len(delta.removed)
- print ' %8d renamed' % len(delta.renamed)
+ outfile.write('\n')
+ outfile.write('In the working tree:\n')
+ outfile.write(' %8s unchanged\n' % len(delta.unchanged))
+ outfile.write(' %8d modified\n' % len(delta.modified))
+ outfile.write(' %8d added\n' % len(delta.added))
+ outfile.write(' %8d removed\n' % len(delta.removed))
+ outfile.write(' %8d renamed\n' % len(delta.renamed))
ignore_cnt = unknown_cnt = 0
for path in working.extras():
@@ -245,61 +253,65 @@
ignore_cnt += 1
else:
unknown_cnt += 1
- print ' %8d unknown' % unknown_cnt
- print ' %8d ignored' % ignore_cnt
+ outfile.write(' %8d unknown\n' % unknown_cnt)
+ outfile.write(' %8d ignored\n' % ignore_cnt)
dir_cnt = 0
for file_id in work_inv:
if (work_inv.get_file_kind(file_id) == 'directory' and
not work_inv.is_root(file_id)):
dir_cnt += 1
- print ' %8d versioned %s' \
- % (dir_cnt,
- plural(dir_cnt, 'subdirectory', 'subdirectories'))
-
-
-def _show_branch_stats(branch, verbose):
+ outfile.write(' %8d versioned %s\n' % (dir_cnt,
+ plural(dir_cnt, 'subdirectory', 'subdirectories')))
+
+
+def _show_branch_stats(branch, verbose, outfile):
"""Show statistics about a branch."""
revno, head = branch.last_revision_info()
- print
- print 'Branch history:'
- print ' %8d revision%s' % (revno, plural(revno))
+ outfile.write('\n')
+ outfile.write('Branch history:\n')
+ outfile.write(' %8d revision%s\n' % (revno, plural(revno)))
stats = branch.repository.gather_stats(head, committers=verbose)
if verbose:
committers = stats['committers']
- print ' %8d committer%s' % (committers, plural(committers))
+ outfile.write(' %8d committer%s\n' % (committers,
+ plural(committers)))
if revno:
timestamp, timezone = stats['firstrev']
age = int((time.time() - timestamp) / 3600 / 24)
- print ' %8d day%s old' % (age, plural(age))
- print ' first revision: %s' % osutils.format_date(timestamp,
- timezone)
+ outfile.write(' %8d day%s old\n' % (age, plural(age)))
+ outfile.write(' first revision: %s\n' %
+ osutils.format_date(timestamp, timezone))
timestamp, timezone = stats['latestrev']
- print ' latest revision: %s' % osutils.format_date(timestamp,
- timezone)
+ outfile.write(' latest revision: %s\n' %
+ osutils.format_date(timestamp, timezone))
return stats
-def _show_repository_info(repository):
+def _show_repository_info(repository, outfile):
"""Show settings of a repository."""
if repository.make_working_trees():
- print
- print 'Create working tree for new branches inside the repository.'
-
-
-def _show_repository_stats(stats):
+ outfile.write('\n')
+ outfile.write('Create working tree for new branches inside '
+ 'the repository.\n')
+
+
+def _show_repository_stats(stats, outfile):
"""Show statistics about a repository."""
if 'revisions' in stats or 'size' in stats:
- print
- print 'Repository:'
+ outfile.write('\n')
+ outfile.write('Repository:\n')
if 'revisions' in stats:
revisions = stats['revisions']
- print ' %8d revision%s' % (revisions, plural(revisions))
+ outfile.write(' %8d revision%s\n' % (revisions, plural(revisions)))
if 'size' in stats:
- print ' %8d KiB' % (stats['size']/1024)
-
-def show_bzrdir_info(a_bzrdir, verbose=False):
+ outfile.write(' %8d KiB\n' % (stats['size']/1024))
+
+
+def show_bzrdir_info(a_bzrdir, verbose=False, outfile=None):
"""Output to stdout the 'info' for a_bzrdir."""
+ if outfile is None:
+ outfile = sys.stdout
try:
tree = a_bzrdir.open_workingtree(
recommend_upgrade=False)
@@ -327,42 +339,46 @@
lockable.lock_read()
try:
- show_component_info(a_bzrdir, repository, branch, tree, verbose)
+ show_component_info(a_bzrdir, repository, branch, tree, verbose,
+ outfile)
finally:
lockable.unlock()
def show_component_info(control, repository, branch=None, working=None,
- verbose=1):
+ verbose=1, outfile=None):
"""Write info about all bzrdir components to stdout"""
+ if outfile is None:
+ outfile = sys.stdout
if verbose is False:
verbose = 1
if verbose is True:
verbose = 2
layout = describe_layout(repository, branch, working)
format = describe_format(control, repository, branch, working)
- print "%s (format: %s)" % (layout, format)
- _show_location_info(gather_location_info(repository, branch, working))
+ outfile.write("%s (format: %s)\n" % (layout, format))
+ _show_location_info(gather_location_info(repository, branch, working),
+ outfile)
if branch is not None:
- _show_related_info(branch, sys.stdout)
+ _show_related_info(branch, outfile)
if verbose == 0:
return
- _show_format_info(control, repository, branch, working)
- _show_locking_info(repository, branch, working)
+ _show_format_info(control, repository, branch, working, outfile)
+ _show_locking_info(repository, branch, working, outfile)
if branch is not None:
- _show_missing_revisions_branch(branch)
+ _show_missing_revisions_branch(branch, outfile)
if working is not None:
- _show_missing_revisions_working(working)
- _show_working_stats(working)
+ _show_missing_revisions_working(working, outfile)
+ _show_working_stats(working, outfile)
elif branch is not None:
- _show_missing_revisions_branch(branch)
+ _show_missing_revisions_branch(branch, outfile)
if branch is not None:
- stats = _show_branch_stats(branch, verbose==2)
+ stats = _show_branch_stats(branch, verbose==2, outfile)
else:
stats = repository.gather_stats()
if branch is None and working is None:
- _show_repository_info(repository)
- _show_repository_stats(stats)
+ _show_repository_info(repository, outfile)
+ _show_repository_stats(stats, outfile)
def describe_layout(repository=None, branch=None, tree=None):
@@ -449,27 +465,3 @@
if len(new_candidates) > 0:
candidates = new_candidates
return ' or '.join(candidates)
-
-
- at deprecated_function(zero_eighteen)
-def show_tree_info(working, verbose):
- """Output to stdout the 'info' for working."""
- branch = working.branch
- repository = branch.repository
- control = working.bzrdir
- show_component_info(control, repository, branch, working, verbose)
-
-
- at deprecated_function(zero_eighteen)
-def show_branch_info(branch, verbose):
- """Output to stdout the 'info' for branch."""
- repository = branch.repository
- control = branch.bzrdir
- show_component_info(control, repository, branch, verbose=verbose)
-
-
- at deprecated_function(zero_eighteen)
-def show_repository_info(repository, verbose):
- """Output to stdout the 'info' for repository."""
- control = repository.bzrdir
- show_component_info(control, repository, verbose=verbose)
=== modified file 'bzrlib/tests/blackbox/test_non_ascii.py'
--- a/bzrlib/tests/blackbox/test_non_ascii.py 2007-10-02 07:14:11 +0000
+++ b/bzrlib/tests/blackbox/test_non_ascii.py 2007-10-15 11:44:43 +0000
@@ -546,3 +546,9 @@
txt = bzr('missing empty-tree', encoding='ascii', retcode=1)
self.assertEqual(-1, txt.find(msg))
self.assertNotEqual(-1, txt.find(msg.encode('ascii', 'replace')))
+
+ def test_info(self):
+ self.run_bzr_decode(['branch', u'.', self.info['directory']])
+ self.run_bzr_decode(['info', self.info['directory']])
+ self.run_bzr_decode(['info', self.info['directory']],
+ encoding='ascii')
More information about the bazaar-commits
mailing list