aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorPriit Laes <plaes@plaes.org>2010-07-02 21:43:13 +0300
committerPriit Laes <plaes@plaes.org>2010-07-02 21:43:13 +0300
commit60169df757d8f3af918d78dd05400994958e36e2 (patch)
treec151f14d939b04db012ffd9b7a11ecba64012fc4 /utils
parentMake package move tracking possible (diff)
downloadgsoc2010-grumpy-60169df757d8f3af918d78dd05400994958e36e2.tar.gz
gsoc2010-grumpy-60169df757d8f3af918d78dd05400994958e36e2.tar.bz2
gsoc2010-grumpy-60169df757d8f3af918d78dd05400994958e36e2.zip
Make package moves "atomic"
Diffstat (limited to 'utils')
-rwxr-xr-xutils/grumpy_sync.py64
1 files changed, 29 insertions, 35 deletions
diff --git a/utils/grumpy_sync.py b/utils/grumpy_sync.py
index e9fd32b..2f883da 100755
--- a/utils/grumpy_sync.py
+++ b/utils/grumpy_sync.py
@@ -30,17 +30,35 @@ def main(path, initial_sync):
repo = repository.UnconfiguredTree(path, cache=cache, \
eclass_cache=eclass_cache)
- movedir = os.path.join(path, 'profiles', 'updates')
- if not os.path.isdir(movedir):
- print "Missing package moves directory: '%s'" % movedir
- return {}
-
def extract_version(pkg, cpv):
"""..."""
return cpv[len(pkg)+1:-7]
+ def package_move(src, dst):
+ """Rename package and its ebuild in database."""
+ srccat, srcpkg = src.split('/')
+ dstcat, dstpkg = dst.split('/')
+ package = Package.query.filter_by(cat=srccat) \
+ .filter_by(pkg=srcpkg).first()
+ if not package:
+ return
+ # Make renames in package and ebuild info
+ cp = "%s/%s" % (dstpkg, dstcat)
+ print "DEBUG: Handling package move: %s/%s -> %s/%s" % \
+ (srccat, srcpkg, dstcat, dstpkg)
+ package.cat = dstcat
+ package.pkg = dstpkg
+ package.cp = cp
+ for ebuild in package.ebuilds:
+ ebuild.cpv = "%s-%s" % (cp, ebuild.version)
+ session.commit()
+
# Read package move information
- pkg_moves = {}
+ movedir = os.path.join(path, 'profiles', 'updates')
+ if not os.path.isdir(movedir):
+ print "DEBUG: Missing package moves directory: '%s'" % movedir
+ raise RuntimeError
+
get_key = lambda name: tuple(reversed(name.split('-')))
move_files = sorted(os.listdir(movedir), key=get_key)
update_file = move_files[-1]
@@ -60,45 +78,21 @@ def main(path, initial_sync):
line = line.split()
if line[0] == 'move' and \
line[1] not in update_data['moves'].keys():
- pkg_moves[line[1]] = line[2]
+ package_move(line[1], line[2])
# New updates file has been added
else:
# First, get the rules from previous update file...
- # FIXME: Should we check whether file exists?
- # ...but these files should never disappear...
for line in iter_read_bash( \
os.path.join(movedir, update_data['file'])):
line = line.split()
if line[0] == 'move' and \
line[1] not in update_data['moves'].keys():
- pkg_moves[line[1]] = line[2]
- # Now read moves from newer files
- # FIXME: What about duplicate keys?
- # ...common sense says it should not happen...
+ package_move(line[1], line[2])
for file in move_files[move_files.index(update_data['file']):]:
for line in iter_read_bash(os.path.join(movedir, file)):
line = line.split()
if line[0] == 'move':
- pkg_moves[line[1]] = line[2]
-
- # Handle package moves before doing full sync
- for src, dst in pkg_moves.iteritems():
- srccat, srcpkg = src.split('/')
- dstcat, dstpkg = dst.split('/')
- package = Package.query.filter_by(cat=srccat) \
- .filter_by(pkg=srcpkg).first()
- if not package:
- continue
- # Make renames in package and ebuild info
- cp = "%s/%s" % (dstpkg, dstcat)
- print "DEBUG: Handling package move: %s/%s -> %s/%s" % \
- (srccat, srcpkg, dstcat, dstpkg)
- package.cat = dstcat
- package.pkg = dstpkg
- package.cp = cp
- for ebuild in package.ebuilds:
- ebuild.cpv = "%s-%s" % (cp, ebuild.version)
- session.commit()
+ package_move(line[1], line[2])
# Parse (again) latest moves file and store its info in database
if prev_updates:
@@ -114,7 +108,7 @@ def main(path, initial_sync):
session.add(Setting(UPDATE_DB_KEY, data))
session.commit()
- def package_update(cat, pkg, files, mtime):
+ def package_sync(cat, pkg, files, mtime):
"""Update package information in database."""
# Fetch package from database
@@ -262,7 +256,7 @@ def main(path, initial_sync):
for pkg in new:
dir = os.path.join(catdir, pkg)
files = [f for f in os.listdir(dir) if fnmatch(f, '*.ebuild')]
- package_update(cat, pkg, files, int(os.stat(dir).st_mtime))
+ package_sync(cat, pkg, files, int(os.stat(dir).st_mtime))
if __name__ == '__main__':
parser = OptionParser(usage="usage: %prog [options] portagedir")