def _show_entry(to_file, prevanno, revno_str, author, date_str, line_rev_id, text, fid): """output one entry of the annotation""" anno = 'revno="%s" author="%s" date="%s"' % \ (_escape_cdata(revno_str), _escape_cdata(author), date_str) if anno.lstrip() == empty_annotation: anno = prevanno if fid: to_file.write('<entry %s fid="%s">%s</entry>' % \ (anno, fid, _escape_cdata(text))) else: to_file.write('<entry %s>' % anno) to_file.write('%s</entry>' % _escape_cdata(text)) return anno
def log_string(self, revno, rev, max_chars=50): """Format log info into one string style. Don't truncate the string like LineLogFormatter because we are writting xml, and don't make sense to truncate the string. :param revno: revision number (int) or None. Revision numbers counts from 1. :param rev: revision info object :return: formatted truncated string """ out = [] out.append('<log>') if revno: # show revno only when is not None out.append("<revno>%s</revno>" % revno) elif rev.revision_id: out.append("<revisionid>%s</revisionid>" % rev.revision_id) out.append('<committer>%s</committer>' % _escape_cdata(rev.committer)) date_str = osutils.format_date(rev.timestamp, rev.timezone or 0, show_offset=True) out.append('<timestamp>%s</timestamp>' % date_str) out.append('<message><![CDATA[%s]]></message>' % \ _format_message(rev.message)) out.append('</log>') return " ".join(out).rstrip('\n')
def show_list(files): for item in files: path, fid, kind = item[:3] if kind == 'directory': path += '/' elif kind == 'symlink': path += '@' if len(item) == 5 and item[4]: path += '*' if show_ids: kind_id = '' if fid: kind_id = get_kind_id_element(kind, fid) to_file.write('<%s %s>%s</%s>' % (kind, kind_id, _escape_cdata(path), kind)) else: to_file.write('<%s>%s</%s>' % (kind, _escape_cdata(path), kind))
def get_cause_xml(self): """return the cause as an xml string: class, dict and message""" s = '<class>%s</class><dict>%s</dict>' \ '<message>%s</message>' \ % (self.error.__class__.__name__, self._get_dict_as_xml(self.error.__dict__), _escape_cdata(str(self.error))) return s
def __str__(self): """__str__""" xml = '<?xml version="1.0" encoding="%s"?>' % \ osutils.get_user_encoding() try: xml += '<error>%s</error>' % self.get_cause_xml() except Exception, e: xml += '<error><message>%s</message></error>' % \ _escape_cdata(str(e))
def __log_revision(self, revision): if revision.revno is not None: self.to_file.write('<revno>%s</revno>' % revision.revno) if revision.tags: self.to_file.write('<tags>') for tag in revision.tags: self.to_file.write('<tag>%s</tag>' % tag) self.to_file.write('</tags>') if self.show_ids: self.to_file.write('<revisionid>%s</revisionid>' % revision.rev.revision_id) if len(revision.rev.parent_ids) > 0: self.to_file.write('<parents>') for parent_id in revision.rev.parent_ids: self.to_file.write('<parent>%s</parent>' % parent_id) if len(revision.rev.parent_ids) > 0: self.to_file.write('</parents>') self.to_file.write('<committer>%s</committer>' % \ _escape_cdata(revision.rev.committer)) try: self.to_file.write('<branch-nick>%s</branch-nick>' % \ _escape_cdata(revision.rev.properties['branch-nick'])) except KeyError: pass date_str = osutils.format_date(revision.rev.timestamp, revision.rev.timezone or 0, self.show_timezone) self.to_file.write('<timestamp>%s</timestamp>' % date_str) self.to_file.write('<message><![CDATA[') if not revision.rev.message: self.to_file.write('(no message)') else: self.to_file.write(_format_message(revision.rev.message)) self.to_file.write(']]></message>') if revision.delta is not None: from statusxml import show_tree_xml self.to_file.write('<affected-files>') show_tree_xml(revision.delta, self.to_file, self.show_ids) self.to_file.write('</affected-files>')
def _show_source_tree(to_file): src_tree = _get_bzr_source_tree() if src_tree: src_revision_id = src_tree.last_revision() revno = src_tree.branch.revision_id_to_revno(src_revision_id) to_file.write(u'<source_tree>') to_file.write(u'<checkout>%s</checkout>' % src_tree.basedir) to_file.write(u'<revision>%s</revision>' % revno) to_file.write(u'<revid>%s</revid>' % src_revision_id) to_file.write(u'<branch_nick>%s</branch_nick>' % \ _escape_cdata(src_tree.branch.nick)) to_file.write(u'</source_tree>')
def run(self, *args, **kwargs): import bzrlib.plugin from inspect import getdoc if self.outf is None: self.outf = sys.stdout self.outf.write('<?xml version="1.0" encoding="%s"?>' % \ bzrlib.osutils.get_user_encoding()) self.outf.write('<plugins>') from writer import _escape_cdata for name, plugin in bzrlib.plugin.plugins().items(): self.outf.write('<plugin>') self.outf.write('<name>%s</name>' % name) self.outf.write('<version>%s</version>' % plugin.__version__) self.outf.write('<path>%s</path>' % plugin.path()) d = getdoc(plugin.module) if d: self.outf.write('<doc>%s</doc>' % _escape_cdata(d)) self.outf.write('</plugin>') self.outf.write('</plugins>') if getattr(kwargs, 'null', False): self.outf.write('\0') self.outf.write('\n')
show_tree_xml(delta, to_file, show_ids=show_ids, show_unchanged=show_unchanged, show_unversioned=want_unversioned) # show the new conflicts only for now. XXX: get them from the # delta. conflicts = new.conflicts() if specific_files is not None: conflicts = conflicts.select_conflicts(new, specific_files, ignore_misses=True, recurse=True)[1] if len(conflicts) > 0: to_file.write("<conflicts>") for conflict in conflicts: to_file.write('<conflict type="%s">%s</conflict>' % (conflict.typestring, _escape_cdata(conflict.path))) to_file.write("</conflicts>") if nonexistents: to_file.write('<nonexistents>') tag = 'nonexistent' for nonexistent in nonexistents: to_file.write('<%s>%s</%s>' % (tag, nonexistent, tag)) to_file.write('</nonexistents>') if new_is_working_tree and show_pending: show_pending_merges(new, to_file) to_file.write('</status>') finally: old.unlock() new.unlock() finally: wt.unlock()
def show_tree_xml(delta, to_file, show_ids=False, show_unchanged=False, short_status=False, show_unversioned=False): """output this delta in a (xml) status-like form to to_file.""" def show_list(files): for item in files: path, fid, kind = item[:3] if kind == 'directory': path += '/' elif kind == 'symlink': path += '@' if len(item) == 5 and item[4]: path += '*' if show_ids: kind_id = '' if fid: kind_id = get_kind_id_element(kind, fid) to_file.write('<%s %s>%s</%s>' % (kind, kind_id, _escape_cdata(path), kind)) else: to_file.write('<%s>%s</%s>' % (kind, _escape_cdata(path), kind)) if delta.removed: to_file.write('<removed>') show_list(delta.removed) to_file.write('</removed>') if delta.added: to_file.write('<added>') show_list(delta.added) to_file.write('</added>') extra_modified = [] if delta.renamed: to_file.write('<renamed>') for (oldpath, newpath, fid, kind, text_modified, meta_modified) in delta.renamed: if text_modified or meta_modified: extra_modified.append( (newpath, fid, kind, text_modified, meta_modified)) metamodified = '' if meta_modified: metamodified = 'meta_modified="true"' if show_ids: kind_id = '' if fid: kind_id = get_kind_id_element(kind, fid) to_file.write('<%s oldpath="%s" %s %s>%s</%s>' % \ (kind, _escape_cdata(oldpath), metamodified, kind_id, _escape_cdata(newpath), kind)) else: to_file.write('<%s oldpath="%s" %s >%s</%s>' % \ (kind, _escape_cdata(oldpath), metamodified, _escape_cdata(newpath), kind)) to_file.write('</renamed>') if delta.kind_changed: to_file.write('<kind_changed>') for (path, fid, old_kind, new_kind) in delta.kind_changed: if show_ids: suffix = 'suffix="%s"' % fid else: suffix = '' to_file.write('<%s oldkind="%s" %s>%s</%s>' % \ (new_kind, old_kind, suffix, _escape_cdata(path), new_kind)) to_file.write('</kind_changed>') if delta.modified or extra_modified: to_file.write('<modified>') show_list(delta.modified) show_list(extra_modified) to_file.write('</modified>') if show_unchanged and delta.unchanged: to_file.write('<unchanged>') show_list(delta.unchanged) to_file.write('</unchanged>') if show_unversioned and delta.unversioned: to_file.write('<unknown>') show_list(delta.unversioned) to_file.write('</unknown>')
show_unchanged=show_unchanged, show_unversioned=want_unversioned) # show the new conflicts only for now. XXX: get them from the # delta. conflicts = new.conflicts() if specific_files is not None: conflicts = conflicts.select_conflicts(new, specific_files, ignore_misses=True, recurse=True)[1] if len(conflicts) > 0: to_file.write("<conflicts>") for conflict in conflicts: to_file.write( '<conflict type="%s">%s</conflict>' % (conflict.typestring, _escape_cdata(conflict.path))) to_file.write("</conflicts>") if nonexistents: to_file.write('<nonexistents>') tag = 'nonexistent' for nonexistent in nonexistents: to_file.write('<%s>%s</%s>' % (tag, nonexistent, tag)) to_file.write('</nonexistents>') if new_is_working_tree and show_pending: show_pending_merges(new, to_file) to_file.write('</status>') finally: old.unlock() new.unlock() finally: wt.unlock()
def show_ls_xml(outf, revision=None, non_recursive=False, from_root=False, unknown=False, versioned=False, ignored=False, kind=None, path=None, verbose=False): if kind and kind not in ('file', 'directory', 'symlink'): raise errors.BzrCommandError('invalid kind specified') all = not (unknown or versioned or ignored) selection = {'I':ignored, '?':unknown, 'V':versioned} long_status_kind = {'I':'ignored', '?':'unknown', 'V':'versioned'} if path is None: fs_path = '.' else: if from_root: raise errors.BzrCommandError('cannot specify both --from-root' ' and PATH') fs_path = path tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch( fs_path) prefix = None if from_root: if relpath: prefix = relpath + '/' elif fs_path != '.': prefix = fs_path + '/' if revision is not None: tree = branch.repository.revision_tree( revision[0].as_revision_id(branch)) elif tree is None: tree = branch.basis_tree() tree.lock_read() try: outf.write('<list>') for fp, fc, fkind, fid, entry in tree.list_files(include_root=False, from_dir=relpath, recursive=not non_recursive): if not all and not selection[fc]: continue if kind is not None and fkind != kind: continue if prefix: fp = osutils.pathjoin(prefix, fp) if fid is None: fid = '' else: fid = '<id>%s</id>' % _escape_cdata(fid) fkind = '<kind>%s</kind>' % fkind status_kind = '<status_kind>%s</status_kind>' % long_status_kind[fc] fpath = '<path>%s</path>' % _escape_cdata(fp) if fc == 'I' and ignored: # get the pattern if tree.basedir in fp: pat = tree.is_ignored(tree.relpath(fp)) else: pat = tree.is_ignored(fp) pattern = '<pattern>%s</pattern>' % _escape_cdata(pat) else: pattern = '' outstring = '<item>%s%s%s%s%s</item>' % (fid, fkind, fpath, status_kind, pattern) outf.write(outstring) finally: outf.write('</list>') tree.unlock()
def _get_dict_as_xml(self, dict): """returns a dict as xml using <key> and <value> tags""" return ''.join(['<key>%s</key><value>%s</value>' % \ (_escape_cdata(key), _escape_cdata(str(val))) \ for key, val in dict.iteritems() if val is not None])
def show_tree_xml(delta, to_file, show_ids=False, show_unchanged=False, short_status=False, show_unversioned=False): """output this delta in a (xml) status-like form to to_file.""" def show_list(files): for item in files: path, fid, kind = item[:3] if kind == 'directory': path += '/' elif kind == 'symlink': path += '@' if len(item) == 5 and item[4]: path += '*' if show_ids: kind_id = '' if fid: kind_id = get_kind_id_element(kind, fid) to_file.write('<%s %s>%s</%s>' % (kind, kind_id, _escape_cdata(path), kind)) else: to_file.write('<%s>%s</%s>' % (kind, _escape_cdata(path), kind)) if delta.removed: to_file.write('<removed>') show_list(delta.removed) to_file.write('</removed>') if delta.added: to_file.write('<added>') show_list(delta.added) to_file.write('</added>') extra_modified = [] if delta.renamed: to_file.write('<renamed>') for (oldpath, newpath, fid, kind, text_modified, meta_modified) in delta.renamed: if text_modified or meta_modified: extra_modified.append((newpath, fid, kind, text_modified, meta_modified)) metamodified = '' if meta_modified: metamodified = 'meta_modified="true"' if show_ids: kind_id = '' if fid: kind_id = get_kind_id_element(kind, fid) to_file.write('<%s oldpath="%s" %s %s>%s</%s>' % \ (kind, _escape_cdata(oldpath), metamodified, kind_id, _escape_cdata(newpath), kind)) else: to_file.write('<%s oldpath="%s" %s >%s</%s>' % \ (kind, _escape_cdata(oldpath), metamodified, _escape_cdata(newpath), kind)) to_file.write('</renamed>') if delta.kind_changed: to_file.write('<kind_changed>') for (path, fid, old_kind, new_kind) in delta.kind_changed: if show_ids: suffix = 'suffix="%s"' % fid else: suffix = '' to_file.write('<%s oldkind="%s" %s>%s</%s>' % \ (new_kind, old_kind, suffix, _escape_cdata(path), new_kind)) to_file.write('</kind_changed>') if delta.modified or extra_modified: to_file.write('<modified>') show_list(delta.modified) show_list(extra_modified) to_file.write('</modified>') if show_unchanged and delta.unchanged: to_file.write('<unchanged>') show_list(delta.unchanged) to_file.write('</unchanged>') if show_unversioned and delta.unversioned: to_file.write('<unknown>') show_list(delta.unversioned) to_file.write('</unknown>')