本文整理汇总了Python中bzrlib.bzrdir.BzrDir类的典型用法代码示例。如果您正苦于以下问题:Python BzrDir类的具体用法?Python BzrDir怎么用?Python BzrDir使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BzrDir类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_branch
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
示例2: run
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: _checkoutUpstreamRevision
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)
示例4: _makeDefaultStackedOnBranch
def _makeDefaultStackedOnBranch(self, private=False):
"""Make a default stacked-on branch.
This creates a database product branch, makes it the default
stacked-on branch for its product and creates a Bazaar branch for it.
:param private: Whether the created branch should be private or not
(defaults to not).
:return: `IBranch`.
"""
# Make the branch in the database.
product = self.factory.makeProduct()
if private:
information_type = InformationType.USERDATA
else:
information_type = InformationType.PUBLIC
default_branch = self.factory.makeProductBranch(
product=product, information_type=information_type)
transaction.commit()
# Create the underlying bzr branch.
lp_server = self.getLPServerForUser(default_branch.owner)
BzrDir.create_branch_convenience(
lp_server.get_url() + default_branch.unique_name)
transaction.commit()
# Make it the default stacked-on branch for the product.
series = removeSecurityProxy(product.development_focus)
series.branch = default_branch
self.assertEqual(
default_branch, IBranchTarget(product).default_stacked_on_branch)
return default_branch
示例5: run
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()
示例6: test_shared_repos
def test_shared_repos(self):
self.make_repository('a', shared=True)
BzrDir.create_branch_convenience('a/branch1')
b = BzrDir.create_branch_convenience('a/branch2')
b.create_checkout(lightweight=True, to_location='b')
out, err = self.run_bzr('branches b')
self.assertEquals(out, " branch1\n"
"* branch2\n")
示例7: setUp
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")
示例8: ensure_repo_consistency
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)
示例9: newtree_cb
def newtree_cb(self, menu, vfs_file):
# We can only cope with local files
if vfs_file.get_uri_scheme() != 'file':
return
file = vfs_file.get_uri()
# We only want to continue here if we get a NotBranchError
try:
tree, path = WorkingTree.open_containing(file)
except NotBranchError:
BzrDir.create_standalone_workingtree(file)
示例10: ensure_repo_consistency
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)
示例11: push
def push(self, db_branch_id, bzr_branch, required_format,
stacked_on_url=None):
"""Push up `bzr_branch` as the Bazaar branch for `code_import`.
:return: A boolean that is true if the push was non-trivial
(i.e. actually transferred revisions).
"""
self.transport.create_prefix()
target_url = self._getMirrorURL(db_branch_id)
try:
remote_branch = Branch.open(target_url)
except NotBranchError:
remote_branch = BzrDir.create_branch_and_repo(
target_url, format=required_format)
old_branch = None
else:
if remote_branch.bzrdir.needs_format_conversion(
required_format):
# For upgrades, push to a new branch in
# the new format. When done pushing,
# retire the old .bzr directory and rename
# the new one in place.
old_branch = remote_branch
upgrade_url = urljoin(target_url, "backup.bzr")
try:
remote_branch.bzrdir.root_transport.delete_tree(
'backup.bzr')
except NoSuchFile:
pass
remote_branch = BzrDir.create_branch_and_repo(
upgrade_url, format=required_format)
else:
old_branch = None
# This can be done safely, since only modern formats are used to
# import to.
if stacked_on_url is not None:
remote_branch.set_stacked_on_url(stacked_on_url)
pull_result = remote_branch.pull(bzr_branch, overwrite=True)
# Because of the way we do incremental imports, there may be revisions
# in the branch's repo that are not in the ancestry of the branch tip.
# We need to transfer them too.
remote_branch.repository.fetch(bzr_branch.repository)
if old_branch is not None:
# The format has changed; move the new format
# branch in place.
base_transport = old_branch.bzrdir.root_transport
base_transport.delete_tree('.bzr')
base_transport.rename("backup.bzr/.bzr", ".bzr")
base_transport.rmdir("backup.bzr")
return pull_result.old_revid != pull_result.new_revid
示例12: __init__
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
示例13: test_post_push_bound_branch
def test_post_push_bound_branch(self):
# pushing to a bound branch should pass in the master branch to the
# hook, allowing the correct number of emails to be sent, while still
# allowing hooks that want to modify the target to do so to both
# instances.
target = self.make_branch('target')
local = self.make_branch('local')
try:
local.bind(target)
except errors.UpgradeRequired:
# We can't bind this format to itself- typically it is the local
# branch that doesn't support binding. As of May 2007
# remotebranches can't be bound. Let's instead make a new local
# branch of the default type, which does allow binding.
# See https://bugs.launchpad.net/bzr/+bug/112020
local = BzrDir.create_branch_convenience('local2')
local.bind(target)
source = self.make_branch('source')
Branch.hooks.install_named_hook('post_push',
self.capture_post_push_hook, None)
source.push(local)
# with nothing there we should still get a notification, and
# have both branches locked at the notification time.
self.assertEqual([
('post_push', source, local.base, target.base, 0, NULL_REVISION,
0, NULL_REVISION, True, True, True)
],
self.hook_calls)
示例14: _find
def _find(self, path):
"""try to find a repository from path upwards
This operates precisely like 'bzrdir.find_repository'.
:return: (relpath, rich_root, tree_ref, external_lookup) flags. All are
strings, relpath is a / prefixed path, and the other three are
either 'yes' or 'no'.
:raises errors.NoRepositoryPresent: When there is no repository
present.
"""
bzrdir = BzrDir.open_from_transport(
self.transport_from_client_path(path))
repository = bzrdir.find_repository()
# the relpath of the bzrdir in the found repository gives us the
# path segments to pop-out.
relpath = repository.bzrdir.root_transport.relpath(
bzrdir.root_transport.base)
if len(relpath):
segments = ['..'] * len(relpath.split('/'))
else:
segments = []
rich_root = self._boolean_to_yes_no(repository.supports_rich_root())
tree_ref = self._boolean_to_yes_no(
repository._format.supports_tree_reference)
external_lookup = self._boolean_to_yes_no(
repository._format.supports_external_lookups)
return '/'.join(segments), rich_root, tree_ref, external_lookup
示例15: do
def do(self, path, network_name, shared):
"""Create a repository in the bzr dir at path.
This operates precisely like 'bzrdir.create_repository'.
If a bzrdir is not present, an exception is propagated
rather than 'no branch' because these are different conditions (and
this method should only be called after establishing that a bzr dir
exists anyway).
This is the initial version of this method introduced to the smart
server for 1.13.
:param path: The path to the bzrdir.
:param network_name: The network name of the repository type to create.
:param shared: The value to pass create_repository for the shared
parameter.
:return: (ok, rich_root, tree_ref, external_lookup, network_name)
"""
bzrdir = BzrDir.open_from_transport(
self.transport_from_client_path(path))
shared = shared == 'True'
format = repository.network_format_registry.get(network_name)
bzrdir.repository_format = format
result = format.initialize(bzrdir, shared=shared)
rich_root, tree_ref, external_lookup = self._format_to_capabilities(
result._format)
return SuccessfulSmartServerResponse(('ok', rich_root, tree_ref,
external_lookup, result._format.network_name()))