diff options
author | 2010-07-02 21:34:16 +0300 | |
---|---|---|
committer | 2010-07-02 21:34:16 +0300 | |
commit | 434652243ec8069bee1f80a42da8f508c9ae91f9 (patch) | |
tree | 4b0542653ccca4bb5bb47bfed599d2d95ba3e9e4 /utils | |
parent | Added logic for case when new update files appear in portage (diff) | |
download | gsoc2010-grumpy-434652243ec8069bee1f80a42da8f508c9ae91f9.tar.gz gsoc2010-grumpy-434652243ec8069bee1f80a42da8f508c9ae91f9.tar.bz2 gsoc2010-grumpy-434652243ec8069bee1f80a42da8f508c9ae91f9.zip |
Make package move tracking possible
Diffstat (limited to 'utils')
-rwxr-xr-x | utils/grumpy_sync.py | 72 |
1 files changed, 43 insertions, 29 deletions
diff --git a/utils/grumpy_sync.py b/utils/grumpy_sync.py index 268778a..e9fd32b 100755 --- a/utils/grumpy_sync.py +++ b/utils/grumpy_sync.py @@ -35,10 +35,13 @@ def main(path, initial_sync): print "Missing package moves directory: '%s'" % movedir return {} - # Sort update files according to date - get_key = lambda name: tuple(reversed(name.split('-'))) + def extract_version(pkg, cpv): + """...""" + return cpv[len(pkg)+1:-7] + # Read package move information pkg_moves = {} + get_key = lambda name: tuple(reversed(name.split('-'))) move_files = sorted(os.listdir(movedir), key=get_key) update_file = move_files[-1] update_path = os.path.join(movedir, update_file) @@ -50,7 +53,7 @@ def main(path, initial_sync): if update_data['file'] == update_file: if update_data['mtime'] == int(os.stat(update_path).st_mtime): # update_file has not been changed, so fall through - pkg_moves = None + pass else: # Fetch new move rules for line in iter_read_bash(update_path): @@ -78,9 +81,38 @@ def main(path, initial_sync): if line[0] == 'move': pkg_moves[line[1]] = line[2] - def extract_version(pkg, cpv): - """...""" - return cpv[len(pkg)+1:-7] + # 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() + + # Parse (again) latest moves file and store its info in database + if prev_updates: + session.delete(prev_updates) + session.flush() + moves = {} + for line in iter_read_bash(update_path): + line = line.split() + if line[0] == 'move': + moves[line[1]] = line[2] + data = dict(file=update_file, moves=moves, \ + mtime=int(os.stat(update_path).st_mtime)) + session.add(Setting(UPDATE_DB_KEY, data)) + session.commit() def package_update(cat, pkg, files, mtime): """Update package information in database.""" @@ -222,34 +254,16 @@ def main(path, initial_sync): if os.path.isdir(os.path.join(catdir, d))] for pkg in [i for i in old if i not in new]: - # Handle package move or deletion - if pkg_moves and "%s/%s" % (cat, pkg) in pkg_moves.keys(): - print "DEBUG: package has been moved:", pkg - raise NotImplementedError - else: - print "DEBUG: package has been removed:", pkg - package = Package.query.filter_by(cat=cat).filter_by(pkg=pkg).one() - session.delete(package) - session.commit() + # Handle package deletion + print "DEBUG: package has been removed:", pkg + package = Package.query.filter_by(cat=cat).filter_by(pkg=pkg).one() + session.delete(package) + session.commit() 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)) - # Parse latest moves file and store its info in database - if prev_updates: - session.delete(prev_updates) - session.flush() - moves = {} - for line in iter_read_bash(update_path): - line = line.split() - if line[0] == 'move': - moves[line[1]] = line[2] - data = dict(file=update_file, moves=moves, \ - mtime=int(os.stat(update_path).st_mtime)) - session.add(Setting(UPDATE_DB_KEY, data)) - session.commit() - if __name__ == '__main__': parser = OptionParser(usage="usage: %prog [options] portagedir") parser.add_option("-i", "--initial-sync", action="store_true", \ |