Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 2 additions & 167 deletions lib/rift/Controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@
from rift.Mock import Mock
from rift.Package import Package, Test
from rift.Repository import LocalRepository, ProjectArchRepositories
from rift.RPM import RPM, Spec, RPMLINT_CONFIG_V1, RPMLINT_CONFIG_V2
from rift.RPM import RPM, Spec
from rift.TempDir import TempDir
from rift.TestResults import TestCase, TestResults
from rift.TextTable import TextTable
from rift.VM import VM
from rift.sync import RepoSyncFactory
from rift.patches import get_packages_from_patch


def message(msg):
Expand Down Expand Up @@ -988,48 +989,6 @@ def action_sync(args, config):
)
synchronizer.run()


def get_packages_from_patch(patch, config, modules, staff):
"""
Return 2-tuple of dicts of updated and removed packages extracted from given
patch.
"""
updated = {}
removed = {}
patchedfiles = parse_unidiff(patch)
if not patchedfiles:
raise RiftError("Invalid patch detected (empty commit ?)")

for patchedfile in patchedfiles:
modifies_packages = _validate_patched_file(
patchedfile,
config=config,
modules=modules,
staff=staff
)
if not modifies_packages:
continue
pkg = _patched_file_updated_package(
patchedfile,
config=config,
modules=modules,
staff=staff
)
if pkg is not None and pkg not in updated:
logging.info('Patch updates package %s', pkg.name)
updated[pkg.name] = pkg
pkg = _patched_file_removed_package(
patchedfile,
config=config,
modules=modules,
staff=staff
)
if pkg is not None and pkg not in removed:
logging.info('Patch deletes package %s', pkg.name)
removed[pkg.name] = pkg

return updated, removed

def create_staging_repo(config):
"""
Create and return staging temporary repository with a 2-tuple containing
Expand Down Expand Up @@ -1230,130 +1189,6 @@ def action(config, args):

return 0

def _validate_patched_file(patched_file, config, modules, staff):
"""
Raise RiftError if patched_file is a binary file or does not match any known
file path in Rift project tree.

Return True if the patched_file modifies a package or False otherwise.
"""
filepath = patched_file.path
names = filepath.split(os.path.sep)

if filepath == config.get('staff_file'):
staff = Staff(config)
staff.load(filepath)
logging.info('Staff file is OK.')
return False

if filepath == config.get('modules_file'):
modules = Modules(config, staff)
modules.load(filepath)
logging.info('Modules file is OK.')
return False

if filepath == 'mock.tpl':
logging.debug('Ignoring mock template file: %s', filepath)
return False

if filepath == '.gitignore':
logging.debug('Ignoring git file: %s', filepath)
return False

if filepath == 'project.conf':
logging.debug('Ignoring project config file: %s', filepath)
return False

if patched_file.binary:
raise RiftError(f"Binary file detected: {filepath}")

if names[0] != config.get('packages_dir'):
raise RiftError(f"Unknown file pattern: {filepath}")

return True

def _patched_file_updated_package(patched_file, config, modules, staff):
"""
Return Package updated by patched_file, or None if either:

- The patched_file modifies a package file that does not impact package
build result.
- The pached_file is removed.

Raise RiftError if patched_file path does not match any known
packaging code file path.
"""
filepath = patched_file.path
names = filepath.split(os.path.sep)
fullpath = config.project_path(filepath)
pkg = None

if patched_file.is_deleted_file:
logging.debug('Ignoring removed file: %s', filepath)
return None

# Drop config.get('packages_dir') from list
names.pop(0)

pkg = Package(names.pop(0), config, staff, modules)

# info.yaml
if fullpath == pkg.metafile:
logging.info('Ignoring meta file')
return None

# README file
if fullpath in pkg.docfiles:
logging.debug('Ignoring documentation file: %s', fullpath)
return None

# backup specfile
if fullpath == f"{pkg.specfile}.orig":
logging.debug('Ignoring backup specfile')
return None

# specfile
if fullpath == pkg.specfile:
logging.info('Detected spec file')

# rpmlint config file
elif names in [RPMLINT_CONFIG_V1, RPMLINT_CONFIG_V2]:
logging.debug('Detecting rpmlint config file')

# sources/
elif fullpath.startswith(pkg.sourcesdir) and len(names) == 2:
logging.debug('Detecting source file: %s', names[1])

# tests/
elif fullpath.startswith(pkg.testsdir):
logging.debug('Detecting test script: %s', filepath)

else:
raise RiftError(
f"Unknown file pattern in '{pkg.name}' directory: {filepath}"
)

return pkg

def _patched_file_removed_package(patched_file, config, modules, staff):
"""
Return Package removed by the patched_file or None if patched_file does not
remove any package.
"""
filepath = patched_file.path
names = filepath.split(os.path.sep)
fullpath = config.project_path(filepath)

if not patched_file.is_deleted_file:
logging.debug('Ignoring not removed file: %s', filepath)
return None

pkg = Package(names[1], config, staff, modules)

if fullpath == pkg.metafile:
return pkg

return None

def main(args=None):
"""Main code of 'rift'"""
Expand Down
Loading