def _status(self, directory, path): global state if state is None: state = library_state.BzrLibraryState(ui=ui.SilentUIFactory, trace=trace.DefaultConfig()) buf = CoerceIO() w = workingtree.WorkingTree.open(directory) status.show_tree_status(w, specific_files=[path] if path else None, to_file=buf, short=True) raw = buf.getvalue() if not raw.strip(): return if path: ans = raw[:2] if ans == 'I ': # Ignored ans = None return ans dirtied = untracked = ' ' for line in raw.splitlines(): if len(line) > 1 and line[1] in 'ACDMRIN': dirtied = 'D' elif line and line[0] == '?': untracked = 'U' ans = dirtied + untracked return ans if ans.strip() else None
def status_string(self, wt, revision=None, short=False, pending=True): # use a real file rather than StringIO because it doesn't handle # Unicode very well. tof = codecs.getwriter('utf-8')(TemporaryFile()) show_tree_status(wt, to_file=tof, revision=revision, short=short, show_pending=pending) tof.seek(0) return tof.read().decode('utf-8')
def test_tree_status_specific_files(self): """Tests branch status with given specific files""" wt = self.make_branch_and_tree('.') b = wt.branch self.build_tree( ['directory/', 'directory/hello.c', 'bye.c', 'test.c', 'dir2/']) wt.add('directory') wt.add('test.c') wt.commit('testing') self.assertStatus( ['unknown:\n', ' bye.c\n', ' dir2/\n', ' directory/hello.c\n'], wt) self.assertStatus( ['? bye.c\n', '? dir2/\n', '? directory/hello.c\n'], wt, short=True) tof = StringIO() self.assertRaises(errors.PathsDoNotExist, show_tree_status, wt, specific_files=['bye.c', 'test.c', 'absent.c'], to_file=tof) tof = StringIO() show_tree_status(wt, specific_files=['directory'], to_file=tof) tof.seek(0) self.assertEquals(tof.readlines(), ['unknown:\n', ' directory/hello.c\n']) tof = StringIO() show_tree_status(wt, specific_files=['directory'], to_file=tof, short=True) tof.seek(0) self.assertEquals(tof.readlines(), ['? directory/hello.c\n']) tof = StringIO() show_tree_status(wt, specific_files=['dir2'], to_file=tof) tof.seek(0) self.assertEquals(tof.readlines(), ['unknown:\n', ' dir2/\n']) tof = StringIO() show_tree_status(wt, specific_files=['dir2'], to_file=tof, short=True) tof.seek(0) self.assertEquals(tof.readlines(), ['? dir2/\n']) tof = StringIO() revs = [RevisionSpec.from_string('0'), RevisionSpec.from_string('1')] show_tree_status(wt, specific_files=['test.c'], to_file=tof, short=True, revision=revs) tof.seek(0) self.assertEquals(tof.readlines(), ['+N test.c\n'])
def tests_revision_to_revision(self): """doing a status between two revision trees should work.""" tree = self.make_branch_and_tree('.') r1_id = tree.commit('one', allow_pointless=True) r2_id = tree.commit('two', allow_pointless=True) r2_tree = tree.branch.repository.revision_tree(r2_id) output = StringIO() show_tree_status(tree, to_file=output, revision=[RevisionSpec.from_string("revid:%s" % r1_id), RevisionSpec.from_string("revid:%s" % r2_id)])
def status_string(self, wt, specific_files=None, revision=None, short=False, pending=True, verbose=False): # use a real file rather than StringIO because it doesn't handle # Unicode very well. tof = codecs.getwriter('utf-8')(TemporaryFile()) show_tree_status(wt, specific_files=specific_files, to_file=tof, revision=revision, short=short, show_pending=pending, verbose=verbose) tof.seek(0) return tof.read().decode('utf-8')
def test_pending_specific_files(self): """With a specific file list, pending merges are not shown.""" tree = self.make_branch_and_tree('tree') self.build_tree_contents([('tree/a', 'content of a\n')]) tree.add('a') r1_id = tree.commit('one') alt = tree.bzrdir.sprout('alt').open_workingtree() self.build_tree_contents([('alt/a', 'content of a\nfrom alt\n')]) alt_id = alt.commit('alt') tree.merge_from_branch(alt.branch) output = self.make_utf8_encoded_stringio() show_tree_status(tree, to_file=output) self.assertContainsRe(output.getvalue(), 'pending merge') out, err = self.run_bzr('status tree/a') self.assertNotContainsRe(out, 'pending merge')
def make_commit_message_template(working_tree, specific_files): """Prepare a template file for a commit into a branch. Returns a unicode string containing the template. """ # TODO: make provision for this to be overridden or modified by a hook # # TODO: Rather than running the status command, should prepare a draft of # the revision to be committed, then pause and ask the user to # confirm/write a message. from StringIO import StringIO # must be unicode-safe from bzrlib.status import show_tree_status status_tmp = StringIO() show_tree_status(working_tree, specific_files=specific_files, to_file=status_tmp) return status_tmp.getvalue()
def _status(self, path): buf = CoerceIO() w = workingtree.WorkingTree.open(self.directory) status.show_tree_status(w, specific_files=[path] if path else None, to_file=buf, short=True) raw = buf.getvalue() if not raw.strip(): return if path: return raw[:2] dirtied = untracked = ' ' for line in raw.splitlines(): if len(line) > 1 and line[1] in 'ACDMRIN': dirtied = 'D' elif line and line[0] == '?': untracked = 'U' return dirtied + untracked
def show_ch(self, cr, uid, ids, context=None): if context is None: context = {} r = False b = False w = False line_brw = ids and self.browse(cr, uid, ids[0], context=context) try: r = repository.Repository.open(line_brw and line_brw.path) b = branch.Branch.open(line_brw and line_brw.path) w = workingtree.WorkingTree.open(line_brw and line_brw.path) except: pass st = False if r and b and w: status.show_tree_status(w, to_file=open('/tmp/status', 'w')) st = commands.getoutput('less /tmp/status') commands.getoutput('rm /tmp/status') res = { 'logs': st, } res_ids = self.create(cr, uid, res) obj_model = self.pool.get('ir.model.data') model_data_ids = obj_model.search( cr, uid, [('model', '=', 'ir.ui.view'), ('name', '=', 'branchinfo_form_log')]) resource_id = obj_model.read(cr, uid, model_data_ids, fields=['res_id'])[0]['res_id'] return { 'view_type': 'form', 'view_mode': 'form', 'res_model': 'branch.info.line', 'views': [(resource_id, 'form')], 'type': 'ir.actions.act_window', 'target': 'inline', 'res_id': res_ids, 'context': context, }
def assertNewContentForSetting(self, wt, eol, expected_unix, expected_win, roundtrip): """Clone a working tree and check the convenience content. If roundtrip is True, status and commit should see no changes. """ if expected_win is None: expected_win = expected_unix self.patch_rules_searcher(eol) wt2 = wt.bzrdir.sprout('tree-%s' % eol).open_workingtree() # To see exactly what got written to disk, we need an unfiltered read content = wt2.get_file('file1-id', filtered=False).read() if sys.platform == 'win32': self.assertEqual(expected_win, content) else: self.assertEqual(expected_unix, content) # Confirm that status thinks nothing has changed if the text roundtrips if roundtrip: status_io = StringIO() status.show_tree_status(wt2, to_file=status_io) self.assertEqual('', status_io.getvalue())
def test_pre_status_hook(self): """Ensure that pre_status hook is invoked with the right args. """ calls = [] _mod_status.hooks.install_named_hook('pre_status', calls.append, None) self.assertLength(0, calls) tree = self.make_branch_and_tree('.') r1_id = tree.commit('one', allow_pointless=True) r2_id = tree.commit('two', allow_pointless=True) r2_tree = tree.branch.repository.revision_tree(r2_id) output = StringIO() show_tree_status(tree, to_file=output, revision=[RevisionSpec.from_string("revid:%s" % r1_id), RevisionSpec.from_string("revid:%s" % r2_id)]) self.assertLength(1, calls) params = calls[0] self.assertIsInstance(params, _mod_status.StatusHookParams) attrs = ['old_tree', 'new_tree', 'to_file', 'versioned', 'show_ids', 'short', 'verbose', 'specific_files'] for a in attrs: self.assertTrue(hasattr(params, a), 'Attribute "%s" not found in StatusHookParam' % a)
def _status(self, directory, path): global state if state is None: state = library_state.BzrLibraryState(ui=ui.SilentUIFactory, trace=trace.DefaultConfig()) buf = CoerceIO() w = workingtree.WorkingTree.open(directory) status.show_tree_status(w, specific_files=[path] if path else None, to_file=buf, short=True) raw = buf.getvalue() if not raw.strip(): return if path: ans = raw[:2] if ans == "I ": # Ignored ans = None return ans dirtied = untracked = " " for line in raw.splitlines(): if len(line) > 1 and line[1] in "ACDMRIN": dirtied = "D" elif line and line[0] == "?": untracked = "U" ans = dirtied + untracked return ans if ans.strip() else None
def test_specific_files_conflicts(self): tree = self.make_branch_and_tree('.') self.build_tree(['dir2/']) tree.add('dir2') tree.commit('added dir2') tree.set_conflicts( conflicts.ConflictList([conflicts.ContentsConflict('foo')])) tof = StringIO() show_tree_status(tree, specific_files=['dir2'], to_file=tof) self.assertEqualDiff('', tof.getvalue()) tree.set_conflicts( conflicts.ConflictList([conflicts.ContentsConflict('dir2')])) tof = StringIO() show_tree_status(tree, specific_files=['dir2'], to_file=tof) self.assertEqualDiff('conflicts:\n Contents conflict in dir2\n', tof.getvalue()) tree.set_conflicts( conflicts.ConflictList([conflicts.ContentsConflict('dir2/file1')])) tof = StringIO() show_tree_status(tree, specific_files=['dir2'], to_file=tof) self.assertEqualDiff('conflicts:\n Contents conflict in dir2/file1\n', tof.getvalue())
def test_specific_files_conflicts(self): tree = self.make_branch_and_tree('.') self.build_tree(['dir2/']) tree.add('dir2') tree.commit('added dir2') tree.set_conflicts(conflicts.ConflictList( [conflicts.ContentsConflict('foo')])) tof = StringIO() show_tree_status(tree, specific_files=['dir2'], to_file=tof) self.assertEqualDiff('', tof.getvalue()) tree.set_conflicts(conflicts.ConflictList( [conflicts.ContentsConflict('dir2')])) tof = StringIO() show_tree_status(tree, specific_files=['dir2'], to_file=tof) self.assertEqualDiff('conflicts:\n Contents conflict in dir2\n', tof.getvalue()) tree.set_conflicts(conflicts.ConflictList( [conflicts.ContentsConflict('dir2/file1')])) tof = StringIO() show_tree_status(tree, specific_files=['dir2'], to_file=tof) self.assertEqualDiff('conflicts:\n Contents conflict in dir2/file1\n', tof.getvalue())
def test_tree_status_specific_files(self): """Tests branch status with given specific files""" wt = self.make_branch_and_tree('.') b = wt.branch self.build_tree(['directory/','directory/hello.c', 'bye.c','test.c','dir2/', 'missing.c']) wt.add('directory') wt.add('test.c') wt.commit('testing') wt.add('missing.c') unlink('missing.c') self.assertStatus([ 'missing:\n', ' missing.c\n', 'unknown:\n', ' bye.c\n', ' dir2/\n', ' directory/hello.c\n' ], wt) self.assertStatus([ '? bye.c\n', '? dir2/\n', '+! missing.c\n', '? directory/hello.c\n' ], wt, short=True) tof = StringIO() self.assertRaises(errors.PathsDoNotExist, show_tree_status, wt, specific_files=['bye.c','test.c','absent.c'], to_file=tof) tof = StringIO() show_tree_status(wt, specific_files=['directory'], to_file=tof) tof.seek(0) self.assertEquals(tof.readlines(), ['unknown:\n', ' directory/hello.c\n' ]) tof = StringIO() show_tree_status(wt, specific_files=['directory'], to_file=tof, short=True) tof.seek(0) self.assertEquals(tof.readlines(), ['? directory/hello.c\n']) tof = StringIO() show_tree_status(wt, specific_files=['dir2'], to_file=tof) tof.seek(0) self.assertEquals(tof.readlines(), ['unknown:\n', ' dir2/\n' ]) tof = StringIO() show_tree_status(wt, specific_files=['dir2'], to_file=tof, short=True) tof.seek(0) self.assertEquals(tof.readlines(), ['? dir2/\n']) tof = StringIO() revs = [RevisionSpec.from_string('0'), RevisionSpec.from_string('1')] show_tree_status(wt, specific_files=['test.c'], to_file=tof, short=True, revision=revs) tof.seek(0) self.assertEquals(tof.readlines(), ['+N test.c\n']) tof = StringIO() show_tree_status(wt, specific_files=['missing.c'], to_file=tof) tof.seek(0) self.assertEquals(tof.readlines(), ['missing:\n', ' missing.c\n']) tof = StringIO() show_tree_status(wt, specific_files=['missing.c'], to_file=tof, short=True) tof.seek(0) self.assertEquals(tof.readlines(), ['+! missing.c\n'])
def load(self, cr, uid, ids, fields, context=None): '''Overwrite default_get method to add branch description''' if context is None: context = {} if context.get('stop', False): return {} addons_path = openerp.conf.addons_paths line_ids = self.search(cr, uid, [], context=context) line_ids and self.unlink(cr, uid, line_ids, context=context) msg = ''' <table border border="1"> <tr> <td>Name</td> <td>Path</td> <td>Revno</td> <td>Revid</td> <td>Parent</td> </tr> <tr>''' lines = [] for path in addons_path: r = False b = False w = False is_branch = False try: is_branch = self.is_branch(cr, uid, ids, path, context) if is_branch: r = repository.Repository.open(is_branch) b = branch.Branch.open(is_branch) w = workingtree.WorkingTree.open(is_branch) except: pass if r and b and w: status.show_tree_status(w, to_file=open('/tmp/status', 'w')) revno = b.revno() name = b.nick parent = b.get_parent() revd = b.last_revision_info()[1] st = commands.getoutput('cat /tmp/status').strip() and \ 'uncommited'\ or 'ok' msg = msg + '''\n <tr> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <tr> ''' % (name, is_branch, revno, revd, parent) self.create(cr, uid, { 'name': name, 'revid': revd, 'parent': parent, 'revno': revno, 'st': st, 'path': is_branch }, context=context) else: revno = 0 name = path.split('/')[-1] parent = False revd = False st = 'notb' msg = msg + '''\n <tr> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <tr> ''' % (name, path, revno, revd, parent) self.create( cr, uid, { 'name': name, 'revid': revd, 'parent': parent, 'revno': revno, 'st': st, 'path': path }) msg = msg + '''\n </tr> </table> ''' res = { 'branch_info': msg, 'jose_way': True, 'line_ids': lines, 'load': True, } try: commands.getoutput('rm /tmp/status') except: pass obj_model = self.pool.get('ir.model.data') model_data_ids = obj_model.search(cr, uid, [('model', '=', 'ir.ui.view'), ('name', '=', 'branchinfo_kanban')]) resource_id = obj_model.read(cr, uid, model_data_ids, fields=['res_id'])[0]['res_id'] return { 'view_type': 'form', 'view_mode': 'form', 'res_model': 'branch.info.line', 'views': [(resource_id, 'kanban')], 'type': 'ir.actions.act_window', 'context': { 'hide_breadcrumb': True, 'stop': True }, }
def verify_status(tester, tree, value): """Verify the output of show_tree_status""" tof = StringIO() show_tree_status(tree, to_file=tof) tof.seek(0) tester.assertEqual(value, tof.readlines())