Rev 1: Adding a command to update all of my bzr.dev mirrors at one time. in http://bzr.arbash-meinel.com/plugins/update_bzrdev
John Arbash Meinel
john at arbash-meinel.com
Thu Nov 29 19:37:37 GMT 2007
At http://bzr.arbash-meinel.com/plugins/update_bzrdev
------------------------------------------------------------
revno: 1
revision-id:john at arbash-meinel.com-20071129193735-h4wyi28y6cj5b1y1
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: update_bzrdev
timestamp: Thu 2007-11-29 13:37:35 -0600
message:
Adding a command to update all of my bzr.dev mirrors at one time.
This should allow parts of the data to stay cached in memory,
and also allow fetching from repositories that have the same format,
so we don't rebuild packs=>knits, etc.
added:
__init__.py __init__.py-20071129193732-xf6i9hy1llvvyr7r-1
update_bzr.py update_bzr.py-20071129193732-xf6i9hy1llvvyr7r-2
-------------- next part --------------
=== added file '__init__.py'
--- a/__init__.py 1970-01-01 00:00:00 +0000
+++ b/__init__.py 2007-11-29 19:37:35 +0000
@@ -0,0 +1,18 @@
+"""A cheap command to update all of my bzr.dev mirrors."""
+
+from bzrlib import commands
+
+class cmd_update_bzrdev(commands.Command):
+ """Update all of my mirrors of bzr.dev in a logical way.
+
+ Update knits from the knit sources, and update packs from pack sources.
+ But pull everything around so all the different repositories get the latest
+ code.
+ """
+
+ def run(self):
+ import update_bzr
+ update_bzr.update()
+
+commands.register_command(cmd_update_bzrdev)
+
=== added file 'update_bzr.py'
--- a/update_bzr.py 1970-01-01 00:00:00 +0000
+++ b/update_bzr.py 2007-11-29 19:37:35 +0000
@@ -0,0 +1,114 @@
+# Go around and make sure all of the bzr.dev copies are at their newest
+
+import os
+import sys
+
+# packs
+pack_source_url = 'http://bazaar-vcs.org/bzr/bzr.dev'
+# There is a knit source url, which may be out of date, but use it if it isn't
+knit_source_url = 'http://bazaar-vcs.org/bzr/bzr.dev.knits'
+
+# knits
+juju_mirror_url = 'bzr+ssh://juju/srv/bzr/public/mirrors/bzr/bzr.dev'
+juju_jam_integration_url = 'bzr+ssh://juju/srv/bzr/public/branches/bzr/jam-integration'
+
+# Local repository, packs
+local_mirror_url = os.path.expanduser('~/dev/bzr/bzr.dev')
+local_jam_url = os.path.expanduser('~/dev/bzr/jam-integration')
+
+
+from bzrlib import (
+ branch,
+ errors,
+ workingtree,
+ )
+
+
+def _update_local_mirror(source_branch, target_info):
+ """Pull into the local bzr.dev mirror."""
+ try:
+ wt = workingtree.WorkingTree.open(local_mirror_url)
+ except errors.NotBranchError:
+ return None, None
+ wt.lock_write()
+ try:
+ print 'Updating from %s %s' % (wt.branch.revno(), wt)
+ result = wt.pull(source_branch, stop_revision=target_info[1])
+ except:
+ wt.unlock()
+ raise
+ return wt, result
+
+
+def _update_juju_mirror(local_wt, source_branch, knit_source, target_info):
+ """Pull from the appropriate source into the juju mirror."""
+ # If knit_source is not None, it has all the revisions already in knit
+ # format, so pull from that.
+ # Otherwise we may as well copy from the local packs repo.
+ # But if that is also None, then just pull from the source repo.
+ if knit_source is not None:
+ source = knit_source
+ elif local_wt is not None:
+ source = local_wt.branch
+ else:
+ source = source_branch
+
+ juju_mirror_branch = branch.Branch.open(juju_mirror_url)
+ juju_mirror_branch.lock_write()
+ try:
+ print 'Updating %s %s from %s' % (juju_mirror_branch.revno(),
+ juju_mirror_branch, source)
+ juju_mirror_branch.pull(source, stop_revision=target_info[1])
+
+ # We don't actually want to update the branch we just want the
+ # repository to have the newest code.
+ # Also, we would probably actually prefer to re-use a connection, but
+ # I'm not user how to use Branch.open() for that.
+ # If only there was a remote "copy to this other repository on your
+ # side."
+ juju_jam_integration_branch = branch.Branch.open(juju_jam_integration_url,
+ possible_transports=[juju_mirror_branch.bzrdir.transport])
+ juju_jam_integration_branch.lock_write()
+ try:
+ repo = juju_jam_integration_branch.repository
+ print 'Copying revisions from %s to %s' % (juju_mirror_branch, repo)
+ repo.fetch(juju_mirror_branch.repository,
+ revision_id=target_info[1])
+ finally:
+ juju_jam_integration_branch.unlock()
+ finally:
+ juju_mirror_branch.unlock()
+
+
+def update():
+ sys.stdout.write('Finding last revision of: %s\n' % (pack_source_url,))
+ source_branch = branch.Branch.open(pack_source_url)
+ source_branch.lock_read()
+ try:
+ source_info = source_branch.last_revision_info()
+ sys.stdout.write(' %s\n' % (source_info[0],))
+ knit_source = branch.Branch.open(knit_source_url)
+ knit_source.lock_read()
+ try:
+ knit_info = knit_source.last_revision_info()
+ if knit_info != source_info:
+ knit_source.unlock()
+ knit_source = None
+
+ local_wt, result = _update_local_mirror(source_branch,
+ source_info)
+ try:
+ _update_juju_mirror(local_wt,
+ source_branch, knit_source, source_info)
+ # TODO: we *could* update jam-integration, but that may have
+ # some pending code. so we just rely on
+ # _update_juju_mirror to have copied the stuff into the
+ # repository, so it should be fast anyway.
+ finally:
+ if local_wt is not None:
+ local_wt.unlock()
+ finally:
+ if knit_source:
+ knit_source.unlock()
+ finally:
+ source_branch.unlock()
More information about the bazaar-commits
mailing list