reimplement the unused-patches command for the CentOS layout

This commit is contained in:
Brian Stinson 2015-07-24 19:39:31 -05:00
parent e7fd56b5d0
commit 1fe6e4da57

View file

@ -291,6 +291,28 @@ class Commands(Commands):
def prep(self, *args, **kwargs):
raise NotImplementedError("prep is not yet implemented in centpkg")
def unused_patches(self, *args, **kwargs):
raise NotImplementedError("unused_patches is not yet implemented in centpkg")
def unused_patches(self):
"""Discover patches checked into source control that are not used
Returns a list of unused patches, which may be empty.
"""
# Create a list for unused patches
unused = []
# Get the content of spec into memory for fast searching
spec = open(self.spec, 'r').read()
# Replace %{name} with the package name
spec = spec.replace("%{name}", self.module_name)
# Replace %{version} with the package version
spec = spec.replace("%{version}", self.ver)
# Get a list of files tracked in source control
files = self.repo.git.ls_files('--exclude-standard').split()
for file in map(os.path.basename, files):
# throw out non patches
if not file.endswith(('.patch', '.diff')):
continue
if file not in spec:
unused.append(file)
return unused