30
30
bzrlib.status, bzrlib.delta.TreeDelta.show and bzrlib.log.LongLogFormatter)
34
from bzrlib.lazy_import import lazy_import
35
lazy_import(globals(), """
37
33
from bzrlib import (
47
from bzrlib.option import Option, custom_help
48
from bzrlib.commands import display_command, register_command
52
from xml_errors import handle_error_xml
37
from bzrlib.commands import plugin_cmds
56
39
version_info = info.bzr_plugin_version
57
40
plugin_name = info.bzr_plugin_name
59
null_option = option.Option('null',
60
help='Write an ascii NUL (\\0) as the final char.')
63
class cmd_xmlstatus(commands.Command):
64
"""Display status summary.
66
This reports on versioned and unknown files, reporting them
67
grouped by state. Possible states are:
70
Versioned in the working copy but not in the previous revision.
73
Versioned in the previous revision but removed or deleted
77
Path of this file changed from the previous revision;
78
the text may also have changed. This includes files whose
79
parent directory was renamed.
82
Text has changed since the previous revision.
85
File kind has been changed (e.g. from file to directory).
88
Not versioned and not matching an ignore pattern.
90
To see ignored files use 'bzr ignored'. For details on the
91
changes to file texts, use 'bzr diff'.
93
Note that --short or -S gives status flags for each item, similar
94
to Subversion's status command. To get output similar to svn -q,
97
If no arguments are specified, the status of the entire working
98
directory is shown. Otherwise, only the status of the specified
99
files or directories is reported. If a directory is given, status
100
is reported for everything inside that directory.
102
If a revision argument is given, the status is calculated against
103
that revision, or between two revisions if two are provided.
106
takes_args = ['file*']
107
takes_options = ['show-ids', 'revision', 'change',
108
Option('versioned', help='Only show versioned files.',
112
encoding_type = 'replace'
116
def run(self, file_list=None, revision=None, versioned=False, null=False):
117
from statusxml import show_tree_status_xml
118
tree, file_list = builtins.tree_files(file_list)
122
show_tree_status_xml(tree, show_ids=True,
123
specific_files=file_list, revision=revision,
124
to_file=to_file, versioned=versioned)
127
self.outf.write('\n')
130
class cmd_xmlannotate(commands.Command):
131
"""Show the origin of each line in a file.
133
This prints out the given file with an annotation on the left side
134
indicating which revision, author and date introduced the change.
136
If the origin is the same for a run of consecutive lines, it is
137
shown only at the top, unless the --all option is given.
140
takes_args = ['filename']
141
takes_options = ['revision', 'show-ids', null_option]
143
encoding_type = 'exact'
147
def run(self, filename, revision=None, show_ids=False, null=False):
148
from annotatexml import annotate_file_xml
149
wt, branch, relpath = \
150
bzrdir.BzrDir.open_containing_tree_or_branch(filename)
155
wt_root_path = wt.id2abspath(wt.get_root_id())
158
revision_id = branch.last_revision()
159
elif len(revision) != 1:
160
raise bzrlib.errors.BzrCommandError(
161
'xmlannotate --revision takes exactly 1 argument')
163
revision_id = revision[0].in_history(branch).rev_id
164
tree = branch.repository.revision_tree(revision_id)
166
file_id = wt.path2id(relpath)
168
file_id = tree.path2id(relpath)
170
raise bzrlib.errors.NotVersionedError(filename)
172
file_version = tree.inventory[file_id].revision
173
# always run with --all and --long options
174
# to get the author of each line
175
annotate_file_xml(branch=branch, rev_id=file_version,
176
file_id=file_id, to_file=self.outf, show_ids=show_ids,
177
wt_root_path=wt_root_path, file_path=relpath)
179
self.outf.write('\0')
180
self.outf.write('\n')
188
class cmd_xmlmissing(commands.Command):
189
"""Show unmerged/unpulled revisions between two branches.
191
OTHER_BRANCH may be local or remote.
194
takes_args = ['other_branch?']
196
Option('reverse', 'Reverse the order of revisions.'),
198
'Display changes in the local branch only.'),
199
Option('this' , 'Same as --mine-only.'),
200
Option('theirs-only',
201
'Display changes in the remote branch only.'),
202
Option('other', 'Same as --theirs-only.'),
207
encoding_type = 'replace'
211
def run(self, *args, **kwargs):
212
from missingxml import show_missing_xml
214
if self.outf is None:
215
self.outf = sys.stdout
217
show_missing_xml(self, log_format=logxml.XMLLogFormatter,
219
if getattr(kwargs, 'null', False):
220
self.outf.write('\0')
221
self.outf.write('\n')
224
class cmd_xmlinfo(commands.Command):
225
"""Show information about a working tree, branch or repository.
227
This command will show all known locations and formats associated to the
228
tree, branch or repository. Statistical information is included with
231
Branches and working trees will also report any missing revisions.
234
takes_args = ['location?']
235
takes_options = ['verbose', null_option]
236
encoding_type = 'replace'
240
def run(self, *args, **kwargs):
242
if kwargs.has_key('location'):
243
location = kwargs['location']
244
if kwargs.has_key('verbose') and kwargs['verbose']:
248
from infoxml import show_bzrdir_info_xml
250
from bzrlib.urlutils import normalize_url
251
location = normalize_url(location)
252
show_bzrdir_info_xml(bzrdir.BzrDir.open_containing(location)[0],
253
verbose=noise_level, outfile=self.outf)
254
if getattr(kwargs, 'null', False):
255
self.outf.write('\0')
256
self.outf.write('\n')
259
class cmd_xmlplugins(commands.Command):
260
"""List the installed plugins.
262
This command displays the list of installed plugins including
263
version of plugin and a short description of each.
267
takes_options = ['verbose', null_option]
271
def run(self, *args, **kwargs):
273
from inspect import getdoc
274
if self.outf is None:
275
self.outf = sys.stdout
277
self.outf.write('<?xml version="1.0" encoding="%s"?>' % \
278
bzrlib.osutils.get_user_encoding())
279
self.outf.write('<plugins>')
280
from writer import _escape_cdata
281
for name, plugin in bzrlib.plugin.plugins().items():
282
self.outf.write('<plugin>')
283
self.outf.write('<name>%s</name>' % name)
284
self.outf.write('<version>%s</version>' % plugin.__version__)
285
self.outf.write('<path>%s</path>' % plugin.path())
286
d = getdoc(plugin.module)
288
self.outf.write('<doc>%s</doc>' % _escape_cdata(d))
289
self.outf.write('</plugin>')
290
self.outf.write('</plugins>')
291
if getattr(kwargs, 'null', False):
292
self.outf.write('\0')
293
self.outf.write('\n')
296
class cmd_xmlversion(commands.Command):
297
"""Show version of bzr."""
299
encoding_type = 'replace'
300
takes_options = [Option("short", help="Only print the version number."),
305
def run(self, short=False, null=False):
306
from versionxml import show_version_xml
310
self.outf.write('<?xml version="1.0" encoding="%s"?>' % \
311
bzrlib.osutils.get_user_encoding())
313
to_file.write("<version><bazaar><version>" + \
314
bzrlib.version_string + \
315
"</version></bazaar></version>")
317
show_version_xml(to_file=to_file)
323
def xmllog_options():
324
# Take a copy of the log options before modifying it
325
opts = builtins.cmd_log.takes_options[:]
326
opts.append(null_option)
327
# Remove log_format since we requires our own
328
opts.remove('log-format')
332
class cmd_xmllog(builtins.cmd_log):
333
"""Show log of a branch, file, or directory as XML."""
336
takes_options = xmllog_options()
340
def run(self, *args, **kwargs):
341
# Force our specific formatter
342
kwargs['log_format'] = logxml.XMLLogFormatter
343
# Filter out our specific option
345
null = kwargs.pop('null')
348
exit_val = builtins.cmd_log.run(self, *args, **kwargs)
350
self.outf.write('\0')
351
self.outf.write('\n')
355
class cmd_xmlls(builtins.cmd_ls):
356
"""XML representation of the list of files in a tree.
360
_see_also = ['xmlstatus']
361
takes_args = ['path?']
362
# TODO: Take a revision or remote path and list that tree instead.
366
Option('non-recursive',
367
help='Don\'t recurse into subdirectories.'),
369
help='Print paths relative to the root of the branch.'),
370
Option('unknown', help='Print unknown files.'),
371
Option('versioned', help='Print versioned files.',
373
Option('ignored', help='Print ignored files.'),
375
help='List entries of a particular kind: file, ' + \
376
'directory, symlink.',
380
encoding_type = 'replace'
385
def run(self, *args, **kwargs):
387
self.outf.write('<?xml version="1.0" encoding="%s"?>' % \
388
bzrlib.osutils.get_user_encoding())
389
lsxml.show_ls_xml(self.outf, *args, **kwargs)
390
if getattr(kwargs, 'null', False):
391
self.outf.write('\0')
392
self.outf.write('\n')
394
class cmd_start_xmlrpc(commands.Command):
395
"""Start the xmlrpc service."""
399
Option('hostname', argname='HOSTNAME', type=str,
400
help='Use the specified hostname, defaults to localhost.'),
401
Option('port', argname='PORT', type=int,
402
help='Use the specified port, defaults to 11111.'),
407
def run(self, port=11111, hostname='localhost', verbose=False):
409
hostname = socket.gethostname()
412
self.outf.write('Listening on http://'+hostname+':'+str(port)+'\n')
415
self.server = service.BzrXMLRPCServer((hostname, port),
416
logRequests=verbose, to_file=self.outf)
419
self.server.serve_forever()
421
self.server.shutdown()
424
class cmd_stop_xmlrpc(commands.Command):
425
"""Stops a xmlrpc service."""
429
Option('hostname', argname='HOSTNAME', type=str,
430
help='Use the specified hostname, defaults to localhost.'),
431
Option('port', argname='PORT', type=int,
432
help='Use the specified port, defaults to 11111.'),
437
def run(self, port=11111, hostname='localhost', verbose=False):
438
url = "http://"+hostname+":"+str(port)
440
self.outf.write('Stopping xmlrpc service on ' + url + '\n')
442
from xmlrpclib import Server
446
register_command(cmd_xmlstatus, decorate=True)
447
register_command(cmd_xmlannotate, decorate=True)
448
register_command(cmd_xmlmissing, decorate=True)
449
register_command(cmd_xmlinfo, decorate=True)
450
register_command(cmd_xmlplugins, decorate=True)
451
register_command(cmd_xmlversion, decorate=True)
452
register_command(cmd_start_xmlrpc, decorate=True)
453
register_command(cmd_stop_xmlrpc, decorate=True)
454
register_command(cmd_xmllog, decorate=True)
455
register_command(cmd_xmlls, decorate=True)
456
log.log_formatter_registry.register('xml', logxml.XMLLogFormatter,
457
'Detailed XML log format')
53
plugin_cmds.register_lazy(
55
"bzrlib.plugins.xmloutput.cmds")
56
log.log_formatter_registry.register_lazy('xml',
57
"bzrlib.plugins.xmloutput.logxml", "XMLLogFormatter",
58
'Detailed XML log format')
460
61
def load_tests(basic_tests, module, loader):