Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from typing import Dict, List, Optional
from rebasehelper.helpers.process_helper import ProcessHelper
from rebasehelper.plugins.checkers import BaseChecker, CheckerCategory
class LicenseCheck(BaseChecker):
"""license compare tool
Attributes:
license_changes(bool): Boolean value to inform whether any license change occured.
license_files_changes(dict): Dictionary of {license: change_type + file_name} pairs.
"""
DEFAULT: bool = True
CATEGORY: Optional[CheckerCategory] = CheckerCategory.SOURCE
CMD: str = 'licensecheck'
license_changes: bool = False
license_files_changes: Dict[str, str] = {}
@classmethod
def is_available(cls):
try:
return ProcessHelper.run_subprocess([cls.CMD, '--help'], output_file=ProcessHelper.DEV_NULL) == 0
except (IOError, OSError):
return False
@classmethod
def get_license_changes(cls, old_dir, new_dir):
"""
Finds differences in licenses between old and new source files.
category=CheckerCategory.SOURCE,
old_dir=old_sources,
new_dir=new_sources)
try:
self.patch_sources([old_sources, new_sources])
except RebaseHelperError as e:
# Print summary and return error
self.print_summary(e)
raise
# Build packages
while True:
try:
if self.conf.build_tasks is None:
self.build_source_packages()
self.run_package_checkers(self.results_dir, category=CheckerCategory.SRPM)
self.build_binary_packages()
if self.conf.builds_nowait and not self.conf.build_tasks:
return
self.run_package_checkers(self.results_dir, category=CheckerCategory.RPM)
# Print summary and return error
except RebaseHelperError as e:
logger.error(e.msg)
if self.conf.build_tasks is None and self.prepare_next_run(self.results_dir):
continue
self.print_summary(e)
raise
else:
break
if not self.conf.keep_workspace:
self._delete_workspace_dir()
from rebasehelper.exceptions import RebaseHelperError, CheckerNotFoundError
from rebasehelper.logger import CustomLogger
from rebasehelper.results_store import results_store
from rebasehelper.plugins.checkers import BaseChecker, CheckerCategory
from rebasehelper.helpers.process_helper import ProcessHelper
from rebasehelper.helpers.rpm_helper import RpmHelper
logger: CustomLogger = cast(CustomLogger, logging.getLogger(__name__))
class PkgDiff(BaseChecker):
""" Pkgdiff compare tool. """
DEFAULT: bool = True
CATEGORY: Optional[CheckerCategory] = CheckerCategory.RPM
CMD: str = 'pkgdiff'
CHECKER_TAGS: List[str] = ['added', 'removed', 'changed', 'moved', 'renamed']
pkgdiff_results_filename: str = 'report'
files_xml: str = 'files.xml'
results_dir: str = ''
results_dict: Dict[str, List[str]] = {}
@classmethod
def is_available(cls):
try:
return ProcessHelper.run_subprocess([cls.CMD, '--help'], output_file=ProcessHelper.DEV_NULL) == 0
except (IOError, OSError):
return False
@classmethod
def print_checkers_text_output(cls, checkers_results):
"""Outputs text output of every checker."""
for category in (CheckerCategory.SOURCE, CheckerCategory.SRPM, CheckerCategory.RPM):
for check_tool in cls.manager.checkers.plugins.values():
if check_tool and check_tool.get_category() == category:
for check, data in sorted(checkers_results.items()):
if check == check_tool.name:
logger_report.info('\n'.join(check_tool.format(data)))
from rebasehelper.exceptions import RebaseHelperError, CheckerNotFoundError
from rebasehelper.logger import CustomLogger
from rebasehelper.results_store import results_store
from rebasehelper.plugins.checkers import BaseChecker, CheckerCategory
from rebasehelper.helpers.process_helper import ProcessHelper
from rebasehelper.helpers.rpm_helper import RpmHelper
logger: CustomLogger = cast(CustomLogger, logging.getLogger(__name__))
class RpmDiff(BaseChecker):
"""rpmdiff compare tool"""
DEFAULT: bool = True
CATEGORY: Optional[CheckerCategory] = CheckerCategory.RPM
CMD: str = 'rpmdiff'
CHECKER_TAGS: List[str] = ['added', 'removed', 'changed', 'moved', 'renamed']
@classmethod
def is_available(cls):
try:
return ProcessHelper.run_subprocess([cls.CMD, '--help'], output_file=ProcessHelper.DEV_NULL) == 0
except (IOError, OSError):
return False
@classmethod
def _get_rpms(cls, rpm_list):
rpm_dict = {}
for rpm_name in rpm_list:
rpm_dict[RpmHelper.get_header_from_rpm(rpm_name).name] = rpm_name
from rebasehelper.logger import CustomLogger
from rebasehelper.results_store import results_store
from rebasehelper.plugins.checkers import BaseChecker, CheckerCategory
from rebasehelper.helpers.rpm_helper import RpmHelper
logger: CustomLogger = cast(CustomLogger, logging.getLogger(__name__))
SonameChanges = Dict[str, Dict[str, List[Union[str, Dict[str, str]]]]]
class SonameCheck(BaseChecker):
DEFAULT: bool = True
CATEGORY: Optional[CheckerCategory] = CheckerCategory.RPM
@classmethod
def is_available(cls):
return True
@classmethod
def _get_sonames(cls, provides: List[str]) -> Set[str]:
soname_re = re.compile(r'(?P[^()]+\.so[^()]+)\(.*\)(\(64bit\))?')
sonames = set()
for p in provides:
match = soname_re.match(p)
if match:
sonames.add(match.group('soname'))
return sonames
@classmethod
for tool_name, tool in plugin_manager.build_tools.plugins.items():
if tool and tool.ACCEPTS_OPTIONS:
tools_accepting_options.append(tool_name)
if self.conf.buildtool not in tools_accepting_options:
options_used = []
if self.conf.builder_options is not None:
options_used.append('--builder-options')
if options_used:
raise RebaseHelperError("{} can be used only with the following build tools: {}".format(
" and ".join(options_used),
", ".join(tools_accepting_options)))
if self.conf.build_tasks is None:
old_sources, new_sources = self.prepare_sources()
self.run_package_checkers(self.results_dir,
category=CheckerCategory.SOURCE,
old_dir=old_sources,
new_dir=new_sources)
try:
self.patch_sources([old_sources, new_sources])
except RebaseHelperError as e:
# Print summary and return error
self.print_summary(e)
raise
# Build packages
while True:
try:
if self.conf.build_tasks is None:
self.build_source_packages()
self.run_package_checkers(self.results_dir, category=CheckerCategory.SRPM)
self.build_binary_packages()