Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # update-librix.py
- # Syncs an overlay with a binary repository.
- # Removes all ebuilds from an overlay for which no packages are present in
- # a repository. Automatically updates ChangeLogs and Manifests for remaining
- # ebuilds.
- import os
- import subprocess
- rep_pkgs = None # Path to repository
- librix_overlay = None # Path to 'librix' overlay working copy
- package_extension = ".tbz2"
- changelog_msg = "Removing outdated/broken ebuilds."
- os.chdir(librix_overlay)
- for dirpath, dirnames, filenames in os.walk("."):
- dir_has_ebuilds = False
- ebuilds_purged = False # Has any ebuild been deleted here?
- ebuilds_kept = [] # ebuilds with packages in the repository
- for ebuild in filenames:
- if not ebuild.endswith(".ebuild"):
- continue
- dir_has_ebuilds = True
- # dirpath has the form:
- # ./<category>/<PN>/
- category = dirpath.rsplit(os.sep, 2)[1]
- package_name = os.path.splitext(ebuild)[0] + package_extension
- # Expected path of the package.
- package_path = os.path.join(rep_pkgs, category, package_name)
- if not os.path.isfile(package_path):
- print "Purging " + ebuild
- ebuilds_purged = True
- subprocess.call(("git", "rm", ebuild), cwd = dirpath)
- else:
- ebuilds_kept.append(ebuild)
- # Skip directories without ebuilds, such as 'profiles'
- if not dir_has_ebuilds:
- continue
- # Are there any ebuilds left?
- if ebuilds_kept:
- # Yes. Any ebuilds removed?
- if ebuilds_purged:
- # Yes. Update ChangeLog and rebuild Manifest
- print "Updating ChangeLog"
- subprocess.call(
- ("echangelog", changelog_msg),
- cwd = dirpath)
- print "Generating Manifest using sudo"
- subprocess.call(
- ("sudo", "ebuild", ebuilds_kept[0], "digest"),
- cwd = dirpath)
- else:
- # No, there are no ebuilds left. Get rid of this directory.
- print "Purging ebuild directory %s" % dirpath
- subprocess.call(("git", "rm", "-r", dirpath))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement