def generate(self, to_file): info = Stanza() revision_id = self._get_revision_id() if revision_id != NULL_REVISION: info.add('revision-id', revision_id) rev = self._branch.repository.get_revision(revision_id) info.add('date', create_date_str(rev.timestamp, rev.timezone)) try: revno = self._get_revno_str(revision_id) except errors.GhostRevisionsHaveNoRevno: revno = None for hook in RioVersionInfoBuilder.hooks['revision']: hook(rev, info) else: revno = '0' info.add('build-date', create_date_str()) if revno is not None: info.add('revno', revno) if self._branch.nick is not None: info.add('branch-nick', self._branch.nick) if self._check or self._include_file_revs: self._extract_file_revisions() if self._check: if self._clean: info.add('clean', 'True') else: info.add('clean', 'False') if self._include_history: log = Stanza() for (revision_id, message, timestamp, timezone) in self._iter_revision_history(): log.add('id', revision_id) log.add('message', message) log.add('date', create_date_str(timestamp, timezone)) info.add('revisions', log.to_unicode()) if self._include_file_revs: files = Stanza() for path in sorted(self._file_revisions.keys()): files.add('path', path) files.add('revision', self._file_revisions[path]) info.add('file-revisions', files.to_unicode()) to_file.write(info.to_unicode())
def test_rio_to_unicode(self): uni_data = u'\N{KATAKANA LETTER O}' s = Stanza(foo=uni_data) unicode_str = s.to_unicode() self.assertEqual(u'foo: %s\n' % (uni_data, ), unicode_str) new_s = rio.read_stanza_unicode(unicode_str.splitlines(True)) self.assertEqual(uni_data, new_s.get('foo'))
def test_nested_rio_unicode(self): uni_data = u'\N{KATAKANA LETTER O}' s = Stanza(foo=uni_data) parent_stanza = Stanza(child=s.to_unicode()) raw_lines = parent_stanza.to_lines() self.assertEqual([ b'child: foo: ' + uni_data.encode('utf-8') + b'\n', b'\t\n', ], raw_lines) new_parent = read_stanza(raw_lines) child_text = new_parent.get('child') self.assertEqual(u'foo: %s\n' % uni_data, child_text) new_child = rio.read_stanza_unicode(child_text.splitlines(True)) self.assertEqual(uni_data, new_child.get('foo'))