本文整理汇总了Python中bzrlib.workingtree.WorkingTree.open方法的典型用法代码示例。如果您正苦于以下问题:Python WorkingTree.open方法的具体用法?Python WorkingTree.open怎么用?Python WorkingTree.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bzrlib.workingtree.WorkingTree
的用法示例。
在下文中一共展示了WorkingTree.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_init_branch
# 需要导入模块: from bzrlib.workingtree import WorkingTree [as 别名]
# 或者: from bzrlib.workingtree.WorkingTree import open [as 别名]
def test_init_branch(self):
out, err = self.run_bzr('init')
self.assertEqual("Created a standalone tree (format: %s)\n" % (
self._default_label,), out)
self.assertEqual('', err)
# Can it handle subdirectories of branches too ?
out, err = self.run_bzr('init subdir1')
self.assertEqual("Created a standalone tree (format: %s)\n" % (
self._default_label,), out)
self.assertEqual('', err)
WorkingTree.open('subdir1')
self.run_bzr_error(['Parent directory of subdir2/nothere does not exist'],
'init subdir2/nothere')
out, err = self.run_bzr('init subdir2/nothere', retcode=3)
self.assertEqual('', out)
os.mkdir('subdir2')
out, err = self.run_bzr('init subdir2')
self.assertEqual("Created a standalone tree (format: %s)\n" % (
self._default_label,), out)
self.assertEqual('', err)
# init an existing branch.
out, err = self.run_bzr('init subdir2', retcode=3)
self.assertEqual('', out)
self.assertTrue(err.startswith('bzr: ERROR: Already a branch:'))
示例2: test_mkdir_w_nested_trees
# 需要导入模块: from bzrlib.workingtree import WorkingTree [as 别名]
# 或者: from bzrlib.workingtree.WorkingTree import open [as 别名]
def test_mkdir_w_nested_trees(self):
"""'bzr mkdir' with nested trees"""
self.make_branch_and_tree('.')
self.make_branch_and_tree('a')
self.make_branch_and_tree('a/b')
self.run_bzr(['mkdir', 'dir', 'a/dir', 'a/b/dir'])
self.assertTrue(os.path.isdir('dir'))
self.assertTrue(os.path.isdir('a/dir'))
self.assertTrue(os.path.isdir('a/b/dir'))
wt = WorkingTree.open('.')
wt_a = WorkingTree.open('a')
wt_b = WorkingTree.open('a/b')
delta = wt.changes_from(wt.basis_tree())
self.assertEquals(len(delta.added), 1)
self.assertEquals(delta.added[0][0], 'dir')
self.assertFalse(delta.modified)
delta = wt_a.changes_from(wt_a.basis_tree())
self.assertEquals(len(delta.added), 1)
self.assertEquals(delta.added[0][0], 'dir')
self.assertFalse(delta.modified)
delta = wt_b.changes_from(wt_b.basis_tree())
self.assertEquals(len(delta.added), 1)
self.assertEquals(delta.added[0][0], 'dir')
self.assertFalse(delta.modified)
示例3: test_new_files
# 需要导入模块: from bzrlib.workingtree import WorkingTree [as 别名]
# 或者: from bzrlib.workingtree.WorkingTree import open [as 别名]
def test_new_files(self):
if sys.platform == 'win32':
raise TestSkipped('chmod has no effect on win32')
t = self.make_branch_and_tree('.')
b = t.branch
with open('a', 'wb') as f: f.write('foo\n')
# ensure check_mode_r works with capital-letter file-ids like TREE_ROOT
t.add('a', 'CAPS-ID')
t.commit('foo')
chmod_r('.bzr', 0644, 0755)
check_mode_r(self, '.bzr', 0644, 0755)
# although we are modifying the filesystem
# underneath the objects, they are not locked, and thus it must
# be safe for most operations. But here we want to observe a
# mode change in the control bits, which current do not refresh
# when a new lock is taken out.
t = WorkingTree.open('.')
b = t.branch
self.assertEqualMode(0755, b.control_files._dir_mode)
self.assertEqualMode(0644, b.control_files._file_mode)
self.assertEqualMode(0755, b.bzrdir._get_dir_mode())
self.assertEqualMode(0644, b.bzrdir._get_file_mode())
# Modifying a file shouldn't break the permissions
with open('a', 'wb') as f: f.write('foo2\n')
t.commit('foo2')
# The mode should be maintained after commit
check_mode_r(self, '.bzr', 0644, 0755)
# Adding a new file should maintain the permissions
with open('b', 'wb') as f: f.write('new b\n')
t.add('b')
t.commit('new b')
check_mode_r(self, '.bzr', 0644, 0755)
# Recursively update the modes of all files
chmod_r('.bzr', 0664, 0775)
check_mode_r(self, '.bzr', 0664, 0775)
t = WorkingTree.open('.')
b = t.branch
self.assertEqualMode(0775, b.control_files._dir_mode)
self.assertEqualMode(0664, b.control_files._file_mode)
self.assertEqualMode(0775, b.bzrdir._get_dir_mode())
self.assertEqualMode(0664, b.bzrdir._get_file_mode())
with open('a', 'wb') as f: f.write('foo3\n')
t.commit('foo3')
check_mode_r(self, '.bzr', 0664, 0775)
with open('c', 'wb') as f: f.write('new c\n')
t.add('c')
t.commit('new c')
check_mode_r(self, '.bzr', 0664, 0775)
示例4: update_branches
# 需要导入模块: from bzrlib.workingtree import WorkingTree [as 别名]
# 或者: from bzrlib.workingtree.WorkingTree import open [as 别名]
def update_branches(sourcecode_directory, update_branches,
possible_transports=None, tip=False, quiet=False):
"""Update the existing branches in sourcecode."""
if possible_transports is None:
possible_transports = []
# XXX: JonathanLange 2009-11-09: Rather than updating one branch after
# another, we could instead try to get them in parallel.
for project, (branch_url, revision, optional) in (
update_branches.iteritems()):
# Update project from branch_url.
destination = os.path.join(sourcecode_directory, project)
if not quiet:
print 'Updating %s to %s' % (
project, _format_revision_name(revision, tip))
local_tree = WorkingTree.open(destination)
try:
remote_branch = Branch.open(
branch_url, possible_transports=possible_transports)
except BzrError:
if optional:
report_exception(sys.exc_info(), sys.stderr)
continue
else:
raise
possible_transports.append(
remote_branch.bzrdir.root_transport)
revision_id = get_revision_id(revision, remote_branch, tip)
try:
result = local_tree.pull(
remote_branch, stop_revision=revision_id, overwrite=True,
possible_transports=possible_transports)
except IncompatibleRepositories:
# XXX JRV 20100407: Ideally remote_branch.bzrdir._format
# should be passed into upgrade() to ensure the format is the same
# locally and remotely. Unfortunately smart server branches
# have their _format set to RemoteFormat rather than an actual
# format instance.
upgrade(destination)
# Upgraded, repoen working tree
local_tree = WorkingTree.open(destination)
result = local_tree.pull(
remote_branch, stop_revision=revision_id, overwrite=True,
possible_transports=possible_transports)
if result.old_revid == result.new_revid:
if not quiet:
print ' (No change)'
else:
if result.old_revno < result.new_revno:
change = 'Updated'
else:
change = 'Reverted'
if not quiet:
print ' (%s from %s to %s)' % (
change, result.old_revno, result.new_revno)
示例5: test_create_branch
# 需要导入模块: from bzrlib.workingtree import WorkingTree [as 别名]
# 或者: from bzrlib.workingtree.WorkingTree import open [as 别名]
def test_create_branch(self):
branch = self.make_branch('branch')
tree = branch.create_checkout('tree', lightweight=True)
tree.commit('one', rev_id='rev-1')
self.run_bzr('switch --create-branch ../branch2', working_dir='tree')
tree = WorkingTree.open('tree')
self.assertEndsWith(tree.branch.base, '/branch2/')
示例6: test_branch_push_pull_merge_copies_tags
# 需要导入模块: from bzrlib.workingtree import WorkingTree [as 别名]
# 或者: from bzrlib.workingtree.WorkingTree import open [as 别名]
def test_branch_push_pull_merge_copies_tags(self):
t = self.make_branch_and_tree('branch1')
t.commit(allow_pointless=True, message='initial commit',
rev_id='first-revid')
b1 = t.branch
b1.tags.set_tag('tag1', 'first-revid')
# branching copies the tag across
self.run_bzr('branch branch1 branch2')
b2 = Branch.open('branch2')
self.assertEquals(b2.tags.lookup_tag('tag1'), 'first-revid')
# make a new tag and pull it
b1.tags.set_tag('tag2', 'twa')
self.run_bzr('pull -d branch2 branch1')
self.assertEquals(b2.tags.lookup_tag('tag2'), 'twa')
# make a new tag and push it
b1.tags.set_tag('tag3', 'san')
self.run_bzr('push -d branch1 branch2')
self.assertEquals(b2.tags.lookup_tag('tag3'), 'san')
# make a new tag and merge it
t.commit(allow_pointless=True, message='second commit',
rev_id='second-revid')
t2 = WorkingTree.open('branch2')
t2.commit(allow_pointless=True, message='commit in second')
b1.tags.set_tag('tag4', 'second-revid')
self.run_bzr('merge -d branch2 branch1')
self.assertEquals(b2.tags.lookup_tag('tag4'), 'second-revid')
# pushing to a new location copies the tag across
self.run_bzr('push -d branch1 branch3')
b3 = Branch.open('branch3')
self.assertEquals(b3.tags.lookup_tag('tag1'), 'first-revid')
示例7: __init__
# 需要导入模块: from bzrlib.workingtree import WorkingTree [as 别名]
# 或者: from bzrlib.workingtree.WorkingTree import open [as 别名]
def __init__(self, path=None):
WorkingCopy.__init__(self)
self.path = path or os.getcwd()
self.workingtree = WorkingTree.open(self.path)
self.repository = BazaarRepository(self.workingtree.branch.user_url)
#self.repository.working_copy = self
self._current_version = self.repository._repository.revno()
示例8: test_set_and_get_view_info
# 需要导入模块: from bzrlib.workingtree import WorkingTree [as 别名]
# 或者: from bzrlib.workingtree.WorkingTree import open [as 别名]
def test_set_and_get_view_info(self):
wt = self.make_branch_and_tree('wt')
view_current = 'view-name'
view_dict = {
view_current: ['dir-1'],
'other-name': ['dir-2']}
wt.views.set_view_info(view_current, view_dict)
current, views = wt.views.get_view_info()
self.assertEquals(view_current, current)
self.assertEquals(view_dict, views)
# then reopen the tree and see they're still there
wt = WorkingTree.open('wt')
current, views = wt.views.get_view_info()
self.assertEquals(view_current, current)
self.assertEquals(view_dict, views)
# test setting a current view which does not exist
self.assertRaises(errors.NoSuchView,
wt.views.set_view_info, 'yet-another', view_dict)
current, views = wt.views.get_view_info()
self.assertEquals(view_current, current)
self.assertEquals(view_dict, views)
# test clearing the current view
wt.views.set_view_info(None, view_dict)
current, views = wt.views.get_view_info()
self.assertEquals(None, current)
self.assertEquals(view_dict, views)
示例9: test_branch_stacked_branch_stacked
# 需要导入模块: from bzrlib.workingtree import WorkingTree [as 别名]
# 或者: from bzrlib.workingtree.WorkingTree import open [as 别名]
def test_branch_stacked_branch_stacked(self):
"""Asking to stack on a stacked branch does work"""
# We have a mainline
trunk_tree = self.make_branch_and_tree('target',
format='development')
trunk_revid = trunk_tree.commit('mainline')
# and a branch from it which is stacked
branch_tree = self.make_branch_and_tree('branch',
format='development')
branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
# with some work on it
branch_revid = branch_tree.commit('moar work plz')
# you can chain branches on from there
out, err = self.run_bzr(['branch', 'branch', '--stacked', 'branch2'])
self.assertEqual('', out)
self.assertEqual('Created new stacked branch referring to %s.\n' %
branch_tree.branch.base, err)
self.assertEqual(branch_tree.branch.base,
branch.Branch.open('branch2').get_stacked_on_url())
branch2_tree = WorkingTree.open('branch2')
branch2_revid = branch2_tree.commit('work on second stacked branch')
self.assertRevisionInRepository('branch2', branch2_revid)
self.assertRevisionsInBranchRepository(
[trunk_revid, branch_revid, branch2_revid],
'branch2')
示例10: runUpdate
# 需要导入模块: from bzrlib.workingtree import WorkingTree [as 别名]
# 或者: from bzrlib.workingtree.WorkingTree import open [as 别名]
def runUpdate(filename):
branch = "versioning.git"
REMOTE_URL="bzr+ssh://bazaar.launchpad.net/~freecad-maintainers/freecad/%s" % (branch)
PUSHTO_URL="bzr+ssh://bazaar.launchpad.net/~freecad-maintainers/freecad/%s" % (branch)
LOCAL_BRANCH=path.join(gettempdir(),branch)
# Location of branch on Launchpad
remote_branch = Branch.open(REMOTE_URL)
# Location of branch on local system
local_branch = remote_branch.bzrdir.sprout(LOCAL_BRANCH).open_branch()
# Change a file in the local branch
try:
wf = open(LOCAL_BRANCH + "/src/Build/Version.h", 'w')
rf = open(filename, 'r')
except IOError as error:
raise error
else:
wf.write(rf.read())
wf.close()
# Commit the change
tree = WorkingTree.open(LOCAL_BRANCH)
tree.commit("Update version number")
示例11: create_tree
# 需要导入模块: from bzrlib.workingtree import WorkingTree [as 别名]
# 或者: from bzrlib.workingtree.WorkingTree import open [as 别名]
def create_tree(self):
'''Create the dir and working tree.'''
try:
self.logger.debug(
'Using tree in %(tree_dir)s' % {
'tree_dir': self.config.tree_dir})
if os.path.exists(self.config.tree_dir):
self.tree = WorkingTree.open(self.config.tree_dir)
if self.tree.branch.user_url != self.bzr_branch.user_url:
self.logger.debug('Tree URLs do not match: %s - %s' % (
self.bzr_branch.user_url, self.tree.branch.user_url))
raise InvalidWorkingTree(
'The `tree_dir` option for the target branch is not a '
'lightweight checkout. Please ask a project '
'administrator to resolve the issue, and try again.')
else:
self.logger.debug('Tree does not exist. Creating dir')
# Create the path up to but not including tree_dir if it does
# not exist.
parent_dir = os.path.dirname(self.config.tree_dir)
if not os.path.exists(parent_dir):
os.makedirs(parent_dir)
self.tree = self.bzr_branch.create_checkout(
self.config.tree_dir, lightweight=True)
except AttributeError:
# Store this so we can rmtree later
self.temp_tree_dir = tempfile.mkdtemp()
self.logger.debug(
'Using temp dir at %(tree_dir)s' % {
'tree_dir': self.temp_tree_dir})
self.tree = self.bzr_branch.create_checkout(self.temp_tree_dir)
self.cleanup()
示例12: test_merge_delete_before_rename_to_temp
# 需要导入模块: from bzrlib.workingtree import WorkingTree [as 别名]
# 或者: from bzrlib.workingtree.WorkingTree import open [as 别名]
def test_merge_delete_before_rename_to_temp(self):
"""delete before rename to temp
This case requires that you must not do
move-out-of-the-way before deletes:
$ touch foo
$ touch bar
$ bzr add foo bar
$ bzr commit
$ rm foo
$ bzr rm foo
$ bzr mv bar foo
$ bzr commit
"""
a_wt = self.make_branch_and_tree('a')
file('a/foo', 'wb').write('A/FOO')
file('a/bar', 'wb').write('A/BAR')
a_wt.add('foo')
a_wt.add('bar')
a_wt.commit('added foo and bar')
self.run_bzr('branch a b')
b_wt = WorkingTree.open('b')
os.unlink('b/foo')
b_wt.remove('foo')
b_wt.rename_one('bar', 'foo')
b_wt.commit('deleted foo, renamed bar to foo')
a_wt.merge_from_branch(b_wt.branch, b_wt.branch.last_revision(),
b_wt.branch.get_rev_id(1))
示例13: test_merge_rename_to_temp_before_delete
# 需要导入模块: from bzrlib.workingtree import WorkingTree [as 别名]
# 或者: from bzrlib.workingtree.WorkingTree import open [as 别名]
def test_merge_rename_to_temp_before_delete(self):
"""rename to temp before delete, source children before parents
This case requires that you must not do deletes before
move-out-of-the-way, and that you must not do children
after parents:
$ mkdir foo
$ touch foo/bar
$ bzr add foo/bar
$ bzr commit
$ bzr mv foo/bar bar
$ rmdir foo
$ bzr commit
"""
a_wt = self.make_branch_and_tree('a')
os.mkdir('a/foo')
file('a/foo/bar', 'wb').write('A/FOO/BAR')
a_wt.add('foo')
a_wt.add('foo/bar')
a_wt.commit('added foo/bar')
self.run_bzr('branch a b')
b_wt = WorkingTree.open('b')
b_wt.rename_one('foo/bar', 'bar')
os.rmdir('b/foo')
b_wt.remove('foo')
b_wt.commit('moved foo/bar to bar, deleted foo')
a_wt.merge_from_branch(b_wt.branch, b_wt.branch.last_revision(),
b_wt.branch.get_rev_id(1))
示例14: test_merge_rename_before_create
# 需要导入模块: from bzrlib.workingtree import WorkingTree [as 别名]
# 或者: from bzrlib.workingtree.WorkingTree import open [as 别名]
def test_merge_rename_before_create(self):
"""rename before create
This case requires that you must not do creates
before move-into-place:
$ touch foo
$ bzr add foo
$ bzr commit
$ bzr mv foo bar
$ touch foo
$ bzr add foo
$ bzr commit
"""
a_wt = self.make_branch_and_tree('a')
file('a/foo', 'wb').write('A/FOO')
a_wt.add('foo')
a_wt.commit('added foo')
self.run_bzr('branch a b')
b_wt = WorkingTree.open('b')
b_wt.rename_one('foo', 'bar')
file('b/foo', 'wb').write('B/FOO')
b_wt.add('foo')
b_wt.commit('moved foo to bar, added new foo')
a_wt.merge_from_branch(b_wt.branch, b_wt.branch.last_revision(),
b_wt.branch.get_rev_id(1))
示例15: test_new_files_group_sticky_bit
# 需要导入模块: from bzrlib.workingtree import WorkingTree [as 别名]
# 或者: from bzrlib.workingtree.WorkingTree import open [as 别名]
def test_new_files_group_sticky_bit(self):
if sys.platform == 'win32':
raise TestSkipped('chmod has no effect on win32')
elif sys.platform == 'darwin' or 'freebsd' in sys.platform:
# FreeBSD-based platforms create temp dirs with the 'wheel' group,
# which users are not likely to be in, and this prevents us from
# setting the sgid bit
os.chown(self.test_dir, os.getuid(), os.getgid())
t = self.make_branch_and_tree('.')
b = t.branch
# Test the group sticky bit
# Recursively update the modes of all files
chmod_r('.bzr', 0664, 02775)
check_mode_r(self, '.bzr', 0664, 02775)
t = WorkingTree.open('.')
b = t.branch
self.assertEqualMode(02775, b.control_files._dir_mode)
self.assertEqualMode(0664, b.control_files._file_mode)
self.assertEqualMode(02775, b.bzrdir._get_dir_mode())
self.assertEqualMode(0664, b.bzrdir._get_file_mode())
with open('a', 'wb') as f: f.write('foo4\n')
t.commit('foo4')
check_mode_r(self, '.bzr', 0664, 02775)
with open('d', 'wb') as f: f.write('new d\n')
t.add('d')
t.commit('new d')
check_mode_r(self, '.bzr', 0664, 02775)