commit: 96e05b63f98d71393e593c6194e2218b6f37abcb Author: André Erdmann <dywi <AT> mailerd <DOT> de> AuthorDate: Thu Jul 17 13:54:27 2014 +0000 Commit: André Erdmann <dywi <AT> mailerd <DOT> de> CommitDate: Thu Jul 17 13:54:27 2014 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=96e05b63
util/portage_regex: add wildcard module matches package strings (CATEGORY/PF, PF, P, PN, PV, PVR, ...) containing wildcard characters, e.g. "sys-*/a*-5.*-r1?". --- roverlay/util/portage_regex/wildcard.py | 75 +++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/roverlay/util/portage_regex/wildcard.py b/roverlay/util/portage_regex/wildcard.py new file mode 100644 index 0000000..fd6308f --- /dev/null +++ b/roverlay/util/portage_regex/wildcard.py @@ -0,0 +1,75 @@ +# R overlay -- roverlay package, util, portage regex - wildcard +# -*- coding: utf-8 -*- +# Copyright (C) 2014 André Erdmann <d...@mailerd.de> +# Distributed under the terms of the GNU General Public License; +# either version 2 of the License, or (at your option) any later version. + +import roverlay.util.portage_regex.default as pre_default +#from . import default as pre_default + + +PAT_WILDCARD_PACKAGE_NAME = pre_default.FMT_PAT_A_PACKAGE_NAME.format ( + a=r'a-zA-Z+*?', b=r'0-9', c=r'-_' +) +PAT_WILDCARD_CATEGORY_NAME = pre_default.FMT_PAT_A_CATEGORY_NAME.format ( + r'a-zA-Z+0-9*?', r'\-_' +) + +PAT_WILDCARD_DOT_DIGITS = pre_default.FMT_PAT_DOT_DIGITS.format ( '0-9*?', '.' ) +PAT_WILDCARD_VERSION = ( + # no wildcard support for the optional a-zA-Z at the end of the str + r'(?P<version>{}[a-zA-Z]?)'.format ( PAT_WILDCARD_DOT_DIGITS ) +) +##PAT_WILDCARD_VSUFFIX = <version suffix not supported> +## (using PAT_A_DEP_ATOM_VERSION_SUFFIXES, +## which may or may not work) + +PAT_WILDCARD_REVISION = r'(?:r(?P<revision>[0-9*?]+))' + + +PAT_WILDCARD_PVR = pre_default.FMT_PAT_PVR.format ( + version = PAT_WILDCARD_VERSION, + version_suffixes = pre_default.PAT_A_DEP_ATOM_VERSION_SUFFIXES, + revision = PAT_WILDCARD_REVISION, +) + +PAT_WILDCARD_PN = pre_default.FMT_PAT_PN.format ( + package_name = PAT_WILDCARD_PACKAGE_NAME, +) + +PAT_WILDCARD_PF = pre_default.FMT_PAT_PF.format ( + pn = PAT_WILDCARD_PN, + pvr = PAT_WILDCARD_PVR, +) + +PAT_WILDCARD_CATEGORY = pre_default.FMT_PAT_CATEGORY.format ( + category_name = PAT_WILDCARD_CATEGORY_NAME +) + +PAT_WILDCARD_PACKAGE = pre_default.FMT_PAT_PACKAGE.format ( + category = PAT_WILDCARD_CATEGORY, + pf = PAT_WILDCARD_PF +) + +RE_WILDCARD_CATEGORY = pre_default.MultiRegexProxy.compile_exact ( + PAT_WILDCARD_CATEGORY +) +RE_WILDCARD_PACKAGE = pre_default.MultiRegexProxy.compile_exact ( + PAT_WILDCARD_PACKAGE +) + + +if __name__ == '__main__': + import sys + + for s in sys.argv[1:]: + match = RE_WILDCARD_PACKAGE.match(s) + k,h,x = s.partition("/") + if h: + print(k,RE_WILDCARD_CATEGORY.match(k),PAT_WILDCARD_CATEGORY) + + + if match: + print ( "{!s} : {!s}".format ( s, match.groupdict() ) ) + else: + print ( "{!s} not matched".format ( s ) )