Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def load_plugins(self, path, excludes=[]):
"""finds all plugins in dir and it's subdirectories"""
pyfiles = path.rglob('*.py')
for pyfile in pyfiles:
splitted_path = self._os_path_split(str(pyfile)[:-3])
path_to_file = '.'.join(splitted_path[:-1])
imported_path = __import__(
path_to_file, fromlist=[splitted_path[-1]])
imported_file = getattr(imported_path, splitted_path[-1])
plugin_file = imported_file.__name__
for var_name in dir(imported_file):
attr = getattr(imported_file, var_name)
if inspect.isclass(attr) and attr != Plugin and \
issubclass(attr, Plugin):
try:
plugin = attr()
plugin_name = plugin.__class__.__name__
if plugin_name not in excludes:
self.plugins.add(plugin)
logging.info("plugin %s loaded (%s)" %
(plugin_name, plugin_file))
else:
logging.info("plugin %s was excluded (%s)" %
(plugin_name, plugin_file))
except Exception:
logging.warn("plugin %s not loaded (%s)" %
(plugin_name, plugin_file))
from rpg.plugin import Plugin
from rpg.command import Command
from modulefinder import ModuleFinder
import logging
import rpm
class PythonPlugin(Plugin):
def patched(self, project_dir, spec, sack):
""" Find python dependencies """
for item in list(project_dir.glob('**/*.py')):
try:
mod = ModuleFinder()
mod.run_script(str(item))
for _, mod in mod.modules.items():
if mod.__file__ and mod.__file__.startswith("/usr/lib"):
spec.required_files.add(mod.__file__)
except ImportError as ie:
logging.warn("Exception was raised by ModuleFinder:\n" +
str(ie) + "\nOn file: " + str(item))
def installed(self, project_dir, spec, sack):
""" Compiles all python files depending on which python version they
from rpg.command import Command
from rpg.plugin import Plugin
import logging
class MakePlugin(Plugin):
def patched(self, project_dir, spec, sack):
""" Appends commands to build Project using Makefile build system """
if (project_dir / "Makefile").is_file() or\
(project_dir / "makefile").is_file():
spec.BuildRequires.add("make")
logging.debug('Makefile found')
cmd_build = Command("make")
cmd_install = Command("make install DESTDIR=$RPM_BUILD_ROOT")
spec.build = cmd_build
spec.install = cmd_install
from rpg.command import Command
from rpg.plugin import Plugin
from rpg.utils import str_to_pkgname
import logging
import re
class AutotoolsPlugin(Plugin):
re_CHECK_MODULES = re.compile(
r"PKG_CHECK_MODULES\s*\(.*?,\s*(.*?)\s*?[,\)]", re.DOTALL)
re_CHECK_PROGS = re.compile(
r"((?:(?:/bin/)|(?:/usr)(?:/bin/)?)[\w/\.-]+)", re.DOTALL)
re_CHECK_MAKEFILE = re.compile(
r"(/[\w/\.-]+\.h)", re.DOTALL)
def extracted(self, project_dir, spec, sack):
if (project_dir / "configure.ac").is_file():
regex = re.compile(
r"AC_INIT\s*\(\s*\[?\s*?(.*?)\s*\]?\s*,\s*"
r"\[?\s*?(.*?)\s*\]?\s*?[,)]",
re.IGNORECASE | re.DOTALL)
from rpg.command import Command
from rpg.plugin import Plugin
from rpg.utils import str_to_pkgname
from javapackages.maven.artifact import Artifact
from javapackages.maven.artifact import ArtifactFormatException
from javapackages.maven.artifact import ArtifactValidationException
from lxml import etree
import logging
import re
class MavenPlugin(Plugin):
def extracted(self, project_dir, spec, sack):
if (project_dir / "pom.xml").is_file():
et = etree.parse(str(project_dir / "pom.xml")).getroot()
for branch in et:
tag = re.sub(r'^{.*?}', '', str(branch.tag))
if tag == 'name':
spec.Name = str_to_pkgname(branch.text.strip())
elif tag == 'version':
spec.Version = re.sub('-SNAPSHOT', '', branch.text.strip())
elif tag == 'description':
spec.description = branch.text.strip()
elif tag == 'url':
spec.URL = branch.text.strip()
def patched(self, project_dir, spec, sack):
from rpg.plugin import Plugin
class FindTranslationPlugin(Plugin):
def installed(self, project_dir, spec, sack):
translation_file = list(project_dir.glob('**/*.mo'))
if translation_file and translation_file[0].is_file():
spec.files.add((("-f %%{%s}.lang"
% translation_file[0].name), None, None))
from rpg.command import Command
from rpg.plugin import Plugin
from rpg.utils import str_to_pkgname
import logging
import re
class SetuptoolsPlugin(Plugin):
def extracted(self, project_dir, spec, sack):
if (project_dir / "setup.py").is_file():
with (project_dir / "setup.py").open() as f:
matches = re.findall(
r'(name|version|description|license|url)'
r'\s*=\s*\(?"(.*?)"\)?\s*,',
f.read(), re.IGNORECASE | re.DOTALL)
for match in matches:
if match[0] == "name":
spec.Name = str_to_pkgname(match[1])
elif match[0] == "version":
spec.Version = match[1]
elif match[0] == "description":
spec.description = re.sub(r'\".*?\"', '', match[1])
elif match[0] == "license":
from rpg.plugin import Plugin
import subprocess
class FindPatchPlugin(Plugin):
def extracted(self, project_dir, spec, sack):
patches = [(f, f.stat().st_mtime) for f in project_dir.iterdir()
if _is_patch(f)]
patches_by_modification = sorted(patches, key=lambda m: m[1])
spec.Patch = list(
map(lambda p: str(p[0]), patches_by_modification))
def _is_patch(path):
if path.is_dir():
return False
output = subprocess.check_output(["file", str(path), "-b"])
return output.decode().find("unified diff output") != -1
from rpg.plugin import Plugin
class FindLibraryPlugin(Plugin):
def installed(self, project_dir, spec, sack):
""" Appends ldconfig if any type of library is installed """
dyn_libs = list(project_dir.glob('**/lib*.so*'))
static_libs = list(project_dir.glob('**/lib*.a*'))
if ((dyn_libs and dyn_libs[0].is_file()) or
static_libs and static_libs[0].is_file()):
# FIXME when Command is integrated with Spec
spec.post.append("/sbin/ldconfig")
spec.postun.append("/sbin/ldconfig")
from rpg.plugin import Plugin
from re import search
class BashCommandPlugin(Plugin):
_file = ""
def mock_recover(self, log, spec):
""" Parses mock logs and finds missing executables, append them
into build_required_files (to be translated into packages)
Returns True on any change"""
for err in log:
match = search(
r"\s*([^:]+)\:\s*" +
r"[cC][oO][mM][mM][aA][nN][dD]\s*[nN][oO][tT]\s*" +
r"[fF][oO][uU][nN][dD]", err)
if match:
if match.group(1) == self._file or\
"/usr/bin/" + match.group(1) == self._file:
raise RuntimeError("Couldn't resolve '{}'!"