def test_demand_compile_regexp(self): scope = {} demandload.demand_compile_regexp('foo', 'frob', scope=scope) self.assertEqual(scope.keys(), ['foo']) self.assertEqual('frob', scope['foo'].pattern) self.assertEqual('frob', scope['foo'].pattern) # verify it's delayed via a bad regex. demandload.demand_compile_regexp('foo', 'f(', scope=scope) self.assertEqual(scope.keys(), ['foo']) # should blow up on accessing an attribute. obj = scope['foo'] self.assertRaises(sre_constants.error, getattr, obj, 'pattern')
def test_demand_compile_regexp(self): scope = {} demandload.demand_compile_regexp(scope, 'foo', 'frob') self.assertEqual(scope.keys(), ['foo']) self.assertEqual('frob', scope['foo'].pattern) self.assertEqual('frob', scope['foo'].pattern) # verify it's delayed via a bad regex. demandload.demand_compile_regexp(scope, 'foo', 'f(') self.assertEqual(scope.keys(), ['foo']) # should blow up on accessing an attribute. obj = scope['foo'] self.assertRaises(sre_constants.error, getattr, obj, 'pattern')
def test_demand_compile_regexp(self): scope = {} demandload.demand_compile_regexp('foo', 'frob', scope=scope) assert list(scope.keys()) == ['foo'] assert 'frob' == scope['foo'].pattern assert 'frob' == scope['foo'].pattern # verify it's delayed via a bad regex. demandload.demand_compile_regexp('foo', 'f(', scope=scope) assert list(scope.keys()) == ['foo'] # should blow up on accessing an attribute. obj = scope['foo'] with pytest.raises(sre_constants.error): getattr(obj, 'pattern')
from itertools import chain from tempfile import TemporaryDirectory from pkgcore.ebuild.misc import sort_keywords from pkgcore.ebuild.repository import UnconfiguredTree from pkgcore.exceptions import PkgcoreException from snakeoil.demandload import demand_compile_regexp from snakeoil.klass import jit_attr from snakeoil.osutils import pjoin from snakeoil.strings import pluralism as _pl from .. import base, git, results, sources from ..log import logger from . import ExplicitlyEnabledCheck, GentooRepoCheck demand_compile_regexp('ebuild_copyright_regex', r'^# Copyright (\d\d\d\d(-\d\d\d\d)?) .+') class GitCommitsRepoSource(sources.RepoSource): """Repository source for locally changed packages in git history. Parses git log history to determine packages with changes that haven't been pushed upstream yet. """ required_addons = (git.GitAddon, ) def __init__(self, *args, git_addon): super().__init__(*args) self._repo = git_addon.commits_repo(git.GitChangedRepo)
# License: GPL2/BSD """gentoo ebuild specific base package class""" __all__ = ("CPV", "versioned_CPV", "unversioned_CPV") from itertools import izip from snakeoil.compatibility import cmp from snakeoil.klass import inject_richcmp_methods_from_cmp from pkgcore.ebuild.errors import InvalidCPV from pkgcore.package import base # do this to break the cycle. from snakeoil.demandload import demandload, demand_compile_regexp demandload(globals(), "pkgcore.ebuild:atom") demand_compile_regexp(globals(), 'suffix_regexp', '^(alpha|beta|rc|pre|p)(\\d*)$') suffix_value = {"pre": -2, "p": 1, "alpha": -4, "beta": -3, "rc": -1} # while the package section looks fugly, there is a reason for it- # to prevent version chunks from showing up in the package demand_compile_regexp( globals(), 'isvalid_version_re', r"^(?:\d+)(?:\.\d+)*[a-zA-Z]?(?:_(p(?:re)?|beta|alpha|rc)\d*)*$") demand_compile_regexp(globals(), 'isvalid_cat_re', r"^(?:[a-zA-Z0-9][-a-zA-Z0-9+._]*(?:/(?!$))?)+$") demand_compile_regexp( globals(), '_pkg_re',
Please note that while this functionality can do variable interpolation, it strictly treats the source as non-executable code. It cannot parse subshells, variable additions, etc. Its primary usage is for reading things like gentoo make.conf's, or libtool .la files that are bash compatible, but non-executable. """ from shlex import shlex from snakeoil.compatibility import raise_from from snakeoil.demandload import demand_compile_regexp from snakeoil.fileutils import readlines_utf8 from snakeoil.mappings import ProtectedDict demand_compile_regexp('line_cont_regexp', r'^(.*[^\\]|)\\$') demand_compile_regexp('inline_comment_regexp', r'^.*\s#.*$') demand_compile_regexp('var_find', r'\\?(\${\w+}|\$\w+)') demand_compile_regexp('backslash_find', r'\\.') __all__ = ( "iter_read_bash", "read_bash", "read_dict", "read_bash_dict", "bash_parser", "BashParseError") def iter_read_bash(bash_source, allow_inline_comments=True, allow_line_cont=False): """Iterate over a file honoring bash commenting rules and line continuations. Note that it's considered good behaviour to close filehandles, as such, either iterate fully through this, or use read_bash instead.
import subprocess import sys from collections import defaultdict from functools import partial from weakref import WeakValueDictionary from snakeoil import klass from snakeoil.demandload import demand_compile_regexp from snakeoil.mappings import ImmutableDict, OrderedFrozenSet, inject_getitem_as_getattr from snakeoil.osutils import pjoin from snakeoil.process.spawn import bash_version from ..log import logger from . import atom, const demand_compile_regexp('_valid_EAPI_regex', r"^[A-Za-z0-9_][A-Za-z0-9+_.-]*$") eapi_optionals = ImmutableDict({ # Controls whether PROPERTIES and RESTRICT are accumulated across eclasses. "accumulate_properties_restrict": False, # Controls what version of bash compatibility to force; see PMS. "bash_compat": '3.2', # Controls whether -r is allowed for dodoc. "dodoc_allow_recursive": False, # Controls the language awareness of doman; see PMS.
from pkgcore.restrictions import boolean, values from pkgcore.restrictions.packages import AndRestriction from snakeoil import klass from snakeoil.compatibility import intern from snakeoil.demandload import demandload, demand_compile_regexp from snakeoil.mappings import IndeterminantDict demandload( "snakeoil:chksum", "snakeoil:data_source,fileutils", "pkgcore.ebuild.eapi:get_eapi", "pkgcore.log:logger", ) demand_compile_regexp('_parse_EAPI_RE', r"^EAPI=(['\"]?)([A-Za-z0-9+_.-]*)\1[\t ]*(?:#.*)?") def generate_depset(c, key, non_package_type, s, **kwds): if non_package_type: return conditionals.DepSet.parse(s.data.pop(key, ""), c, operators={ "||": boolean.OrRestriction, "": boolean.AndRestriction }, **kwds) eapi_obj = s.eapi_obj if not eapi_obj.is_supported: raise metadata_errors.MetadataException( s, "eapi", "unsupported eapi: %s" % eapi_obj.magic)
from pkgcore.restrictions import boolean, values from snakeoil import klass from snakeoil.demandload import demandload, demand_compile_regexp demandload( "snakeoil:chksum", "snakeoil:data_source,fileutils", 'snakeoil.sequences:iflatten_instance', "pkgcore.ebuild:const", "pkgcore.ebuild.eapi:get_eapi", "pkgcore:fetch", "pkgcore.log:logger", ) demand_compile_regexp('_parse_EAPI_regex', r"^EAPI=(['\"]?)([A-Za-z0-9+_.-]*)\1[\t ]*(?:#.*)?") demand_compile_regexp('_parse_inherit_regex', r'^\s*inherit\s(.*)$') def generate_depset(kls, key, non_package_type, self, **kwds): if non_package_type: return conditionals.DepSet.parse(self.data.pop(key, ""), kls, operators={ "||": boolean.OrRestriction, "": boolean.AndRestriction }, **kwds) kwds['element_func'] = self.eapi.atom_kls kwds['transitive_use_atoms'] = self.eapi.options.transitive_use_atoms return conditionals.DepSet.parse(self.data.pop(key, ""), kls, **kwds)
from snakeoil.demandload import demand_compile_regexp from snakeoil.iterables import partition from snakeoil.klass import jit_attr from snakeoil.osutils import pjoin from snakeoil.process import CommandNotFound, find_binary from snakeoil.process.spawn import spawn_get_output from snakeoil.strings import pluralism from . import base, caches, objects from .checks import GitCheck from .log import logger # hacky path regexes for git log parsing, proper validation is handled later _ebuild_path_regex_raw = '([^/]+)/([^/]+)/([^/]+)\\.ebuild' _ebuild_path_regex = '(?P<category>[^/]+)/(?P<PN>[^/]+)/(?P<P>[^/]+)\\.ebuild' demand_compile_regexp('ebuild_ADM_regex', fr'^(?P<status>[ADM])\t{_ebuild_path_regex}$') demand_compile_regexp( 'ebuild_R_regex', fr'^(?P<status>R)\d+\t{_ebuild_path_regex}\t{_ebuild_path_regex_raw}$') demand_compile_regexp('eclass_regex', r'^eclass/(?P<eclass>\S+)\.eclass$') class GitCommit: """Git commit objects.""" def __init__(self, hash, commit_date, author, committer, message): self.hash = hash self.commit_date = commit_date self.author = author self.committer = committer self.message = message
Please note that while this functionality can do variable interpolation, it strictly treats the source as non-executable code. It cannot parse subshells, variable additions, etc. Its primary usage is for reading things like gentoo make.conf's, or libtool .la files that are bash compatible, but non executable. """ from shlex import shlex from snakeoil.compatibility import raise_from from snakeoil.demandload import demand_compile_regexp from snakeoil.fileutils import readlines_utf8 from snakeoil.mappings import ProtectedDict demand_compile_regexp('line_cont_regexp', r'^(.*[^\\]|)\\$') demand_compile_regexp('inline_comment_regexp', r'^.*\s#.*$') demand_compile_regexp('var_find', r'\\?(\${\w+}|\$\w+)') demand_compile_regexp('backslash_find', r'\\.') __all__ = ( "iter_read_bash", "read_bash", "read_dict", "read_bash_dict", "bash_parser", "BashParseError") def iter_read_bash(bash_source, allow_inline_comments=True, allow_line_cont=False): """Iterate over a file honoring bash commenting rules and line continuations. Note that it's considered good behaviour to close filehandles, as such, either iterate fully through this, or use read_bash instead.
from pkgcore.fetch.errors import UnknownMirror from pkgcore.fetch import fetchable, mirror, uri_list, default_mirror from pkgcore.ebuild import processor from snakeoil.mappings import IndeterminantDict from snakeoil.currying import alias_class_method, partial from snakeoil import klass from snakeoil.compatibility import intern from snakeoil import demandload demandload.demandload( globals(), "pkgcore.log:logger", "pkgcore.ebuild.eapi:get_eapi", "snakeoil:data_source,fileutils", "snakeoil:chksum" ) demandload.demand_compile_regexp(globals(), "_parse_EAPI_RE", r"^EAPI=(['\"]?)([A-Za-z0-9+_.-]*)\1[\t ]*(?:#.*)?") def generate_depset(c, key, non_package_type, s, **kwds): if non_package_type: return conditionals.DepSet.parse( s.data.pop(key, ""), c, operators={"||": boolean.OrRestriction, "": boolean.AndRestriction}, **kwds ) eapi_obj = s.eapi_obj if not eapi_obj.is_supported: raise metadata_errors.MetadataException(s, "eapi", "unsupported eapi: %s" % eapi_obj.magic) kwds["element_func"] = eapi_obj.atom_kls kwds["transitive_use_atoms"] = eapi_obj.options.transitive_use_atoms return conditionals.DepSet.parse(s.data.pop(key, ""), c, **kwds)
# namespace compatibility... MalformedAtom = errors.MalformedAtom alphanum = set(string.digits) alphanum.update(string.ascii_letters) valid_repo_chars = set(alphanum) valid_repo_chars.update("_-") valid_slot_chars = set(alphanum) valid_slot_chars.update(".+_-") alphanum = frozenset(alphanum) valid_repo_chars = frozenset(valid_repo_chars) valid_slot_chars = frozenset(valid_slot_chars) valid_ops = frozenset(['<', '<=', '=', '~', '>=', '>']) demand_compile_regexp('valid_use_flag', r'^[A-Za-z0-9][A-Za-z0-9+_@-]*$') class atom(boolean.AndRestriction, metaclass=klass.generic_equality): """Currently implements gentoo ebuild atom parsing. Should be converted into an agnostic dependency base. """ # note we don't need _hash __slots__ = ( "blocks", "blocks_strongly", "op", "cpvstr", "negate_vers",
from collections import defaultdict, deque from operator import itemgetter from snakeoil.demandload import demand_compile_regexp from snakeoil.osutils import listdir_files, pjoin from snakeoil.sequences import iflatten_instance from ..log import logger from .atom import atom demand_compile_regexp('valid_updates_re', r'^([1-4])Q-(\d{4})$') def _scan_directory(path): files = [] for filename in listdir_files(path): match = valid_updates_re.match(filename) if match is not None: files.append(((match.group(2), match.group(1)), filename)) else: logger.error(f'incorrectly named update file: {filename!r}') files.sort(key=itemgetter(0)) return [x[1] for x in files] def read_updates(path): def f(): d = deque() return [d,d] # mods tracks the start point [0], and the tail, [1]. # via this, pkg moves into a specific pkg can pick up
# Copyright: 2006 Markus Ullmann <*****@*****.**> # Copyright: 2006 Marien Zwart <*****@*****.**> # License: BSD/GPL2 from snakeoil.demandload import demand_compile_regexp from pkgcheck import base demand_compile_regexp("indent_regexp", "^\t* \t+") class base_whitespace(base.Warning): threshold = base.versioned_feed __slots__ = () @property def lines_str(self): if len(self.lines) == 1: return "line %i" % self.lines[0] return "lines %s" % ", ".join(str(x) for x in self.lines) class WhitespaceFound(base_whitespace): """leading or trailing whitespaces are found""" __slots__ = ("category", "package", "version", "lines", "leadtrail") def __init__(self, pkg, leadtrail, lines): super(WhitespaceFound, self).__init__()
from pkgcore.restrictions import packages from snakeoil.cli.exceptions import UserException from snakeoil.demandload import demand_compile_regexp from snakeoil.klass import jit_attr from snakeoil.osutils import pjoin from snakeoil.process import CommandNotFound, find_binary from snakeoil.process.spawn import spawn_get_output from snakeoil.strings import pluralism as _pl from . import base from .log import logger # hacky ebuild path regexes for git log parsing, proper atom validation is handled later _ebuild_path_regex_raw = '([^/]+)/([^/]+)/([^/]+)\\.ebuild' _ebuild_path_regex = '(?P<category>[^/]+)/(?P<PN>[^/]+)/(?P<P>[^/]+)\\.ebuild' demand_compile_regexp('ebuild_ADM_regex', fr'^(?P<status>[ADM])\t{_ebuild_path_regex}$') demand_compile_regexp( 'ebuild_R_regex', fr'^(?P<status>R)\d+\t{_ebuild_path_regex_raw}\t{_ebuild_path_regex}$') _GitCommit = namedtuple( 'GitCommit', ['commit', 'commit_date', 'author', 'committer', 'message']) _GitPkgChange = namedtuple('GitPkgChange', [ 'atom', 'status', 'commit', 'commit_date', 'author', 'committer', 'message' ]) class ParsedGitRepo(UserDict): """Parse repository git logs.""" # git command to run on the targeted repo
import re import sys from snakeoil import mappings, weakrefs, klass from snakeoil.demandload import demandload, demand_compile_regexp from snakeoil.osutils import pjoin demandload( "functools:partial", 'snakeoil.process.spawn:bash_version,spawn_get_output', "pkgcore.ebuild:atom,const", "pkgcore.log:logger", ) demand_compile_regexp( '_valid_EAPI_regex', r"^[A-Za-z0-9_][A-Za-z0-9+_.-]*$" ) eapi_optionals = mappings.ImmutableDict({ # Controls what version of bash compatibility to force; see PMS. "bash_compat": '3.2', # Controls whether -r is allowed for dodoc. "dodoc_allow_recursive": False, # Controls the language awareness of doman; see PMS. "doman_language_detect": False, # Controls whether -i18n option is allowed. "doman_language_override": False,
# License: GPL2/BSD 3 clause from collections import deque, defaultdict from operator import itemgetter from snakeoil.demandload import demandload, demand_compile_regexp from snakeoil.fileutils import readlines from snakeoil.osutils import listdir_files, pjoin from snakeoil.sequences import iflatten_instance from pkgcore.ebuild.atom import atom demandload('pkgcore.log:logger') demand_compile_regexp( "valid_updates_re", "^(\d)Q-(\d{4})$" ) def _scan_directory(path): files = [] for x in listdir_files(path): match = valid_updates_re.match(x) if match is not None: files.append(((match.group(2), match.group(1)), x)) files.sort(key=itemgetter(0)) return [x[1] for x in files] def read_updates(path): def f():
import re from collections import defaultdict from pkgcore.ebuild.eapi import EAPI from snakeoil.demandload import demand_compile_regexp from snakeoil.klass import jit_attr from snakeoil.mappings import ImmutableDict from snakeoil.sequences import stable_unique from snakeoil.strings import pluralism as _pl from .. import results, sources from . import Check, GentooRepoCheck demand_compile_regexp( 'ebuild_copyright_regex', r'^# Copyright (?P<begin>\d{4}-)?(?P<end>\d{4}) (?P<holder>.+)$') PREFIXED_VARIABLES = ('EROOT', 'ED') PATH_VARIABLES = ('BROOT', 'ROOT', 'D') + PREFIXED_VARIABLES class _CommandResult(results.LineResult): """Generic command result.""" def __init__(self, command, **kwargs): super().__init__(**kwargs) self.command = command @property def usage_desc(self): return f'{self.command!r}'
from pkgcore.package.errors import MissingChksum from pkgcore.restrictions import boolean, values from snakeoil import klass from snakeoil.compatibility import intern from snakeoil.demandload import demandload, demand_compile_regexp demandload( "snakeoil:chksum", "snakeoil:data_source,fileutils", "pkgcore.ebuild.eapi:get_eapi", "pkgcore.log:logger", ) demand_compile_regexp( '_parse_EAPI_RE', r"^EAPI=(['\"]?)([A-Za-z0-9+_.-]*)\1[\t ]*(?:#.*)?" ) def generate_depset(c, key, non_package_type, s, **kwds): if non_package_type: return conditionals.DepSet.parse( s.data.pop(key, ""), c, operators={ "||":boolean.OrRestriction, "":boolean.AndRestriction}, **kwds) eapi = s.eapi if not eapi.is_supported: raise metadata_errors.MetadataException(s, "eapi", "unsupported EAPI: %s" % (eapi,)) kwds['element_func'] = eapi.atom_kls
# License: GPL2/BSD 3 clause from operator import itemgetter from collections import deque, defaultdict from snakeoil.osutils import listdir_files, pjoin from snakeoil.fileutils import readlines from pkgcore.ebuild.atom import atom from snakeoil.lists import iflatten_instance from snakeoil import demandload demandload.demandload( globals(), 'pkgcore.log:logger', ) demandload.demand_compile_regexp(globals(), "valid_updates_re", "^(\d)Q-(\d{4})$") def _scan_directory(path): files = [] for x in listdir_files(path): match = valid_updates_re.match(x) if match is not None: files.append(((match.group(2), match.group(1)), x)) files.sort(key=itemgetter(0)) return [x[1] for x in files] def read_updates(path): def f(): d = deque()
__all__ = ("CPV", "versioned_CPV", "unversioned_CPV") from itertools import izip from snakeoil.compatibility import cmp from snakeoil.demandload import demandload, demand_compile_regexp from snakeoil.klass import inject_richcmp_methods_from_cmp from pkgcore.ebuild.errors import InvalidCPV from pkgcore.package import base # do this to break the cycle. demandload("pkgcore.ebuild:atom") demand_compile_regexp( 'suffix_regexp', '^(alpha|beta|rc|pre|p)(\\d*)$') suffix_value = {"pre": -2, "p": 1, "alpha": -4, "beta": -3, "rc": -1} # while the package section looks fugly, there is a reason for it- # to prevent version chunks from showing up in the package demand_compile_regexp( 'isvalid_version_re', r"^(?:\d+)(?:\.\d+)*[a-zA-Z]?(?:_(p(?:re)?|beta|alpha|rc)\d*)*$") demand_compile_regexp( 'isvalid_cat_re', r"^(?:[a-zA-Z0-9][-a-zA-Z0-9+._]*(?:/(?!$))?)+$") # empty string is fine, means a -- was encounter. demand_compile_regexp(
# License: GPL2/BSD 3 clause from collections import deque, defaultdict from operator import itemgetter from snakeoil.demandload import demandload, demand_compile_regexp from snakeoil.fileutils import readlines from snakeoil.osutils import listdir_files, pjoin from snakeoil.sequences import iflatten_instance from pkgcore.ebuild.atom import atom demandload('pkgcore.log:logger') demand_compile_regexp( "valid_updates_re", "^(\d)Q-(\d{4})$" ) def _scan_directory(path): files = [] for x in listdir_files(path): match = valid_updates_re.match(x) if match is not None: files.append(((match.group(2), match.group(1)), x)) files.sort(key=itemgetter(0)) return [x[1] for x in files] def read_updates(path): def f(): d = deque()
# License: GPL2/BSD """gentoo ebuild specific base package class""" __all__ = ("CPV", "versioned_CPV", "unversioned_CPV") from snakeoil.compatibility import cmp from snakeoil.demandload import demandload, demand_compile_regexp from snakeoil.klass import inject_richcmp_methods_from_cmp from pkgcore.ebuild.errors import InvalidCPV from pkgcore.package import base # do this to break the cycle. demandload("pkgcore.ebuild:atom") demand_compile_regexp('suffix_regexp', '^(alpha|beta|rc|pre|p)(\\d*)$') suffix_value = {"pre": -2, "p": 1, "alpha": -4, "beta": -3, "rc": -1} # while the package section looks fugly, there is a reason for it- # to prevent version chunks from showing up in the package demand_compile_regexp( 'isvalid_version_re', r"^(?:\d+)(?:\.\d+)*[a-zA-Z]?(?:_(p(?:re)?|beta|alpha|rc)\d*)*$") demand_compile_regexp('isvalid_cat_re', r"^(?:[a-zA-Z0-9][-a-zA-Z0-9+._]*(?:/(?!$))?)+$") # empty string is fine, means a -- was encounter. demand_compile_regexp('_pkg_re', r"^[a-zA-Z0-9+_]+$")
"""gentoo ebuild specific base package class""" __all__ = ("CPV", "versioned_CPV", "unversioned_CPV") from itertools import izip from snakeoil.compatibility import cmp from snakeoil.klass import inject_richcmp_methods_from_cmp from pkgcore.ebuild.errors import InvalidCPV from pkgcore.package import base # do this to break the cycle. from snakeoil.demandload import demandload, demand_compile_regexp demandload(globals(), "pkgcore.ebuild:atom") demand_compile_regexp(globals(), 'suffix_regexp', '^(alpha|beta|rc|pre|p)(\\d*)$') suffix_value = {"pre": -2, "p": 1, "alpha": -4, "beta": -3, "rc": -1} # while the package section looks fugly, there is a reason for it- # to prevent version chunks from showing up in the package demand_compile_regexp(globals(), 'isvalid_version_re', r"^(?:\d+)(?:\.\d+)*[a-zA-Z]?(?:_(p(?:re)?|beta|alpha|rc)\d*)*$") demand_compile_regexp(globals(), 'isvalid_cat_re', r"^(?:[a-zA-Z0-9][-a-zA-Z0-9+._]*(?:/(?!$))?)+$") demand_compile_regexp(globals(), '_pkg_re', #empty string is fine, means a -- was encounter. r"^[a-zA-Z0-9+_]+$")
from .. import fetch from ..cache import errors as cache_errors from ..log import logger from ..package import errors as metadata_errors from ..package import metadata from ..package.base import DynamicGetattrSetter from ..restrictions import boolean, values from . import conditionals from . import errors as ebuild_errors from . import processor from .atom import atom from .eapi import get_eapi from .misc import sort_keywords demand_compile_regexp( '_EAPI_regex', r"^EAPI=(['\"]?)(?P<EAPI>[A-Za-z0-9+_.-]*)\1[\t ]*(?:#.*)?") demand_compile_regexp('_EAPI_str_regex', r"^EAPI=(['\"]?)(?P<EAPI>.*)\1") class base(metadata.package): """ebuild package :cvar _config_wrappables: mapping of attribute to callable for re-evaluating attributes dependent on configuration """ _config_wrappables = { x: klass.alias_method("evaluate_depset") for x in ( "bdepend", "depend",
Please note that while this functionality can do variable interpolation, it strictly treats the source as non-executable code. It cannot parse subshells, variable additions, etc. Its primary usage is for reading things like gentoo make.conf's, or libtool .la files that are bash compatible, but non executable. """ from shlex import shlex from snakeoil.compatibility import raise_from from snakeoil.demandload import demand_compile_regexp from snakeoil.fileutils import readlines_utf8 from snakeoil.mappings import ProtectedDict demand_compile_regexp("line_cont_regexp", r"^(.*[^\\]|)\\$") demand_compile_regexp("inline_comment_regexp", r"^.*\s#.*$") demand_compile_regexp("var_find", r"\\?(\${\w+}|\$\w+)") demand_compile_regexp("backslash_find", r"\\.") __all__ = ("iter_read_bash", "read_bash", "read_dict", "read_bash_dict", "bash_parser", "BashParseError") def iter_read_bash(bash_source, allow_inline_comments=True, allow_line_cont=False): """Iterate over a file honoring bash commenting rules and line continuations. Note that it's considered good behaviour to close filehandles, as such, either iterate fully through this, or use read_bash instead. Once the file object is no longer referenced the handle will be closed, but be proactive instead of relying on the garbage collector.
from tempfile import TemporaryDirectory from urllib.parse import urlparse from pkgcore.ebuild.misc import sort_keywords from pkgcore.ebuild.repository import UnconfiguredTree from pkgcore.exceptions import PkgcoreException from snakeoil import klass from snakeoil.demandload import demand_compile_regexp from snakeoil.osutils import pjoin from snakeoil.strings import pluralism from .. import base, git, results, sources from ..log import logger from . import GentooRepoCheck, GitCheck demand_compile_regexp('copyright_regex', r'^# Copyright (\d\d\d\d(-\d\d\d\d)?) .+') demand_compile_regexp('commit_footer', r'^(?P<tag>[a-zA-Z0-9_-]+): (?P<value>.*)$') demand_compile_regexp('git_cat_file_regex', r'^(?P<object>.+?) (?P<status>.+)$') class GitCommitsRepoSource(sources.RepoSource): """Repository source for locally changed packages in git history. Parses git log history to determine packages with changes that haven't been pushed upstream yet. """
from snakeoil import chksum, data_source, fileutils, klass from snakeoil.demandload import demand_compile_regexp from snakeoil.sequences import iflatten_instance from pkgcore import fetch from pkgcore.cache import errors as cache_errors from pkgcore.ebuild import conditionals, const, processor, errors as ebuild_errors from pkgcore.ebuild.atom import atom from pkgcore.ebuild.eapi import get_eapi from pkgcore.ebuild.misc import sort_keywords from pkgcore.log import logger from pkgcore.package import errors as metadata_errors, metadata from pkgcore.restrictions import boolean, values demand_compile_regexp( '_EAPI_regex', r"^EAPI=(['\"]?)(?P<EAPI>[A-Za-z0-9+_.-]*)\1[\t ]*(?:#.*)?") demand_compile_regexp( '_EAPI_str_regex', r"^EAPI=(['\"]?)(?P<EAPI>.*)\1") demand_compile_regexp('_parse_inherit_regex', r'^\s*inherit\s(?P<eclasses>.*?)(#.*)?$') def generate_depset(kls, key, self): return conditionals.DepSet.parse( self.data.pop(key, ""), kls, attr=key, element_func=self.eapi.atom_kls, transitive_use_atoms=self.eapi.options.transitive_use_atoms) def generate_licenses(self): return conditionals.DepSet.parse( self.data.pop('LICENSE', ''), str,
from snakeoil.demandload import demand_compile_regexp from snakeoil.strings import pluralism as _pl from .. import results, sources from . import Check demand_compile_regexp('indent_regexp', '^\t* \t+') class _Whitespace(results.VersionResult, results.Warning): @property def lines_str(self): return f"line{_pl(self.lines)}: {', '.join(str(x) for x in self.lines)}" class WhitespaceFound(_Whitespace): """Leading or trailing whitespace found.""" def __init__(self, leadtrail, lines, **kwargs): super().__init__(**kwargs) self.lines = tuple(lines) self.leadtrail = leadtrail @property def desc(self): return f"ebuild has {self.leadtrail} whitespace on {self.lines_str}" class WrongIndentFound(_Whitespace): """Incorrect indentation whitespace found.""" def __init__(self, lines, **kwargs): super().__init__(**kwargs)
# Copyright: 2011 Brian Harring <*****@*****.**> # License: GPL2/BSD 3 clause from operator import itemgetter from collections import deque, defaultdict from snakeoil.osutils import listdir_files, pjoin from snakeoil.fileutils import readlines from snakeoil.iterables import chain_from_iterable from pkgcore.ebuild.atom import atom from snakeoil.lists import iflatten_instance from snakeoil import demandload demandload.demandload(globals(), 'pkgcore.log:logger', ) demandload.demand_compile_regexp(globals(), "valid_updates_re", "^(\d)Q-(\d{4})$") def _scan_directory(path): files = [] for x in listdir_files(path): match = valid_updates_re.match(x) if match is not None: files.append(((match.group(2), match.group(1)), x)) files.sort(key=itemgetter(0)) return [x[1] for x in files] def read_updates(path): def f(): d = deque() return [d,d]
from snakeoil import klass from snakeoil.demandload import demandload, demand_compile_regexp demandload( "snakeoil:chksum", "snakeoil:data_source,fileutils", 'snakeoil.sequences:iflatten_instance', "pkgcore.ebuild:const", "pkgcore.ebuild.eapi:get_eapi", "pkgcore:fetch", "pkgcore.log:logger", ) demand_compile_regexp( '_parse_EAPI_regex', r"^EAPI=(['\"]?)([A-Za-z0-9+_.-]*)\1[\t ]*(?:#.*)?" ) demand_compile_regexp('_parse_inherit_regex', r'^\s*inherit\s(.*)$') def generate_depset(kls, key, non_package_type, self, **kwds): if non_package_type: return conditionals.DepSet.parse( self.data.pop(key, ""), kls, operators={ "||": boolean.OrRestriction, "": boolean.AndRestriction}, **kwds) kwds['element_func'] = self.eapi.atom_kls kwds['transitive_use_atoms'] = self.eapi.options.transitive_use_atoms return conditionals.DepSet.parse(self.data.pop(key, ""), kls, **kwds)