a guest Jun 19th, 2017 49 Never
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."
- 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"):
- dir_has_ebuilds = True
- # dirpath has the form:
- # ./<category>/<PN>/
- category = dirpath.rsplit(os.sep, 2)
- package_name = os.path.splitext(ebuild) + 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)
- # Skip directories without ebuilds, such as 'profiles'
- if not dir_has_ebuilds:
- # Are there any ebuilds left?
- if ebuilds_kept:
- # Yes. Any ebuilds removed?
- if ebuilds_purged:
- # Yes. Update ChangeLog and rebuild Manifest
- print "Updating ChangeLog"
- ("echangelog", changelog_msg),
- cwd = dirpath)
- print "Generating Manifest using sudo"
- ("sudo", "ebuild", ebuilds_kept, "digest"),
- cwd = dirpath)
- # No, there are no ebuilds left. Get rid of this directory.
- print "Purging ebuild directory %s" % dirpath
- subprocess.call(("git", "rm", "-r", dirpath))
RAW Paste Data