本文整理汇总了Python中bzrlib.bzrdir.BzrDir.open方法的典型用法代码示例。如果您正苦于以下问题:Python BzrDir.open方法的具体用法?Python BzrDir.open怎么用?Python BzrDir.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bzrlib.bzrdir.BzrDir
的用法示例。
在下文中一共展示了BzrDir.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _checkoutUpstreamRevision
# 需要导入模块: from bzrlib.bzrdir import BzrDir [as 别名]
# 或者: from bzrlib.bzrdir.BzrDir import open [as 别名]
def _checkoutUpstreamRevision(self, revision):
"""
Initial checkout of upstream branch, equivalent of 'bzr branch -r',
and return the last changeset.
"""
from os.path import join, exists
if exists(join(self.repository.basedir, '.bzr')):
bzrdir = BzrDir.open(self.repository.basedir)
branch = bzrdir.open_branch()
self._working_tree = bzrdir.open_workingtree()
revid = self._working_tree.last_revision()
return self._changesetFromRevision(branch, revid)
else:
parent_bzrdir = BzrDir.open(self.repository.repository)
parent_branch = parent_bzrdir.open_branch()
if revision == "INITIAL":
try:
revid = parent_branch.get_rev_id(1)
except NoSuchRevision:
return None
elif revision == "HEAD":
revid = None
else:
revid = revision
self.log.info('Extracting %r out of %r in %r...',
revid, parent_bzrdir.root_transport.base,
self.repository.basedir)
bzrdir = parent_bzrdir.sprout(self.repository.basedir, revid)
self._working_tree = bzrdir.open_workingtree()
return self._changesetFromRevision(parent_branch, revid)
示例2: run
# 需要导入模块: from bzrlib.bzrdir import BzrDir [as 别名]
# 或者: from bzrlib.bzrdir.BzrDir import open [as 别名]
def run(self, src_location, dest_location):
from bzrlib.bzrdir import BzrDir, format_registry
from bzrlib.errors import NoRepositoryPresent, NotBranchError
from bzrlib.repository import Repository
source_repo = Repository.open(src_location)
format = format_registry.make_bzrdir('rich-root-pack')
try:
target_bzrdir = BzrDir.open(dest_location)
except NotBranchError:
target_bzrdir = BzrDir.create(dest_location, format=format)
try:
target_repo = target_bzrdir.open_repository()
except NoRepositoryPresent:
target_repo = target_bzrdir.create_repository(shared=True)
target_repo.fetch(source_repo)
for name, ref in source_repo._git.heads().iteritems():
head_loc = os.path.join(dest_location, name)
try:
head_bzrdir = BzrDir.open(head_loc)
except NotBranchError:
head_bzrdir = BzrDir.create(head_loc, format=format)
try:
head_branch = head_bzrdir.open_branch()
except NotBranchError:
head_branch = head_bzrdir.create_branch()
head_branch.generate_revision_history(source_repo.get_mapping().revision_id_foreign_to_bzr(ref))
示例3: setUp
# 需要导入模块: from bzrlib.bzrdir import BzrDir [as 别名]
# 或者: from bzrlib.bzrdir.BzrDir import open [as 别名]
def setUp(self):
"""Set up tests."""
# These tests assume a branch with five revisions, and
# a branch from version 1 containing three revisions
# merged at version 2.
TestCaseWithTransport.setUp(self)
self.tree = self.make_branch_and_tree(".")
test_file = open("test_file", "w")
test_file.write("one")
test_file.close()
self.tree.add(self.tree.relpath(os.path.join(os.getcwd(),
'test_file')))
test_file_append = open("test_file_append", "a")
test_file_append.write("one\n")
test_file_append.close()
self.tree.add(self.tree.relpath(os.path.join(os.getcwd(),
'test_file_append')))
self.tree.commit(message = "add test files")
BzrDir.open(".").sprout("../temp-clone")
clone_bzrdir = BzrDir.open("../temp-clone")
clone_tree = clone_bzrdir.open_workingtree()
for content in ["one dot one", "one dot two", "one dot three"]:
test_file = open("../temp-clone/test_file", "w")
test_file.write(content)
test_file.close()
test_file_append = open("../temp-clone/test_file_append", "a")
test_file_append.write(content + "\n")
test_file_append.close()
clone_tree.commit(message = "make branch test change")
saved_subtree_revid = clone_tree.branch.last_revision()
self.tree.merge_from_branch(clone_tree.branch)
test_file = open("test_file", "w")
test_file.write("two")
test_file.close()
test_file_append = open("test_file_append", "a")
test_file_append.write("two\n")
test_file_append.close()
self.tree.commit(message = "merge external branch")
shutil.rmtree("../temp-clone")
self.subtree_rev = saved_subtree_revid
file_contents = ["three", "four", "five"]
for content in file_contents:
test_file = open("test_file", "w")
test_file.write(content)
test_file.close()
test_file_append = open("test_file_append", "a")
test_file_append.write(content + "\n")
test_file_append.close()
self.tree.commit(message = "make test change")
示例4: ensure_repo_consistency
# 需要导入模块: from bzrlib.bzrdir import BzrDir [as 别名]
# 或者: from bzrlib.bzrdir.BzrDir import open [as 别名]
def ensure_repo_consistency(self):
""" Makes sure the self.repo_location directory is a Bazaar branch.
The repo and Bazaar branch will be created if they don't already exist.
Any unknown or modified files will be commited to the branch.
"""
try:
BzrDir.open(self.repo_location)
except bzrlib.errors.NotBranchError, e:
logger.info("Location [%s] is not a Bazaar branch. Will turn it into one." % self.repo_location)
BzrDir.create_branch_convenience(self.repo_location)
示例5: ensure_repo_consistency
# 需要导入模块: from bzrlib.bzrdir import BzrDir [as 别名]
# 或者: from bzrlib.bzrdir.BzrDir import open [as 别名]
def ensure_repo_consistency(self):
""" Makes sure the self.repo_location directory is a Bazaar branch.
The repo and Bazaar branch will be created if they don't already exist.
Any unknown or modified files will be commited to the branch.
Also, 'bzr whoami' will be set to the current user so that all commands
can be traced back to an actual person (assuming everyone has their
own logins).
"""
try:
BzrDir.open(self.repo_location)
except bzrlib.errors.NotBranchError, e:
logger.info('Location [{}] is not a Bazaar branch. Will turn it into one.'.format(self.repo_location))
BzrDir.create_branch_convenience(self.repo_location)
示例6: run
# 需要导入模块: from bzrlib.bzrdir import BzrDir [as 别名]
# 或者: from bzrlib.bzrdir.BzrDir import open [as 别名]
def run(self, destination=None, remember=False, overwrite=False):
from repopush import repo_push
# get the repository for the branch we're currently in
bzrdir = BzrDir.open_containing('.')[0]
try:
branch = bzrdir.open_branch()
src_repo = branch.repository
except errors.NotBranchError:
src_repo = bzrdir.open_repository()
repo_config = LocationConfig(src_repo.bzrdir.root_transport.base)
if destination is None:
destination = repo_config.get_user_option('public_repository')
if destination is None:
raise errors.BzrCommandError('No destination specified')
dst_repo = BzrDir.open(destination).open_repository()
if remember or (repo_config.get_user_option('public_repository')
is None):
repo_config.set_user_option('public_repository',
dst_repo.bzrdir.root_transport.base)
pb = ui_factory.nested_progress_bar()
try:
repo_push(src_repo, dst_repo, pb=pb, overwrite=overwrite)
finally:
pb.finished()
示例7: get_branch
# 需要导入模块: from bzrlib.bzrdir import BzrDir [as 别名]
# 或者: from bzrlib.bzrdir.BzrDir import open [as 别名]
def get_branch(repo, relpath, format=None):
"""Return existing branch in destination repo. Create new if don't exist.
@param format: force create new branch in specified format.
"""
repo_trans = repo.bzrdir.root_transport
try:
br_dir = BzrDir.open(repo_trans.abspath(relpath))
branch = br_dir.open_branch()
except errors.NotBranchError:
# create destination branch directory, creating parents as needed.
needed = [relpath]
while needed:
try:
repo_trans.mkdir(needed[-1])
needed.pop()
except errors.NoSuchFile:
parent = urlutils.dirname(needed[-1])
if parent == '':
raise errors.BzrCommandError('Could not create branch dir')
needed.append(parent)
br_dir = BzrDir.create(repo_trans.abspath(relpath))
if format is None:
format = BranchFormat.get_default_format()
branch = format.initialize(br_dir)
note('Created destination branch %s' % relpath)
if branch.repository.bzrdir.root_transport.base != repo_trans.base:
raise errors.BzrCommandError('Branch %s does not use repository %s'
% (relpath, repo_trans.base))
# XXX: hack to make sure the branch is using the same repository
# instance, for locking purposes
branch.repository = repo
return branch
示例8: __init__
# 需要导入模块: from bzrlib.bzrdir import BzrDir [as 别名]
# 或者: from bzrlib.bzrdir.BzrDir import open [as 别名]
def __init__(self, repository):
from os.path import split
from bzrlib import version_info, IGNORE_FILENAME
if version_info > (0,9):
from bzrlib.ignores import add_runtime_ignores, parse_ignore_file
else:
from bzrlib import DEFAULT_IGNORE
WorkingDir.__init__(self, repository)
# TODO: check if there is a "repository" in the configuration,
# and use it as a bzr repository
self.ignored = []
self._working_tree = None
# The bzr repository may have some plugins that needs to be activated
load_plugins()
try:
bzrdir = BzrDir.open(self.repository.basedir)
wt = self._working_tree = bzrdir.open_workingtree()
# read .bzrignore for _addSubtree()
if wt.has_filename(IGNORE_FILENAME):
f = wt.get_file_byname(IGNORE_FILENAME)
if version_info > (0,9):
self.ignored.extend(parse_ignore_file(f))
else:
self.ignored.extend([ line.rstrip("\n\r") for line in f.readlines() ])
f.close()
except errors.NotBranchError, errors.NoWorkingTree:
pass
示例9: list_branches
# 需要导入模块: from bzrlib.bzrdir import BzrDir [as 别名]
# 或者: from bzrlib.bzrdir.BzrDir import open [as 别名]
def list_branches(repo):
trans = repo.bzrdir.root_transport
dirs_to_check = ['.']
branches = []
while len(dirs_to_check) > 0:
filename = dirs_to_check.pop(0)
if stat.S_ISDIR(trans.stat(filename).st_mode):
# is this a branch inside the given repository?
try:
br_dir = BzrDir.open(trans.abspath(filename))
branch = br_dir.open_branch()
except errors.NotBranchError:
branch = None
# if we have a branch, add it to the result set, provided
# that it uses the same repository.
if branch is not None:
# if the branch uses a different repository, then
# don't include it.
if (branch.repository.bzrdir.root_transport.base !=
trans.base):
continue
# XXX: hack to make sure the branch is using the same
# repository instance, for locking purposes
branch.repository = repo
branches.append(branch)
# extend the list of dirs to check.
dirs_to_check.extend([urlutils.join(filename, name)
for name in trans.list_dir(filename)
if name != '.bzr'])
return branches
示例10: run
# 需要导入模块: from bzrlib.bzrdir import BzrDir [as 别名]
# 或者: from bzrlib.bzrdir.BzrDir import open [as 别名]
def run(self, location=None, remember=False, directory=None,
no_rebase=False):
from bzrlib import urlutils
from bzrlib.bzrdir import BzrDir
from bzrlib.errors import BzrCommandError, NoWorkingTree
from bzrlib.trace import info
from bzrlib.workingtree import WorkingTree
from upgrade import update_workingtree_fileids
if directory is None:
directory = "."
try:
source_wt = WorkingTree.open_containing(directory)[0]
source_branch = source_wt.branch
except NoWorkingTree:
source_branch = Branch.open_containing(directory)[0]
source_wt = None
stored_loc = source_branch.get_push_location()
if location is None:
if stored_loc is None:
raise BzrCommandError("No push location known or specified.")
else:
display_url = urlutils.unescape_for_display(stored_loc,
self.outf.encoding)
self.outf.write("Using saved location: %s\n" % display_url)
location = stored_loc
bzrdir = BzrDir.open(location)
target_branch = bzrdir.open_branch()
target_branch.lock_write()
try:
if not isinstance(target_branch, ForeignBranch):
info("target branch is not a foreign branch, using regular push.")
target_branch.pull(source_branch)
no_rebase = True
else:
revid_map = target_branch.dpull(source_branch)
# We successfully created the target, remember it
if source_branch.get_push_location() is None or remember:
source_branch.set_push_location(target_branch.base)
if not no_rebase:
_, old_last_revid = source_branch.last_revision_info()
new_last_revid = revid_map[old_last_revid]
if source_wt is not None:
source_wt.pull(target_branch, overwrite=True,
stop_revision=new_last_revid)
source_wt.lock_write()
try:
update_workingtree_fileids(source_wt,
source_wt.branch.repository.revision_tree(old_last_revid),
source_wt.branch.repository.revision_tree(new_last_revid))
finally:
source_wt.unlock()
else:
source_branch.pull(target_branch, overwrite=True,
stop_revision=new_last_revid)
finally:
target_branch.unlock()
示例11: get_refs
# 需要导入模块: from bzrlib.bzrdir import BzrDir [as 别名]
# 或者: from bzrlib.bzrdir.BzrDir import open [as 别名]
def get_refs(self):
""" return a dict of all tags and branches in repository (and shas) """
ret = {}
repo_dir = BzrDir.open(self.directory)
repo = repo_dir.open_repository()
for branch in repo.find_branches(using=True):
#FIXME: Need to get branch path relative to its repository and use this instead of nick
ret["refs/heads/"+branch.nick] = self.mapping.revision_id_bzr_to_foreign(branch.last_revision())
return ret
示例12: setUp
# 需要导入模块: from bzrlib.bzrdir import BzrDir [as 别名]
# 或者: from bzrlib.bzrdir.BzrDir import open [as 别名]
def setUp(self):
super(TestsNeedingReweave, self).setUp()
t = self.get_transport()
# an empty inventory with no revision for testing with.
repo = self.make_repository('inventory_without_revision')
repo.lock_write()
repo.start_write_group()
inv = Inventory(revision_id='missing')
inv.root.revision = 'missing'
repo.add_inventory('missing', inv, [])
repo.commit_write_group()
repo.unlock()
def add_commit(repo, revision_id, parent_ids):
repo.lock_write()
repo.start_write_group()
inv = Inventory(revision_id=revision_id)
inv.root.revision = revision_id
root_id = inv.root.file_id
sha1 = repo.add_inventory(revision_id, inv, parent_ids)
repo.texts.add_lines((root_id, revision_id), [], [])
rev = bzrlib.revision.Revision(timestamp=0,
timezone=None,
committer="Foo Bar <[email protected]>",
message="Message",
inventory_sha1=sha1,
revision_id=revision_id)
rev.parent_ids = parent_ids
repo.add_revision(revision_id, rev)
repo.commit_write_group()
repo.unlock()
# an empty inventory with no revision for testing with.
# this is referenced by 'references_missing' to let us test
# that all the cached data is correctly converted into ghost links
# and the referenced inventory still cleaned.
repo = self.make_repository('inventory_without_revision_and_ghost')
repo.lock_write()
repo.start_write_group()
repo.add_inventory('missing', inv, [])
repo.commit_write_group()
repo.unlock()
add_commit(repo, 'references_missing', ['missing'])
# a inventory with no parents and the revision has parents..
# i.e. a ghost.
repo = self.make_repository('inventory_one_ghost')
add_commit(repo, 'ghost', ['the_ghost'])
# a inventory with a ghost that can be corrected now.
t.copy_tree('inventory_one_ghost', 'inventory_ghost_present')
bzrdir_url = self.get_url('inventory_ghost_present')
bzrdir = BzrDir.open(bzrdir_url)
repo = bzrdir.open_repository()
add_commit(repo, 'the_ghost', [])
示例13: test_switch_branches
# 需要导入模块: from bzrlib.bzrdir import BzrDir [as 别名]
# 或者: from bzrlib.bzrdir.BzrDir import open [as 别名]
def test_switch_branches(self):
# switch_branches moves a branch to the new location and places a
# branch (with no revisions) stacked on the new branch in the old
# location.
chroot_server = ChrootServer(self.get_transport())
chroot_server.start_server()
self.addCleanup(chroot_server.stop_server)
scheme = chroot_server.get_url().rstrip("/:")
old_branch = FakeBranch(1)
self.get_transport(old_branch.unique_name).create_prefix()
tree = self.make_branch_and_tree(old_branch.unique_name)
# XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
# required to generate the revision-id.
with override_environ(BZR_EMAIL="[email protected]"):
tree.commit(message=".")
new_branch = FakeBranch(2)
switch_branches(".", scheme, old_branch, new_branch)
# Post conditions:
# 1. unstacked branch in new_branch's location
# 2. stacked branch with no revisions in repo at old_branch
# 3. last_revision() the same for two branches
old_location_bzrdir = BzrDir.open(str(URI(scheme=scheme, host="", path="/" + old_branch.unique_name)))
new_location_bzrdir = BzrDir.open(str(URI(scheme=scheme, host="", path="/" + new_branch.unique_name)))
old_location_branch = old_location_bzrdir.open_branch()
new_location_branch = new_location_bzrdir.open_branch()
# 1. unstacked branch in new_branch's location
self.assertRaises(NotStacked, new_location_branch.get_stacked_on_url)
# 2. stacked branch with no revisions in repo at old_branch
self.assertEqual("/" + new_branch.unique_name, old_location_branch.get_stacked_on_url())
self.assertEqual([], old_location_bzrdir.open_repository().all_revision_ids())
# 3. last_revision() the same for two branches
self.assertEqual(old_location_branch.last_revision(), new_location_branch.last_revision())
示例14: test_convenience_reconcile_inventory_without_revision_reconcile
# 需要导入模块: from bzrlib.bzrdir import BzrDir [as 别名]
# 或者: from bzrlib.bzrdir.BzrDir import open [as 别名]
def test_convenience_reconcile_inventory_without_revision_reconcile(self):
# smoke test for the all in one ui tool
bzrdir_url = self.get_url('inventory_without_revision')
bzrdir = BzrDir.open(bzrdir_url)
repo = bzrdir.open_repository()
if not repo._reconcile_does_inventory_gc:
raise TestSkipped('Irrelevant test')
reconcile(bzrdir)
# now the backup should have it but not the current inventory
repo = bzrdir.open_repository()
self.check_missing_was_removed(repo)
示例15: _getUpstreamChangesets
# 需要导入模块: from bzrlib.bzrdir import BzrDir [as 别名]
# 或者: from bzrlib.bzrdir.BzrDir import open [as 别名]
def _getUpstreamChangesets(self, sincerev):
"""
See what other revisions exist upstream and return them
"""
parent_branch = BzrDir.open(self.repository.repository).open_branch()
branch = self._working_tree.branch
revisions = branch.missing_revisions(parent_branch)
branch.fetch(parent_branch)
for revision_id in revisions:
yield self._changesetFromRevision(parent_branch, revision_id)