Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.90 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # update-librix.py
  3. # Syncs an overlay with a binary repository.
  4. # Removes all ebuilds from an overlay for which no packages are present in
  5. # a repository. Automatically updates ChangeLogs and Manifests for remaining
  6. # ebuilds.
  7.  
  8. import os
  9. import subprocess
  10.  
  11. rep_pkgs = None # Path to repository
  12. librix_overlay = None # Path to 'librix' overlay working copy
  13.  
  14. package_extension = ".tbz2"
  15. changelog_msg = "Removing outdated/broken ebuilds."
  16.  
  17. os.chdir(librix_overlay)
  18. for dirpath, dirnames, filenames in os.walk("."):
  19.     dir_has_ebuilds = False
  20.     ebuilds_purged = False # Has any ebuild been deleted here?
  21.     ebuilds_kept = [] # ebuilds with packages in the repository
  22.  
  23.     for ebuild in filenames:
  24.         if not ebuild.endswith(".ebuild"):
  25.             continue
  26.  
  27.         dir_has_ebuilds = True
  28.  
  29.         # dirpath has the form:
  30.         # ./<category>/<PN>/
  31.         category = dirpath.rsplit(os.sep, 2)[1]
  32.  
  33.         package_name = os.path.splitext(ebuild)[0] + package_extension
  34.         # Expected path of the package.
  35.         package_path = os.path.join(rep_pkgs, category, package_name)
  36.  
  37.         if not os.path.isfile(package_path):
  38.             print "Purging " + ebuild
  39.             ebuilds_purged = True
  40.             subprocess.call(("git", "rm", ebuild), cwd = dirpath)
  41.         else:
  42.             ebuilds_kept.append(ebuild)
  43.    
  44.     # Skip directories without ebuilds, such as 'profiles'
  45.     if not dir_has_ebuilds:
  46.         continue
  47.    
  48.     # Are there any ebuilds left?
  49.     if ebuilds_kept:
  50.         # Yes. Any ebuilds removed?
  51.         if ebuilds_purged:
  52.             # Yes. Update ChangeLog and rebuild Manifest
  53.             print "Updating ChangeLog"
  54.             subprocess.call(
  55.                 ("echangelog", changelog_msg),
  56.                 cwd = dirpath)
  57.            
  58.             print "Generating Manifest using sudo"
  59.             subprocess.call(
  60.                 ("sudo", "ebuild", ebuilds_kept[0], "digest"),
  61.                 cwd = dirpath)
  62.     else:
  63.         # No, there are no ebuilds left. Get rid of this directory.
  64.         print "Purging ebuild directory %s" % dirpath
  65.         subprocess.call(("git", "rm", "-r", dirpath))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement