* [gentoo-commits] proj/R_overlay:master commit in: roverlay/depres/simpledeprule/
@ 2012-07-11 18:43 André Erdmann
0 siblings, 0 replies; 19+ messages in thread
From: André Erdmann @ 2012-07-11 18:43 UTC (permalink / raw
To: gentoo-commits
commit: bfbd448ff8727a18b90947c255a9ebd456a96651
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Wed Jul 11 18:42:52 2012 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Wed Jul 11 18:42:52 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=bfbd448f
depres console (module code)
* this console can be used to interactively create new rules,
test dependency resolution etc.
new file: roverlay/depres/simpledeprule/console.py
---
roverlay/depres/simpledeprule/console.py | 406 ++++++++++++++++++++++++++++++
1 files changed, 406 insertions(+), 0 deletions(-)
diff --git a/roverlay/depres/simpledeprule/console.py b/roverlay/depres/simpledeprule/console.py
new file mode 100644
index 0000000..e3db541
--- /dev/null
+++ b/roverlay/depres/simpledeprule/console.py
@@ -0,0 +1,406 @@
+import re
+import os
+import sys
+import shlex
+import logging
+
+from roverlay import config
+from roverlay.depres.depresolver import DependencyResolver
+from roverlay.depres.channels import EbuildJobChannel
+from roverlay.depres.simpledeprule.pool import SimpleDependencyRulePool
+from roverlay.depres.simpledeprule.rulemaker import SimpleRuleMaker
+
+from roverlay.depres.simpledeprule import rules
+class PackageDirRuleMaker ( object ):
+ """Scans a distdir and creates selfdep rules for it.
+ Part of the console module 'cause only used here (currently).
+ """
+
+ def __init__ ( self, fuzzy=True ):
+ self.fuzzy = fuzzy
+ self.package_regex = re.compile (
+ "^(?P<name>[^_]+)_.+{}$".format (
+ config.get_or_fail ( 'R_PACKAGE.suffix_regex' )
+ )
+ )
+ # --- end of __init__ (...) ---
+
+ def _scan ( self, distdir ):
+ # ~duplicate of remote/basicrepo
+
+ for dirpath, dirnames, filenames in os.walk ( distdir ):
+ for filename in filenames:
+ m = self.package_regex.match ( filename )
+ if m is not None:
+ yield m.group ( 'name' )
+ # --- end of _scan (...) ---
+
+ def make_rules ( self, distdir ):
+ cat = config.get_or_fail ( 'OVERLAY.category' ) + '/'
+ if self.fuzzy:
+ for dep in self._scan ( distdir ):
+ yield rules.SimpleFuzzyDependencyRule (
+ resolving_package = cat + dep,
+ dep_str = dep,
+ is_selfdep=True
+ )
+ else:
+ for dep in self._scan ( distdir ):
+ yield rules.SimpleDependencyRule (
+ resolving_package = cat + dep,
+ dep_str = dep,
+ is_selfdep=True
+ )
+ # --- end of make_rules (...) ---
+
+
+class DepResConsole ( object ):
+ # !! The console is really inefficient in terms of using cached data,
+ # saving functions calls, ...
+ # It's assumed that the user is still slower ;)
+
+ shlex = shlex.shlex()
+ whitespace = re.compile ( "\s+" )
+
+ def __init__ ( self ):
+ self.resolver = DependencyResolver()
+ # log everything
+ self.resolver.set_logmask ( -1 )
+ # disable passing events to listeners
+ self.resolver.set_listenermask ( 0 )
+
+ self.poolstack = self.resolver.static_rule_pools
+ self.pool_id = 0
+
+ self._rule_maker = SimpleRuleMaker()
+ self._dir_rule_maker = PackageDirRuleMaker()
+
+ self._cwd = None
+
+ self.shlex_active = True
+
+ self.PS1 = "cmd % "
+
+ self.stdout = sys.stdout.write
+ self.stderr = sys.stderr.write
+
+ self.cmd_table = {
+ 'resolve' : self.cmd_resolve,
+ 'r' : self.cmd_resolve,
+ '?' : self.cmd_resolve,
+ 'scandir' : self.cmd_rule_scandir,
+ 'sd' : self.cmd_rule_scandir,
+ 'addrule' : self.cmd_rule_add,
+ '+' : self.cmd_rule_add,
+ 'load' : self.cmd_rule_load,
+ 'li' : self.cmd_rule_load,
+ 'l' : self.cmd_rule_load,
+ 'load_conf' : self.cmd_rule_load_from_config,
+ 'lc' : self.cmd_rule_load_from_config,
+ 'pool' : self.cmd_pool,
+ 'write' : self.cmd_pool_write,
+ 'w' : self.cmd_pool_write,
+ 'p' : self.cmd_pool_print,
+ 'print' : self.cmd_pool_print,
+ 'unwind' : self.cmd_pool_unwind,
+ '>>' : self.cmd_pool_unwind,
+ 'add_pool' : self.cmd_pool_add,
+ '<<' : self.cmd_pool_add,
+ 'cd' : self.cmd_cd,
+ 'set' : self.cmd_set,
+ 'unset' : self.cmd_unset,
+ 'help' : self.cmd_help,
+ }
+
+ self.cmd_exit = frozenset (( 'q', 'qq', 'exit' ))
+
+ if sys.version_info < ( 3, 0 ):
+ self._get_input = raw_input
+ else:
+ self._get_input = input
+ # --- end of __init__ (...) ---
+
+ def _getpool ( self, new=False ):
+ if new or not self.poolstack:
+ pool = SimpleDependencyRulePool ( "pool" + str ( self.pool_id ) )
+ self.pool_id += 1
+ self.poolstack.append ( pool )
+ self.resolver._reset_unresolvable()
+
+ return self.poolstack [-1]
+ # --- end of _getpool (...) ---
+
+ def cmd_cd ( self, argv, line ):
+ if not argv:
+ self.stdout (
+ "usage is cd <dir>, dir will be created if not existent.\n"
+ )
+ return False
+ else:
+ self._cwd = os.path.abspath ( argv [0] )
+ if not os.path.isdir ( self._cwd ):
+ os.makedirs ( self._cwd )
+ self.stdout ( "cwd = {!r}\n".format ( self._cwd ) )
+ return True
+ # --- end of cmd_cd (...) ---
+
+ def cmd_rule_scandir ( self, argv, *ignored ):
+ if not argv:
+ self.stdout ( "usage is scandir <dir>\n" )
+ return False
+ elif not os.path.isdir ( argv[0] ):
+ self.stderr ( "arg0 is not a dir\n" )
+ return False
+
+ pool = self._getpool ( new=True )
+ self.stdout ( "new rules:\n" )
+ for r in self._dir_rule_maker.make_rules ( argv [0] ):
+ self.stdout ( str ( r ) + "\n" )
+ pool.add ( r )
+ self.stdout ( "--- ---\n" )
+ pool.sort()
+
+ def cmd_rule_load_from_config ( self, *ignored ):
+ load = config.get_or_fail ( "DEPRES.simple_rules.files" )
+ self._getpool ( new=True ).get_reader().read ( load )
+ # don't write into ^this pool
+ self._getpool ( new=True )
+ # --- end of cmd_rule_load_from_config (...) ---
+
+ def cmd_rule_load ( self, argv, line ):
+ if argv:
+ self._getpool().get_reader().read ( argv )
+ else:
+ self.stdout ( "usage is load/li <files or dirs>\n" )
+ # --- end of cmd_rule_load (...) ---
+
+ def cmd_rule_add ( self, argv, line ):
+ if not line:
+ self.stdout ( "usage is <cmd> <rule>\n" )
+ elif self._rule_maker.add ( line ):
+ rules = self._rule_maker.done()
+
+ self.stdout ( "new rules:\n" )
+ for r in rules:
+ self.stdout ( str ( r ) + "\n" )
+ self.stdout ( "--- ---\n" )
+
+ pool = self._getpool()
+ pool.rules.extend ( rules )
+ pool.sort()
+
+ self.resolver._reset_unresolvable()
+
+ return True
+ else:
+ return False
+ # --- end of cmd_addrule (...) ---
+
+ def cmd_pool_help ( self, *ignore ):
+ self.stdout ( "<todo>\n" )
+ # --- end of cmd_pool_help (...) ---
+
+ def cmd_pool_print ( self, argv, *ignore ):
+ if argv and len ( argv ) > 0:
+ if argv[0] == "all":
+ _last = len ( self.poolstack )
+ for n, p in enumerate ( self.poolstack ):
+ self.stdout ( "showing pool {}/{}.\n".format (
+ n + 1, _last
+ ))
+ p.export_rules ( sys.stdout )
+ else:
+ self.stdout ( "unknown arg1 {!r}.\n".format ( argv[0] ) )
+ return False
+ else:
+ if len ( self.poolstack ):
+ self.poolstack [-1].export_rules ( sys.stdout )
+ # --- end of cmd_pool_print (...) ---
+
+ def cmd_pool ( self, argv, line ):
+ if not argv:
+ self.stdout ( "usage: pool <action> [args]\n" )
+ return self.cmd_pool_help()
+
+ cmd = argv[0]
+
+ if cmd == "unwind" or cmd == "destroy":
+ return self.cmd_pool_unwind ( argv, line )
+ elif cmd == "add" or cmd == "create":
+ return self.cmd_pool_add ( argv, line )
+ elif cmd == "print" or cmd == "show":
+ if len ( argv ) > 1:
+ return self.cmd_pool_print ( argv[1:] )
+ else:
+ return self.cmd_pool_print ( None )
+
+ # --- end of cmd_pool (...) ---
+
+ def cmd_pool_write ( self, argv, *ignore ):
+ if not argv:
+ self.stdout ( "usage: write <file>\n" )
+ return False
+
+ if argv[0][0] == os.sep:
+ f = argv [0]
+ elif self._cwd is not None:
+ f = self._cwd + os.sep + argv [0]
+ else:
+ f = os.path.abspath ( argv[0] )
+
+ if os.access ( f, os.F_OK ):
+ self.stdout ( "file {!r} exists!\n".format ( f ) )
+ return False
+
+ elif len ( self.poolstack ):
+ try:
+ fh = open ( f, 'w' )
+ self.poolstack[-1].export_rules ( fh )
+ fh.close()
+ self.stdout ( "Wrote {!r}.\n".format ( f ) )
+ return True
+ finally:
+ if 'fh' in locals() and fh: fh.close()
+
+ else:
+ self.stdout ( "no pool in use.\n" )
+ return False
+
+
+ def cmd_pool_unwind ( self, *ignore ):
+ if self.poolstack:
+ self.poolstack.pop()
+ self.stdout ( "Pool removed from resolver.\n" )
+ else:
+ self.stdout ( "Resolver has no pools.\n" )
+ # --- end of cmd_pool_unwind (...) ---
+
+ def cmd_pool_add ( self, *ignore ):
+ self._getpool ( new=True )
+ self.stdout ( "New pool created.\n" )
+ # --- end of cmd_pool_add (...) ---
+
+ def run ( self ):
+ cmd = None
+
+ self.stdout (
+ '== depres console ==\n'
+ 'run \'help\' to list all known commands\n'
+ 'use \'load_conf\' or \'lc\' to load the configured rule files\n'
+ )
+ if self.shlex_active:
+ self.stdout (
+ 'Note: shlex mode is enabled by default. '
+ 'This splits all args according to shell syntax. '
+ 'You can disable this (useful when resolving) '
+ 'with \'unset shlex\'.\n'
+ )
+ self.stdout ( "\n" )
+ self.cmd_help()
+ self.stdout ( "\n" )
+
+ while True:
+ try:
+ #self.stdout ( "\n" )
+ cmd, argv, line = self.split_line ( self._get_input ( self.PS1 ) )
+
+ if cmd is None:
+ pass
+ elif cmd in self.cmd_exit:
+ break
+ elif cmd in self.cmd_table:
+ ret = self.cmd_table [cmd] ( argv, line )
+ if ret is True:
+ self.stdout ( "command succeeded.\n" )
+ elif ret is False:
+ self.stdout ( "command failed.\n" )
+ else:
+ self.stdout ( "command {!r} not found.\n".format ( cmd ) )
+ self.cmd_help()
+
+ except KeyboardInterrupt:
+ self.stdout ( "\nuse \'exit\' to exit (or close stdin)\n" )
+ except EOFError:
+ self.stderr ( "\nexiting...\n" )
+ break
+ except Exception as e:
+ logging.exception ( e )
+ self.stderr ( str ( e ) + "\n" )
+
+ self.resolver.close()
+ # --- end of run (...) ---
+
+ def split_line ( self, line ):
+ l = line.strip()
+ if not l:
+ return ( None, None, None )
+
+ linev = self.__class__.whitespace.split ( l, 1 )
+
+ if len ( linev ) == 0:
+ return ( None, None, None )
+ elif len ( linev ) == 1:
+ return ( linev [0].lower(), None, None )
+ elif self.shlex_active:
+ return ( linev [0].lower(), shlex.split ( linev [1] ), linev [1] )
+ else:
+ return ( linev [0].lower(), ( linev [1], ), linev [1] )
+ # --- end of split_line (...) ---
+
+ def cmd_help ( self, *ignored ):
+ self.stdout ( "commands: {}\n".format (
+ ', '.join ( self.cmd_table.keys() )
+ ) )
+ self.stdout ( "exit-commands: {}\n".format (
+ ', '.join ( self.cmd_exit )
+ ) )
+ # --- end of cmd_help (...) ---
+
+ def cmd_resolve ( self, dep_list, line ):
+ if not dep_list:
+ self.stdout ( "Resolve what?\n" )
+ else:
+ channel = EbuildJobChannel ( err_queue=None, name="channel" )
+ self.resolver.register_channel ( channel )
+
+ self.stdout ( "Trying to resolve {!r}.\n".format ( dep_list ) )
+
+ channel.add_dependencies ( dep_list )
+ deps = channel.satisfy_request (
+ close_if_unresolvable=False,
+ preserve_order=True
+ )
+ channel.close()
+
+ if deps is None:
+ self.stdout (
+ 'Channel returned {!r}. '
+ 'At least one dep couldn\'t be resolved.\n'.format ( deps )
+ )
+ else:
+ self.stdout ( "Resolved as: {!r}\n".format ( deps ) )
+ # --- end of cmd_resolve (...) ---
+
+ def _cmd_set_or_unset ( self, argv, is_set ):
+ if not argv:
+ self.stdout ( "shlex mode is {}.\n".format (
+ "on" if self.shlex_active else "off"
+ ) )
+ elif argv [0] == 'shlex':
+ self.shlex_active = is_set
+ elif argv [0].lower() == "ps1":
+ if is_set:
+ self.PS1 = argv [1] + ' '
+ else:
+ self.PS1 = "cmd % "
+ else:
+ self.stdout ( "unknown args: {}.\n".format ( argv ) )
+ # --- end of _cmd_set_or_unset (...) ---
+
+ def cmd_set ( self, argv, line ):
+ self._cmd_set_or_unset ( argv, True )
+ # --- end of cmd_set (...) ---
+
+ def cmd_unset ( self, argv, line ):
+ self._cmd_set_or_unset ( argv, False )
+ # --- end of cmd_unset (...) ---
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/depres/simpledeprule/
@ 2012-08-01 21:10 André Erdmann
0 siblings, 0 replies; 19+ messages in thread
From: André Erdmann @ 2012-08-01 21:10 UTC (permalink / raw
To: gentoo-commits
commit: db13e3750a908c150432250f8326427afdf03d61
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Wed Aug 1 21:10:46 2012 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Wed Aug 1 21:10:46 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=db13e375
resolve selfdeps with dots in their names
---
roverlay/depres/simpledeprule/abstractrules.py | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/roverlay/depres/simpledeprule/abstractrules.py b/roverlay/depres/simpledeprule/abstractrules.py
index e4aa7b2..18dc4b7 100644
--- a/roverlay/depres/simpledeprule/abstractrules.py
+++ b/roverlay/depres/simpledeprule/abstractrules.py
@@ -32,6 +32,12 @@ class SimpleRule ( deprule.DependencyRule ):
if not dep_str is None:
self.dep_alias.append ( dep_str )
+ if self.is_selfdep and dep_str is not None:
+ # add the actual package name (replace '_' by '.') to self.dep_alias
+ actual_name = dep_str.replace ( '_', '.' )
+ if actual_name != dep_str:
+ self.dep_alias.append ( dep_str )
+
# --- end of __init__ (...) ---
def done_reading ( self ):
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/depres/simpledeprule/
@ 2012-08-02 15:14 André Erdmann
0 siblings, 0 replies; 19+ messages in thread
From: André Erdmann @ 2012-08-02 15:14 UTC (permalink / raw
To: gentoo-commits
commit: fa61ced324300bf42436828200f8d532ab44fc13
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Thu Aug 2 15:01:11 2012 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Thu Aug 2 15:01:11 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=fa61ced3
call read_file(), not _read_file()
---
roverlay/depres/simpledeprule/reader.py | 12 ++++++++++--
1 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/roverlay/depres/simpledeprule/reader.py b/roverlay/depres/simpledeprule/reader.py
index edc04b0..3094d9c 100644
--- a/roverlay/depres/simpledeprule/reader.py
+++ b/roverlay/depres/simpledeprule/reader.py
@@ -34,8 +34,16 @@ class SimpleDependencyRuleReader ( object ):
# --- end of __init__ (...) ---
def read ( self, files_or_dirs ):
+ """Reads dependency rules from files or directories, in which case
+ all files from a dir are read.
+
+ arguments:
+ * files_or_dirs --
+ """
if self._pool_add is None:
- raise AssertionError ( "Resolver, but pool_add is None." )
+ raise AssertionError (
+ "Read method is for resolver, but pool_add is None."
+ )
for k in files_or_dirs:
if os.path.isdir ( k ):
@@ -45,7 +53,7 @@ class SimpleDependencyRuleReader ( object ):
if os.path.isfile ( f ):
self.read_file ( f )
else:
- self._read_file ( k )
+ self.read_file ( k )
rule_count, pools = self._rmaker.done ( as_pool=True )
self.logger.debug ( "Read {} rules in {} files.".format (
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/depres/simpledeprule/
@ 2012-08-13 16:34 André Erdmann
0 siblings, 0 replies; 19+ messages in thread
From: André Erdmann @ 2012-08-13 16:34 UTC (permalink / raw
To: gentoo-commits
commit: a91b4e8c6e67a0772a323206f0ed51a4321f4378
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Mon Aug 13 16:31:38 2012 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Mon Aug 13 16:31:38 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=a91b4e8c
depres console: help/usage messages
---
roverlay/depres/simpledeprule/console.py | 442 +++++++++++++++++++++++-------
1 files changed, 344 insertions(+), 98 deletions(-)
diff --git a/roverlay/depres/simpledeprule/console.py b/roverlay/depres/simpledeprule/console.py
index 9428875..0572850 100644
--- a/roverlay/depres/simpledeprule/console.py
+++ b/roverlay/depres/simpledeprule/console.py
@@ -8,6 +8,9 @@
This module provides console access to a (self-managed) dependency resolver
and is meant for testing.
+
+Furthermore, its commands can be given through a stdin-pipe:
+echo -e 'lc\n? <dep str>\n? <dep str2>' | roverlay depres
"""
__all__ = [ 'DepResConsole', ]
@@ -17,21 +20,25 @@ import sys
import shlex
import logging
-from roverlay import config, strutil
+from roverlay import config, strutil
from roverlay.errorqueue import ErrorQueue
from roverlay.depres import deptype
from roverlay.depres.depresolver import DependencyResolver
from roverlay.depres.channels import EbuildJobChannel
+from roverlay.depres.simpledeprule import rules
from roverlay.depres.simpledeprule.pool import SimpleDependencyRulePool
from roverlay.depres.simpledeprule.rulemaker import SimpleRuleMaker
-from roverlay.depres.simpledeprule import rules
class PackageDirRuleMaker ( object ):
"""Scans a distdir and creates selfdep rules for it.
- Part of the console module 'cause only used here (currently).
+ Part of the console module 'cause only used here. The overlay package
+ has its own implementation that automatically uses all added packages
+ for resolving dependencies.
"""
-
def __init__ ( self, fuzzy=True ):
+ """Initializes a PackageDirRuleMaker that will create fuzzy rules if
+ 'fuzzy' is True, else normal ones.
+ """
self.fuzzy = fuzzy
self.package_regex = re.compile (
"^(?P<name>[^_]+)_.+{}$".format (
@@ -41,8 +48,12 @@ class PackageDirRuleMaker ( object ):
# --- end of __init__ (...) ---
def _scan ( self, distdir ):
- # ~duplicate of remote/basicrepo
+ """
+ Traverses through a distdir and yields the names of found R packages.
+ arguments:
+ * distdir --
+ """
for dirpath, dirnames, filenames in os.walk ( distdir ):
for filename in filenames:
m = self.package_regex.match ( filename )
@@ -51,6 +62,12 @@ class PackageDirRuleMaker ( object ):
# --- end of _scan (...) ---
def make_rules ( self, distdir ):
+ """Consecutively creates and yields dependency rules for R packages
+ found in the given distdir.
+
+ arguments:
+ * distdir --
+ """
cat = config.get_or_fail ( 'OVERLAY.category' ) + '/'
if self.fuzzy:
for dep in self._scan ( distdir ):
@@ -74,61 +91,272 @@ class DepResConsole ( object ):
# saving functions calls, ...
# It's assumed that the user is still slower ;)
- shlex = shlex.shlex()
+ shlex = shlex.shlex()
whitespace = re.compile ( "\s+" )
+ # the command usage dict
+ CMD_USAGE = {
+ 'add_pool' : """
+ Creates a new pool on top of any existing ones.
+
+ Arguments: None (ignored)
+
+ Usage:
+ * add_pool|<<
+ """,
+ 'addrule' : """
+ Creates a new dependency rule and adds it to the current rule pool.
+ The console supports single-line rules only at this time.
+
+ Arguments: a list of quoted rule strings if shlex mode is active,
+ else one rule string
+
+ Usage:
+ * +|addrule <rule>
+ * +|addrule "<rule>" ["<rule>"]*
+
+ """,
+ 'help' : """
+ Prints a general help message, a list of all help topics if --list\\
+ is given, or a specific help message for the given command.
+
+ Arguments: None, '--list', or a command
+
+ Usage:
+ * help
+ * help --list
+ * help <command>
+ """,
+ 'load' : """
+ Loads a rule file or directory into a new dependency rule pool.
+
+ Arguments: a file
+
+ Usage:
+ * load|li|l <file|dir>
+ """,
+ 'load_conf' : """
+ Loads the rule files listed in the config file.
+
+ Arguments: None (ignored)
+
+ Usage:
+ * load_conf|lc
+ """,
+ 'mkhelp' : """
+ Verifies that all usable commands have a help message.
+
+ Arguments: None (ignored)
+
+ Usage:
+ * mkhelp
+ """,
+ 'print': """
+ Prints the content of the current pool or all pools.
+
+ Arguments: 'all' (=> print all pools)
+
+ Usage:
+ * print
+ * print all
+ """,
+ 'resolve': """
+ Resolves one or more dependency strings.
+
+ Arguments: a list of quoted dependency strings if shlex mode is\\
+ active, else one dependency string.
+
+ Usage:
+ * resolve|r|? <dependency string>
+ * resolve|r|? "<dependency string>" ["<dependency string>"]*
+ """,
+ 'scandir' : """
+ Scans a directory for R packages and creates dependency rules\\
+ for them.
+
+ Arguments: a directory
+
+ Usage:
+ * scandir|sd <directory>
+ """,
+ 'set' : """
+ Set or unset modes. Prints all modes and their state when called\\
+ with no args.
+ Currently, the only available mode is 'shlex' which enables/disables\\
+ shell-like argument parsing.\\
+ Shlex mode allows to specify more than one arg when running certain
+ commands, but requires args to be enclosed with quotes.
+
+ Arguments: None or a mode
+
+ Usage:
+ * set
+ * unset
+ * set <mode>
+ * unset <mode>
+ """,
+ 'unwind' : """
+ Removes the top-most (latest) dependency rule pool and all of its\\
+ rules.
+
+ Arguments: None (ignored)
+
+ Usage:
+ * unwind|>>
+ """,
+ 'write' : """
+ Writes the rules of the top-most (latest) dependency rule pool to\\
+ a file that later be loaded.
+
+ Arguments: file to write
+
+ Usage:
+ * write|w <file>
+ """,
+ 'cd' : """
+ Changes the working directory to the given one. Also creates it\\
+ if necessary.
+
+ Arguments: a directory
+
+ Usage:
+ * cd <directory>
+ """,
+ }
+
+ CMD_USAGE_REDIRECT = {
+ 'r' : 'resolve',
+ '?' : 'resolve',
+ 'sd' : 'scandir',
+ '+' : 'addrule',
+ 'li' : 'load',
+ 'l' : 'load',
+ 'lc' : 'load_conf',
+ 'w' : 'write',
+ 'p' : 'print',
+ '>>' : 'unwind',
+ '<<' : 'add_pool',
+ 'unset' : 'set',
+ 'h' : 'help',
+ }
+
+ def _create_command_table ( self ):
+ # the command table
+ # each command string is mapped to a function/method
+ self.cmd_table = {
+ 'resolve' : self.cmd_resolve,
+ 'scandir' : self.cmd_rule_scandir,
+ 'addrule' : self.cmd_rule_add,
+ 'load' : self.cmd_rule_load,
+ 'load_conf' : self.cmd_rule_load_from_config,
+ 'write' : self.cmd_pool_write,
+ 'print' : self.cmd_pool_print,
+ 'unwind' : self.cmd_pool_unwind,
+ 'add_pool' : self.cmd_pool_add,
+ 'cd' : self.cmd_cd,
+ 'set' : self.cmd_set,
+ 'unset' : self.cmd_unset,
+ 'help' : self.cmd_help,
+ 'mkhelp' : self.cmd_mkhelp,
+ }
+
+ for alias, real in self.__class__.CMD_USAGE_REDIRECT.items():
+ self.cmd_table [alias] = self.cmd_table [real]
+ # --- end of _create_command_table (...) ---
+
+ def _get_usage ( self, func_name ):
+ """Returns the usage string for the given function (by name).
+
+ arguments:
+ * func_name
+ """
+ if func_name in self.__class__.CMD_USAGE_REDIRECT:
+ fname = self.__class__.CMD_USAGE_REDIRECT [func_name]
+ else:
+ fname = func_name
+
+ if fname not in self._usage_dict:
+ lines = list()
+ for line in self.__class__.CMD_USAGE [fname].split ( '\n' ):
+ line = line.strip()
+ if len ( line ) or len ( lines ):
+ lines.append ( line )
+
+ if len ( lines ) and not len ( lines [-1] ):
+ lines.pop()
+
+ self._usage_dict [fname] = '\n'.join ( lines ).replace ( '\\\n', ' ' )
+
+ return self._usage_dict [fname]
+ # --- end of _get_usage (...) ---
+
+ def _print_usage ( self, func_name ):
+ """Prints a usage message for the given function (by name)."""
+ print (
+ "command {!r}, usage:\n".format ( func_name ) + \
+ self._get_usage ( func_name )
+ )
+ # --- end of _print_usage (...) ---
+
+ def usage ( self ):
+ """Prints a usage message for the command currently running and
+ returns False."""
+ self._print_usage ( self._current_command )
+ return False
+ # --- end of usage (...) ---
+
def __init__ ( self ):
+ """Initializes a dependency resolution console."""
self.err_queue = ErrorQueue()
+ # set up the resolver
self.resolver = DependencyResolver ( err_queue=self.err_queue )
# log everything
self.resolver.set_logmask ( -1 )
# disable passing events to listeners
self.resolver.set_listenermask ( 0 )
+ # dependency rule pools (a set of rules) are organized in a FIFO
+ # structure that allows to create and delete new pools at runtime
self.poolstack = self.resolver.static_rule_pools
self.pool_id = 0
- self._rule_maker = SimpleRuleMaker()
+ # this rule maker is used to convert input (strings) into dependency
+ # rules
+ self._rule_maker = SimpleRuleMaker()
+
+ # this rule maker is used to create rules for R packages found in
+ # directories
self._dir_rule_maker = PackageDirRuleMaker()
+ # used for relative file paths (rule file writing,...)
self._cwd = None
+ # shlex mode:
+ # if True: split command args using shell syntax
+ # else : treat command args as one arg
+
+ # e.g. 'resolve zoo >= 5',
+ # => command is 'resolve'
+ # => args:
+ # shlex: [ 'zoo', '>=' , '5', ]
+ # no-shlex: [ 'zoo >= 5', ]
self.shlex_active = False
+ # each command line is prefixed by this string
self.PS1 = "cmd % "
+ # output streams
self.stdout = sys.stdout.write
self.stderr = sys.stderr.write
- self.cmd_table = {
- 'resolve' : self.cmd_resolve,
- 'r' : self.cmd_resolve,
- '?' : self.cmd_resolve,
- 'scandir' : self.cmd_rule_scandir,
- 'sd' : self.cmd_rule_scandir,
- 'addrule' : self.cmd_rule_add,
- '+' : self.cmd_rule_add,
- 'load' : self.cmd_rule_load,
- 'li' : self.cmd_rule_load,
- 'l' : self.cmd_rule_load,
- 'load_conf' : self.cmd_rule_load_from_config,
- 'lc' : self.cmd_rule_load_from_config,
- 'pool' : self.cmd_pool,
- 'write' : self.cmd_pool_write,
- 'w' : self.cmd_pool_write,
- 'p' : self.cmd_pool_print,
- 'print' : self.cmd_pool_print,
- 'unwind' : self.cmd_pool_unwind,
- '>>' : self.cmd_pool_unwind,
- 'add_pool' : self.cmd_pool_add,
- '<<' : self.cmd_pool_add,
- 'cd' : self.cmd_cd,
- 'set' : self.cmd_set,
- 'unset' : self.cmd_unset,
- 'help' : self.cmd_help,
- }
+ self._create_command_table()
+
+ self._usage_dict = dict()
+ self._current_command = None
+ # the command table of exit commands
+ # each listed command can be used to exit the depres console
self.cmd_exit = frozenset (( 'q', 'qq', 'exit' ))
if sys.version_info < ( 3, 0 ):
@@ -138,6 +366,12 @@ class DepResConsole ( object ):
# --- end of __init__ (...) ---
def _getpool ( self, new=False ):
+ """Returns a dependency rule pool. Creates a new one if no pool exists
+ or 'new' is set to True.
+
+ arguments:
+ * new -- defaults to True
+ """
if not self.poolstack or ( new and not self.poolstack [-1].empty() ):
pool = SimpleDependencyRulePool (
"pool" + str ( self.pool_id ),
@@ -150,37 +384,56 @@ class DepResConsole ( object ):
return self.poolstack [-1]
# --- end of _getpool (...) ---
- def cmd_cd ( self, argv, line ):
- if not argv:
- self.stdout (
- "usage is cd <dir>, dir will be created if not existent.\n"
+ def cmd_mkhelp ( self, argv, line ):
+ missing = list()
+ for cmd in self.cmd_table:
+ try:
+ self._get_usage ( cmd )
+ except KeyError:
+ missing.append ( cmd )
+
+ if missing:
+ print (
+ "Please write help messages for the following commands: " + \
+ ', '.join ( sorted ( missing ) )
)
return False
else:
- self._cwd = os.path.abspath ( argv [0] )
+ print ( "Everything looks ok." )
+ return True
+ # --- end of cmd_mkhelp (...) ---
+
+ def cmd_cd ( self, argv, line ):
+ if argv:
+ self._cwd = os.path.abspath ( os.path.expanduser ( argv [0] ) )
if not os.path.isdir ( self._cwd ):
os.makedirs ( self._cwd )
self.stdout ( "cwd = {!r}\n".format ( self._cwd ) )
return True
+ else:
+ return self.usage()
# --- end of cmd_cd (...) ---
- def cmd_rule_scandir ( self, argv, *ignored ):
- if not argv:
- self.stdout ( "usage is scandir <dir>\n" )
- return False
- elif not os.path.isdir ( argv[0] ):
- self.stderr ( "arg0 is not a dir\n" )
- return False
+ def cmd_rule_scandir ( self, argv, line ):
+ """Scans a directory for R packages and creates rules for them.
+
+ Usage: scandir <directory>
+ """
+ if argv and os.path.isdir ( argv[0] ):
+ pool = self._getpool ( new=True )
+ self.stdout ( "new rules:\n" )
+ for r in self._dir_rule_maker.make_rules ( argv [0] ):
+ self.stdout ( str ( r ) + "\n" )
+ pool.add ( r )
+ self.stdout ( "--- ---\n" )
+ pool.sort()
- pool = self._getpool ( new=True )
- self.stdout ( "new rules:\n" )
- for r in self._dir_rule_maker.make_rules ( argv [0] ):
- self.stdout ( str ( r ) + "\n" )
- pool.add ( r )
- self.stdout ( "--- ---\n" )
- pool.sort()
+ else:
+ self.stderr ( "arg0 is not a dir\n" )
+ return self.usage()
+ # --- end of cmd_rule_scandir (...) ---
- def cmd_rule_load_from_config ( self, *ignored ):
+ def cmd_rule_load_from_config ( self, argv, line ):
load = config.get_or_fail ( "DEPRES.simple_rules.files" )
self.resolver.get_reader().read ( load )
# don't write into ^this pool
@@ -191,15 +444,15 @@ class DepResConsole ( object ):
if argv:
self.resolver.get_reader().read ( argv )
else:
- self.stdout ( "usage is load/li <files or dirs>\n" )
+ return self.usage()
# --- end of cmd_rule_load (...) ---
def cmd_rule_add ( self, argv, line ):
if not line:
- self.stdout ( "usage is <cmd> <rule>\n" )
+ return self.usage()
elif self._rule_maker.add ( line ):
rules = self._rule_maker.done()
- pool = self._getpool()
+ pool = self._getpool()
self.stdout ( "new rules:\n" )
for _deptype, r in rules:
@@ -216,11 +469,7 @@ class DepResConsole ( object ):
return False
# --- end of cmd_addrule (...) ---
- def cmd_pool_help ( self, *ignore ):
- self.stdout ( "<todo>\n" )
- # --- end of cmd_pool_help (...) ---
-
- def cmd_pool_print ( self, argv, *ignore ):
+ def cmd_pool_print ( self, argv, line ):
if argv and len ( argv ) > 0:
if argv[0] == "all":
_last = len ( self.poolstack )
@@ -231,35 +480,15 @@ class DepResConsole ( object ):
p.export_rules ( sys.stdout )
else:
self.stdout ( "unknown arg1 {!r}.\n".format ( argv[0] ) )
- return False
+ return self.usage()
else:
if len ( self.poolstack ):
self.poolstack [-1].export_rules ( sys.stdout )
# --- end of cmd_pool_print (...) ---
- def cmd_pool ( self, argv, line ):
- if not argv:
- self.stdout ( "usage: pool <action> [args]\n" )
- return self.cmd_pool_help()
-
- cmd = argv[0]
-
- if cmd == "unwind" or cmd == "destroy":
- return self.cmd_pool_unwind ( argv, line )
- elif cmd == "add" or cmd == "create":
- return self.cmd_pool_add ( argv, line )
- elif cmd == "print" or cmd == "show":
- if len ( argv ) > 1:
- return self.cmd_pool_print ( argv[1:] )
- else:
- return self.cmd_pool_print ( None )
-
- # --- end of cmd_pool (...) ---
-
- def cmd_pool_write ( self, argv, *ignore ):
+ def cmd_pool_write ( self, argv, line ):
if not argv:
- self.stdout ( "usage: write <file>\n" )
- return False
+ return self.usage()
if argv[0][0] == os.sep:
f = argv [0]
@@ -285,9 +514,10 @@ class DepResConsole ( object ):
else:
self.stdout ( "no pool in use.\n" )
return False
+ # --- end of cmd_pool_write (...) ---
- def cmd_pool_unwind ( self, *ignore ):
+ def cmd_pool_unwind ( self, argv, line ):
if self.poolstack:
self.poolstack.pop()
self.stdout ( "Pool removed from resolver.\n" )
@@ -295,7 +525,7 @@ class DepResConsole ( object ):
self.stdout ( "Resolver has no pools.\n" )
# --- end of cmd_pool_unwind (...) ---
- def cmd_pool_add ( self, *ignore ):
+ def cmd_pool_add ( self, argv, line ):
self._getpool ( new=True )
self.stdout ( "New pool created.\n" )
# --- end of cmd_pool_add (...) ---
@@ -305,8 +535,10 @@ class DepResConsole ( object ):
self.stdout (
'== depres console ==\n'
- 'run \'help\' to list all known commands\n'
- 'use \'load_conf\' or \'lc\' to load the configured rule files\n'
+ 'Run \'help\' to list all known commands\n'
+ 'More specifically, \'help <cmd>\' prints a help message for the '
+ 'given command, and \'help --list\' lists all help topics available\n'
+ 'Use \'load_conf\' or \'lc\' to load the configured rule files\n'
)
if self.shlex_active:
self.stdout (
@@ -329,7 +561,8 @@ class DepResConsole ( object ):
elif cmd in self.cmd_exit:
break
elif cmd in self.cmd_table:
- ret = self.cmd_table [cmd] ( argv, line )
+ self._current_command = cmd
+ ret = self.cmd_table [cmd] ( argv=argv, line=line )
if ret is True:
self.stdout ( "command succeeded.\n" )
elif ret is False:
@@ -367,18 +600,30 @@ class DepResConsole ( object ):
return ( linev [0].lower(), ( linev [1], ), linev [1] )
# --- end of split_line (...) ---
- def cmd_help ( self, *ignored ):
- self.stdout ( "commands: {}\n".format (
- ', '.join ( self.cmd_table.keys() )
- ) )
- self.stdout ( "exit-commands: {}\n".format (
- ', '.join ( self.cmd_exit )
- ) )
+ def cmd_help ( self, argv=None, *ignored, **kwargs_ignored ):
+ if argv:
+ if argv [0] == '--list':
+ print (
+ "The following help topics are available: " + \
+ ', '.join ( self.__class__.CMD_USAGE ) + "."
+ )
+ else:
+ for cmd in argv:
+ self._print_usage ( cmd )
+ else:
+ self.stdout ( "commands: {}\n".format (
+ ', '.join ( self.cmd_table.keys() )
+ ) )
+ self.stdout ( "exit-commands: {}\n".format (
+ ', '.join ( self.cmd_exit )
+ ) )
# --- end of cmd_help (...) ---
- def cmd_resolve ( self, dep_list, line ):
+ def cmd_resolve ( self, argv, line ):
+ dep_list = argv
if not dep_list:
self.stdout ( "Resolve what?\n" )
+ return self.usage()
else:
channel = EbuildJobChannel (
err_queue=self.err_queue, name="channel"
@@ -417,6 +662,7 @@ class DepResConsole ( object ):
self.PS1 = "cmd % "
else:
self.stdout ( "unknown args: {}.\n".format ( argv ) )
+ return self.usage()
# --- end of _cmd_set_or_unset (...) ---
def cmd_set ( self, argv, line ):
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/depres/simpledeprule/
@ 2013-06-04 21:06 André Erdmann
0 siblings, 0 replies; 19+ messages in thread
From: André Erdmann @ 2013-06-04 21:06 UTC (permalink / raw
To: gentoo-commits
commit: 0286a16de9137711d1d68649308e07d92d0a9e9c
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Tue May 14 13:24:58 2013 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Tue May 14 13:24:58 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=0286a16d
fix AttributeError in depres/simpledeprule
iter(<iterable>).next() does not work.
---
roverlay/depres/simpledeprule/abstractrules.py | 2 +-
roverlay/depres/simpledeprule/rules.py | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/roverlay/depres/simpledeprule/abstractrules.py b/roverlay/depres/simpledeprule/abstractrules.py
index bc4bab2..b622e56 100644
--- a/roverlay/depres/simpledeprule/abstractrules.py
+++ b/roverlay/depres/simpledeprule/abstractrules.py
@@ -120,7 +120,7 @@ class SimpleRule ( deprule.DependencyRule ):
pass
elif len ( self.dep_alias ) == 1:
- yield "{} :: {}".format ( resolving, iter ( self.dep_alias ).next() )
+ yield "{} :: {}".format ( resolving, next ( iter ( self.dep_alias ) ) )
else:
yield resolving + ' {'
diff --git a/roverlay/depres/simpledeprule/rules.py b/roverlay/depres/simpledeprule/rules.py
index 966d3d1..a5d65e3 100644
--- a/roverlay/depres/simpledeprule/rules.py
+++ b/roverlay/depres/simpledeprule/rules.py
@@ -48,7 +48,7 @@ class SimpleIgnoreDependencyRule ( SimpleRule ):
def __str__ ( self ):
if self.is_selfdep:
- return self.__class__.RULE_PREFIX + iter ( self.dep_alias ).next()
+ return self.__class__.RULE_PREFIX + next ( iter ( self.dep_alias ) )
else:
return super ( self.__class__, self ) . __str__()
@@ -86,7 +86,7 @@ class SimpleFuzzyIgnoreDependencyRule ( FuzzySimpleRule ):
def __str__ ( self ):
if self.is_selfdep:
- return self.__class__.RULE_PREFIX + iter ( self.dep_alias ).next()
+ return self.__class__.RULE_PREFIX + next ( iter ( self.dep_alias ) )
else:
return super ( self.__class__, self ) . __str__()
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/depres/simpledeprule/
2013-06-05 18:08 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
@ 2013-06-13 16:34 ` André Erdmann
0 siblings, 0 replies; 19+ messages in thread
From: André Erdmann @ 2013-06-13 16:34 UTC (permalink / raw
To: gentoo-commits
commit: 9fa3b9afb66e6d2c7ae4ac902fe6abb613949c91
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Wed Jun 5 17:59:42 2013 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Wed Jun 5 17:59:42 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=9fa3b9af
dynamic selfdep pool: dont add rule kwargs
---
roverlay/depres/simpledeprule/dynpool.py | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/roverlay/depres/simpledeprule/dynpool.py b/roverlay/depres/simpledeprule/dynpool.py
index b1d008d..8b6cf20 100644
--- a/roverlay/depres/simpledeprule/dynpool.py
+++ b/roverlay/depres/simpledeprule/dynpool.py
@@ -46,8 +46,7 @@ class DynamicSelfdepRulePool ( SimpleDependencyRulePool ):
def reload ( self ):
self.rules = list (
- self._rule_class ( is_selfdep=True, **kwargs ) \
- for kwargs in self._rule_kw_function()
+ self._rule_class ( **kwargs ) for kwargs in self._rule_kw_function()
)
# --- end of reload (...) ---
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/depres/simpledeprule/
@ 2013-07-03 10:05 André Erdmann
0 siblings, 0 replies; 19+ messages in thread
From: André Erdmann @ 2013-07-03 10:05 UTC (permalink / raw
To: gentoo-commits
commit: 56508c012746facf81dc62926dc86646f5b04a60
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Fri Jun 28 17:14:23 2013 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Fri Jun 28 17:14:23 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=56508c01
roverlay/depres: SLOT handling fixup (part 1)
(rule file-)syntax fixup for fuzzy slot dep rules.
This feature still needs some work.
---
roverlay/depres/simpledeprule/abstractrules.py | 38 +++--
roverlay/depres/simpledeprule/rules.py | 204 ++++++++++++++++++-------
2 files changed, 175 insertions(+), 67 deletions(-)
diff --git a/roverlay/depres/simpledeprule/abstractrules.py b/roverlay/depres/simpledeprule/abstractrules.py
index 85c365d..0713c81 100644
--- a/roverlay/depres/simpledeprule/abstractrules.py
+++ b/roverlay/depres/simpledeprule/abstractrules.py
@@ -97,21 +97,32 @@ class SimpleRule ( deprule.DependencyRule ):
return None
# --- end of matches (...) ---
+ def noexport ( self ):
+ """Removes all variables from this object that are used for string
+ creation ("export_rule()") only.
+ """
+ pass
+ # --- end of noexport (...) ---
+
def export_rule ( self ):
"""Generates text lines for this rule that can later be read using
the SimpleDependencyRuleReader.
"""
- if self.resolving_package is None:
- resolving = ''
+ if hasattr ( self, 'get_resolving_str' ):
+ resolving = self.get_resolving_str()
else:
- resolving = self.resolving_package
+ if self.resolving_package is None:
+ resolving = ''
+ else:
+ resolving = self.resolving_package
- if self.is_selfdep:
- resolving = resolving.rpartition ( '/' ) [2]
+ if self.is_selfdep:
+ resolving = resolving.rpartition ( '/' ) [2]
- if hasattr ( self.__class__, 'RULE_PREFIX' ):
- resolving = self.__class__.RULE_PREFIX + resolving
+ if hasattr ( self.__class__, 'RULE_PREFIX' ):
+ resolving = self.__class__.RULE_PREFIX + resolving
+ # -- end if;
if self.is_selfdep:
yield resolving
@@ -178,15 +189,12 @@ class FuzzySimpleRule ( SimpleRule ):
# --- end of log_fuzzy_match (...) ---
def log_standard_match ( self, dep_env, score ):
- if dep is False:
- return None
- else:
- self.logger.debug (
- "matches {dep_str} with score {s} and priority {p}.".format (
- dep_str=dep_env.dep_str, s=score, p=self.priority
- )
+ self.logger.debug (
+ "matches {dep_str} with score {s} and priority {p}.".format (
+ dep_str=dep_env.dep_str, s=score, p=self.priority
)
- return ( score, self.resolving_package )
+ )
+ return ( score, self.resolving_package )
# --- end of log_standard_match (...) ---
def handle_version_relative_match ( self, dep_env, fuzzy ):
diff --git a/roverlay/depres/simpledeprule/rules.py b/roverlay/depres/simpledeprule/rules.py
index db208d4..ac3fa89 100644
--- a/roverlay/depres/simpledeprule/rules.py
+++ b/roverlay/depres/simpledeprule/rules.py
@@ -23,10 +23,90 @@ __all__ = (
from roverlay.depres.simpledeprule.abstractrules import \
SimpleRule, FuzzySimpleRule
+class SlotRestrict ( object ):
+ def accepts ( self, k ):
+ """Returns True if k is allowed, else False.
+
+ arguments:
+ * k -- int
+ """
+ return True
+
+ def __bool__ ( self ):
+ return True
+
+ def noexport ( self ):
+ pass
+
+ def __str__ ( self ):
+ return ':'
+# --- end of SlotRestrict ---
+
+class SlotRangeRestrict ( SlotRestrict ):
+ DEFAULT_LOW = 0
+ DEFAULT_HIGH = 1000
+
+ def __init__ ( self, low, high ):
+ super ( SlotRangeRestrict, self ).__init__()
+ if low:
+ self.low = int ( low )
+ else:
+ self.low = self.DEFAULT_LOW
+ self._implicit_low = True
+
+ if high:
+ self.high = int ( high )
+ else:
+ self.high = self.DEFAULT_HIGH
+ self._implicit_high = True
+ # --- end of __init__ (...) ---
+
+ def noexport ( self ):
+ if hasattr ( self, '_implicit_low' ):
+ del self._implicit_low
+ if hasattr ( self, '_implicit_high' ):
+ del self._implicit_high
+ # --- end of noexport (...) ---
+
+ def accepts ( self, k ):
+ """Returns True if k is allowed, else False.
+
+ arguments:
+ * k -- int
+ """
+ return k >= self.low and k <= self.high
+
+ def __str__ ( self ):
+ return ":{low}..{high}".format (
+ low = ( '' if hasattr ( self, '_implicit_low' ) else self.low ),
+ high = ( '' if hasattr ( self, '_implicit_high' ) else self.high ),
+ )
+ # --- end of __str__ (...) ---
+
+# --- end of SlotRangeRestrict ---
+
+class SlotSetRestrict ( SlotRestrict ):
+ def __init__ ( self, iterable ):
+ self._iset = frozenset ( int ( k ) for k in iterable )
+
+ def accepts ( self, k ):
+ """Returns True if k is allowed, else False.
+
+ arguments:
+ * k -- int
+ """
+ return k in self._iset
+
+ def __str__ ( self ):
+ return ':' + ','.join ( str ( k ) for k in sorted ( self._iset ) )
+ # --- end of __str__ (...) ---
+
+# --- end of SlotSetRestrict ---
+
class RuleConstructor ( object ):
def __init__ ( self, eapi ):
- self.eapi = eapi
+ ##self.eapi = eapi
self.kw_ignore = SimpleIgnoreDependencyRule.RULE_PREFIX
self.kw_fuzzy = SimpleFuzzyDependencyRule.RULE_PREFIX
@@ -42,58 +122,59 @@ class RuleConstructor ( object ):
elif kw == self.kw_fuzzy_ignore:
return ( SimpleFuzzyIgnoreDependencyRule, get_kwless(), {} )
elif kw == self.kw_fuzzy:
- ##TODO
- ## > "default"
- ## > "slot only"
- ## > "combined"
- ## syntax
- ## ~cat/pkg:<slot suffix>
- ## ~cat/pkg:/<slot suffix>
- ## ~cat/pkg:{major}/{minor}<slot suffix>
- ##
+ ## syntax
+ ## ~cat/pkg:<slot range>:<slot suffix>
kwless = get_kwless()
resolving, sepa, remainder = kwless.partition ( ':' )
if sepa:
# fuzzy slot rule
- kwargs = { 'resolving_package_name' : resolving, }
+ kwargs = dict()
slot_head, slot_sepa, slot_rem = remainder.partition ( ':' )
if slot_sepa:
- # slot restriction
+ # int range restriction
istart, isepa, istop = slot_head.partition ( '..' )
if isepa:
- kwargs ['slot_restrict'] = frozenset (
- range ( int ( istart or 0 ), int ( istop or 100 ) + 1 )
+ kwargs ['slot_restrict'] = SlotRangeRestrict (
+ low=istart, high=istop
)
else:
- kwargs ['slot_restrict'] = frozenset (
- int ( k ) for k in slot_head.split ( ',' )
+ # int list restriction
+
+ # "filter(None,...)" filters 0 but not '0'
+ istr_list = list (
+ filter ( None, slot_head.split ( ',' ) )
+ #filter ( lambda s : s or s == 0, slot_head.split ( ',' ) )
)
+ if istr_list:
+ kwargs ['slot_restrict'] = SlotSetRestrict ( istr_list )
+
remainder = slot_rem
else:
+ #kwargs ['slot_restrict'] = SlotRestrict()
remainder = slot_head
# -- end if;
+ if remainder[:2] == '+v':
+ kwargs ['with_version'] = True
+ remainder = remainder[2:]
+ # -- end if;
if not remainder:
- # <cat>/<pkg>:
- kwargs ['slot_suffix'] = sepa + '{slot}'
-
+ pass
elif remainder[0] in { '/', '*', '=' }:
# subslot, "any slot" operators
- assert self.eapi >= 5
- kwargs ['slot_suffix'] = sepa + '{slot}' + remainder
- else:
- kwargs ['slot_suffix'] = sepa + remainder
-
+ # (subslots don't seem to make much sense here)
- # verify that slot_suffix can be formatted properly
-## if kwargs ['slot_suffix'] [0] != ':':
-## kwargs ['slot_suffix'] = ':' + kwargs ['slot_suffix']
+ ##if self.eapi < 5: raise ...
+ kwargs ['slot_suffix'] = remainder
+ else:
+ raise Exception (
+ "unknown slot rule remainder {!r}".format ( remainder )
+ )
- DONT_CARE = kwargs ['slot_suffix'].format ( slot='_', version='_' )
return ( SimpleFuzzySlotDependencyRule, resolving, kwargs )
else:
return ( SimpleFuzzyDependencyRule, kwless, {} )
@@ -212,39 +293,55 @@ class SimpleFuzzySlotDependencyRule ( FuzzySimpleRule ):
RULE_PREFIX = SimpleFuzzyDependencyRule.RULE_PREFIX
def __init__ ( self,
- priority = 71,
- resolving_package = None,
- resolving_package_name = None,
- slot_suffix = None,
- slot_restrict = None,
+ priority = 71,
+ resolving_package = None,
+ slot_suffix = None,
+ slot_restrict = None,
+ with_version = False,
**kw
):
super ( SimpleFuzzySlotDependencyRule, self ) . __init__ (
priority=priority,
resolving_package = resolving_package,
- logger_name = 'FUZZY_SLOT.' + (
- resolving_package_name if resolving_package_name is not None
- else resolving_package.partition ( ':' )[0]
- ),
+ logger_name = 'FUZZY_SLOT.' + resolving_package,
**kw
)
- self.slot_suffix = slot_suffix
+ self.slot_suffix = slot_suffix
+ self.slot_restrict = slot_restrict
- if slot_restrict:
- self.slot_restrict = frozenset ( int ( k ) for k in slot_restrict )
+ if with_version:
+ self._resolving_fmt = (
+ '{vmod}' + self.resolving_package + '-{version}:{slot}'
+ + ( slot_suffix or '' )
+ )
+ self.with_version = True
else:
- self.slot_restrict = None
+ self._resolving_fmt = (
+ self.resolving_package + ':{slot}' + ( slot_suffix or '' )
+ )
+ self.with_version = False
+
+ if self.is_selfdep:
+ raise NotImplementedError ( "fuzzy slot rule must not be a selfdep." )
# --- end of __init__ (...) ---
- def __str__ ( self ):
- # FIXME/TODO
- return 'TODO! {low}..{high} {s}'.format (
- low = ( min ( self.slot_restrict ) if self.slot_restrict else 'X' ),
- high = ( max ( self.slot_restrict ) if self.slot_restrict else 'X' ),
- s = ( super ( SimpleFuzzySlotDependencyRule, self ).__str__() ),
+ def noexport ( self ):
+ del self.slot_suffix
+ del self.with_version
+ if self.slot_restrict:
+ self.slot_restrict.noexport()
+ # --- end of noexport (...) ---
+
+ def get_resolving_str ( self ):
+ return "{prefix}{resolv}{restrict}:{flags}{slot}".format (
+ prefix = self.RULE_PREFIX,
+ resolv = self.resolving_package,
+ restrict = ( self.slot_restrict or '' ),
+ flags = ( '+v' if self.with_version else '' ),
+ slot = ( self.slot_suffix or '' ),
)
- # --- end of __str__ (...) ---
+ # --- end of get_resolving_str (...) ---
def handle_version_relative_match ( self, dep_env, fuzzy ):
res = False
@@ -256,6 +353,8 @@ class SimpleFuzzySlotDependencyRule ( FuzzySimpleRule ):
ver_str = fuzzy ['version']
v_major, sepa, v_remainder = ver_str.partition ( '.' )
try:
+ # TODO/FIXME: slot != int(v_major);
+ # example: sci-libs/fftw where slots are K.J (2.1, 3.0)
slot = int ( v_major )
# resolve '<' and '>' by decrementing/incrementing slot
@@ -264,10 +363,11 @@ class SimpleFuzzySlotDependencyRule ( FuzzySimpleRule ):
elif vmod == dep_env.VMOD_GT:
slot += 1
- if not self.slot_restrict or slot in self.slot_restrict:
- res = self.resolving_package + self.slot_suffix.format (
- slot=slot, version=ver_str,
- #vmod=fuzzy ['version_modifier']
+ if not self.slot_restrict or self.slot_restrict.accepts ( slot ):
+ res = self._resolving_fmt.format (
+ slot=slot,
+ version=ver_str,
+ vmod=fuzzy ['version_modifier'],
)
except ValueError:
pass
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/depres/simpledeprule/
2013-07-03 10:04 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
@ 2013-07-03 10:05 ` André Erdmann
0 siblings, 0 replies; 19+ messages in thread
From: André Erdmann @ 2013-07-03 10:05 UTC (permalink / raw
To: gentoo-commits
commit: 6cb202e96bfd7e9e34bdc0abe64688595ab8142b
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Wed Jul 3 09:59:16 2013 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Wed Jul 3 10:03:57 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=6cb202e9
roverlay/depres: restrict calculated slot value
This commit changes the behavior when using slot restrictions.
A slot value is now accepted if the _calculated_ slot value (taken from the dep
strings version) is in the list of allowed values. This is only relevant for
rules that use "immediate" slot values.
---
roverlay/depres/simpledeprule/rules.py | 26 ++++++++++------------
roverlay/depres/simpledeprule/util.py | 40 +++++++++++++++++++++++-----------
2 files changed, 39 insertions(+), 27 deletions(-)
diff --git a/roverlay/depres/simpledeprule/rules.py b/roverlay/depres/simpledeprule/rules.py
index 999a8b4..dea5f38 100644
--- a/roverlay/depres/simpledeprule/rules.py
+++ b/roverlay/depres/simpledeprule/rules.py
@@ -308,15 +308,6 @@ class SimpleFuzzySlotDependencyRule ( FuzzySimpleRule ):
# --- end of noexport (...) ---
def get_resolving_str ( self ):
- ## syntax
- ## ~<cat>/<pkg>[:[<slot option>]]*
- ## where slot option is any of
- ## * slot restrict (range, list)
- ## * "with version", "open" ("*" and "=" slot operators)
- ## * relevant version parts ("1.2.3.4" => "1" if 1, "1.2" if 2, ...)
- ## * relevant subslot version parts ("1.2.3.4" => <SLOT>/<SUBSLOT?>)
- ## * slot operator ("=")
-
def gen_opts():
if self.mode == 2:
yield "open"
@@ -360,20 +351,27 @@ class SimpleFuzzySlotDependencyRule ( FuzzySimpleRule ):
if self.mode == 2:
res = self._resolving_str
elif vmod & dep_env.VMOD_EQ:
- slot_str = None
- slot = self.slotparts.get_slot ( fuzzy )
+ slot_str = None
+ vslot_str = None
+ slot = self.slotparts.get_slot ( fuzzy )
if slot is not None:
if self.subslotparts:
subslot = self.subslotparts.get_slot ( fuzzy )
if subslot is not None:
- slot_str = slot + '/' + subslot
+ slot_str = slot + '/' + subslot
+ vslot_str = (
+ self.slotparts.calculate_slot ( fuzzy, slot )
+ + '/'
+ + self.subslotparts.calculate_slot ( fuzzy, subslot )
+ )
else:
- slot_str = slot
+ vslot_str = self.slotparts.calculate_slot ( fuzzy, slot )
+ slot_str = slot
if slot_str and (
not self.slot_restrict
- or self.slot_restrict.accepts ( slot )
+ or self.slot_restrict.accepts ( vslot_str )
):
res = self._resolving_fmt.format (
slot=slot_str,
diff --git a/roverlay/depres/simpledeprule/util.py b/roverlay/depres/simpledeprule/util.py
index 0a8311c..0ce5aa4 100644
--- a/roverlay/depres/simpledeprule/util.py
+++ b/roverlay/depres/simpledeprule/util.py
@@ -68,6 +68,9 @@ class SlotSetRestrict ( SlotRestrict ):
class SlotValueCreatorBase ( object ):
+ def calculate_slot ( self, fuzzy, slot_value ):
+ return slot_value
+
def get_slot ( self, *args, **kwargs ):
raise NotImplementedError()
# --- end of get_slot (...) ---
@@ -77,19 +80,6 @@ class SlotValueCreatorBase ( object ):
# --- end of __str__ (...) ---
-class ImmediateSlotValueCreator ( SlotValueCreatorBase ):
- def __init__ ( self, v_str ):
- super ( ImmediateSlotValueCreator, self ).__init__()
- self._value = v_str
- # --- end of __init__ (...) ---
-
- def get_slot ( self, *args, **kwargs ):
- return self._value
- # --- end of get_slot (...) ---
-
- def __str__ ( self ):
- return "i" + self._value
-
class SingleIndexValueCreator ( SlotValueCreatorBase ):
def __init__ ( self, index ):
super ( SingleIndexValueCreator, self ).__init__()
@@ -129,6 +119,30 @@ class IndexRangeSlotValueCreator ( SlotValueCreatorBase ):
( self._high - 1 ) if self._high > 0 else self._high
)
+class ImmediateSlotValueCreator ( SlotValueCreatorBase ):
+ def __init__ ( self, v_str ):
+ super ( ImmediateSlotValueCreator, self ).__init__()
+ self._value = v_str
+ numparts = len ( v_str.split ( "." ) )
+ assert numparts > 0
+
+ if numparts < 2:
+ self._slot_calculator = SingleIndexValueCreator ( 0 )
+ else:
+ self._slot_calculator = IndexRangeSlotValueCreator ( 0, numparts-1 )
+ # --- end of __init__ (...) ---
+
+ def calculate_slot ( self, fuzzy, slot_value ):
+ cval = self._slot_calculator.get_slot ( fuzzy )
+ return slot_value if cval is None else cval
+ # --- end of calculate_slot (...) ---
+
+ def get_slot ( self, *args, **kwargs ):
+ return self._value
+ # --- end of get_slot (...) ---
+
+ def __str__ ( self ):
+ return "i" + self._value
def get_slot_parser ( vstr ):
if vstr [0] == 'i':
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/depres/simpledeprule/
2013-07-10 15:10 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
@ 2013-07-10 16:16 ` André Erdmann
0 siblings, 0 replies; 19+ messages in thread
From: André Erdmann @ 2013-07-10 16:16 UTC (permalink / raw
To: gentoo-commits
commit: 1c14f3a2bae0517890589572d90c5f07bdff6f85
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Wed Jul 10 13:29:27 2013 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Wed Jul 10 13:32:17 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=1c14f3a2
roverlay/depres/simpledeprule: use util.mapreader
* rulemaker: use common code provided by util.mapreader.MapfileParser
* reader: offload file reading/parsing to rulemaker, skip vcs directories when
scanning directories for rule files
---
roverlay/depres/simpledeprule/reader.py | 96 +++--------------------
roverlay/depres/simpledeprule/rulemaker.py | 120 +++++++++++++----------------
2 files changed, 61 insertions(+), 155 deletions(-)
diff --git a/roverlay/depres/simpledeprule/reader.py b/roverlay/depres/simpledeprule/reader.py
index d7edc48..e22877b 100644
--- a/roverlay/depres/simpledeprule/reader.py
+++ b/roverlay/depres/simpledeprule/reader.py
@@ -13,12 +13,9 @@ rules from a file.
__all__ = [ 'SimpleDependencyRuleReader', ]
import os
-import sys
import logging
-import gzip
-import bz2
-import mimetypes
+import roverlay.util
from roverlay.depres.simpledeprule.rulemaker import SimpleRuleMaker
@@ -29,19 +26,15 @@ class SimpleDependencyRuleReader ( object ):
""" A SimpleDependencyRuleReader reads such rules from a file."""
self.logger = logging.getLogger ( self.__class__.__name__ )
- # note that breakparse is reader-specific (not in SimpleRuleMaker)
- self.breakparse = set (( '#! NOPARSE', '#! BREAK' ))
-
self._rmaker = SimpleRuleMaker()
- self._mimetypes = mimetypes.MimeTypes()
- self.guess_ftype = self._mimetypes.guess_type
+ # bind read method of the rule maker
+ self.read_file = self._rmaker.read_file
self._pool_add = pool_add
self._when_done = when_done
self._fcount = 0
-
# --- end of __init__ (...) ---
def read ( self, files_or_dirs ):
@@ -58,11 +51,12 @@ class SimpleDependencyRuleReader ( object ):
for k in files_or_dirs:
if os.path.isdir ( k ):
- # without recursion
- for fname in os.listdir ( k ):
- f = k + os.sep + fname
- if os.path.isfile ( f ):
- self.read_file ( f )
+ if not roverlay.util.is_vcs_dir ( k ):
+ # without recursion
+ for fname in os.listdir ( k ):
+ f = k + os.sep + fname
+ if os.path.isfile ( f ):
+ self.read_file ( f )
else:
self.read_file ( k )
@@ -78,75 +72,3 @@ class SimpleDependencyRuleReader ( object ):
else:
return pools
# --- end of read (...) ---
-
- def read_file ( self, filepath ):
- """Reads a file that contains simple dependency rules
- (SimpleIgnoreDependencyRules/SimpleDependencyRules).
-
- arguments:
- * filepath -- file to read
- """
-
- # line number is used for logging
- lineno = 0
-
- self._fcount += 1
-
- try:
- self.logger.debug (
- "Reading simple dependency rule file {!r}.".format ( filepath )
- )
- ftype = self.guess_ftype ( filepath )
-
- compressed = True
-
- if ftype [1] == 'bzip2':
- fh = bz2.BZ2File ( filepath, mode='r' )
- elif ftype [1] == 'gzip':
- fh = gzip.GzipFile ( filepath, mode='r' )
- else:
- fh = open ( filepath, 'r' )
- compressed = False
-
-
- if compressed and sys.version_info >= ( 3, ):
- readlines = ( l.decode().strip() for l in fh.readlines() )
- else:
- readlines = ( l.strip() for l in fh.readlines() )
-
- for line in readlines:
- lineno += 1
-
- if not line:
- # empty (the rule maker catches this, too)
- pass
-
- elif line in self.breakparse:
- # stop reading here
- break
-
- elif not self._rmaker.add ( line ):
- self.logger.error (
- "In {!r}, line {}: cannot use this line.".format (
- filepath, lineno
- )
- )
-
- if fh: fh.close()
-
- except IOError as ioerr:
- if lineno:
- self.logger.error (
- "Failed to read file {!r} after {} lines.".format (
- filepath, lineno
- )
- )
- else:
- self.logger.error (
- "Could not read file {!r}.".format ( filepath )
- )
- raise
- finally:
- if 'fh' in locals() and fh: fh.close()
-
- # --- end of read_file (...) ---
diff --git a/roverlay/depres/simpledeprule/rulemaker.py b/roverlay/depres/simpledeprule/rulemaker.py
index ed39791..3f9ab73 100644
--- a/roverlay/depres/simpledeprule/rulemaker.py
+++ b/roverlay/depres/simpledeprule/rulemaker.py
@@ -15,6 +15,8 @@ __all__ = [ 'SimpleRuleMaker', ]
import re
import logging
+import roverlay.util.mapreader
+
from roverlay import config
from roverlay.depres import deptype
@@ -22,15 +24,14 @@ from roverlay.depres.simpledeprule import rules
from roverlay.depres.simpledeprule.abstractrules import *
from roverlay.depres.simpledeprule.pool import SimpleDependencyRulePool
-class SimpleRuleMaker ( object ):
+class SimpleRuleMaker ( roverlay.util.mapreader.MapFileParser ):
+
+ breakparse = set (( '! NOPARSE', '! BREAK' ))
def __init__ ( self, rule_separator=None ):
+ super ( SimpleRuleMaker, self ).__init__()
self.logger = logging.getLogger ( self.__class__.__name__ )
- self.single_line_separator = re.compile (
- '\s+::\s+' if rule_separator is None else rule_separator
- )
-
self.DEPTYPE_MAP = {
'all' : deptype.ALL,
'sys' : deptype.external,
@@ -38,9 +39,6 @@ class SimpleRuleMaker ( object ):
'selfdep' : deptype.selfdep,
}
- self.multiline_start = '{'
- self.multiline_stop = '}'
- self.comment_char = '#'
self.kw_selfdep_once = '@selfdep'
self._kwmap = rules.RuleConstructor (
eapi = config.get_or_fail ( 'EBUILD.eapi' )
@@ -49,37 +47,23 @@ class SimpleRuleMaker ( object ):
self.deptype_kw = 'deptype'
self._deptype = deptype.ALL
self._deptype_once = deptype.NONE
- self._next = None
- # [ ( deptype, rule ), ... ]
- self._rules = list()
# --- end of __init__ (...) ---
- def zap ( self ):
- if self._next is not None:
- self.logger.warning (
- "Multi line rule does not end at EOF - ignored"
- )
- self._next = None
- self._rules = list()
- # --- end of zap (...) ---
-
- def done ( self, as_pool=False ):
- rule_count = len ( self._rules )
+ def make_result ( self, as_pool=False ):
+ rule_count = len ( self._items )
if as_pool:
poolmap = dict()
- for dtype, rule in self._rules:
+ for dtype, rule in self._items:
if dtype not in poolmap:
poolmap [dtype] = SimpleDependencyRulePool (
name=str ( id ( self ) ),
deptype_mask=dtype
)
poolmap [dtype].add ( rule )
- ret = ( rule_count, tuple ( poolmap.values() ) )
+ return ( rule_count, tuple ( poolmap.values() ) )
else:
- ret = self._rules
- self.zap()
- return ret
- # --- end of done (...) ---
+ return self._items
+ # --- end of make_result (...) ---
def _parse_deptype ( self, deptype_str ):
ret = deptype.NONE
@@ -104,7 +88,7 @@ class SimpleRuleMaker ( object ):
return self._deptype
# --- end of _get_effective_deptype (...) ---
- def _single_line_rule ( self, dep, dep_str='' ):
+ def handle_entry_line ( self, dep, dep_str='' ):
# single line rule, either selfdep,
# e.g. '~zoo' -> fuzzy sci-R/zoo :: zoo
# or normal rule 'dev-lang/R :: R'
@@ -141,52 +125,52 @@ class SimpleRuleMaker ( object ):
return False
new_rule.done_reading()
- self._rules.append ( ( rule_deptype, new_rule ) )
+ self._items.append ( ( rule_deptype, new_rule ) )
return True
- # --- end of _single_line_rule (...) ---
+ # --- end of handle_entry_line (...) ---
- def add ( self, line ):
- if len ( line ) == 0:
- return True
- elif self._next is not None:
- if line [0] == self.multiline_stop:
- # end of a multiline rule,
- # add rule to rules and set next_rule to None
- self._next [1].done_reading()
- self._rules.append ( self._next )
- self._next = None
- else:
- # new resolved str
- self._next [1].add_resolved ( line )
+ def handle_multiline_begin ( self, line ):
+ rule_class, resolving, kwargs = self._kwmap.lookup ( line )
- return True
+ self._next = (
+ self._get_effective_deptype(),
+ rule_class ( resolving_package=resolving, **kwargs ),
+ )
+ return True
+ # --- end of handle_multiline_begin (...) ---
- elif line [0] == self.comment_char:
- if line [ 1 : 1 + len ( self.deptype_kw ) ] == self.deptype_kw :
- # changing deptype ("#deptype <type>")
- dtype_str = line [ len ( self.deptype_kw ) + 2 : ].lstrip().lower()
- self._deptype = self._parse_deptype ( dtype_str )
+ def handle_multiline_end ( self, line ):
+ self._next [1].done_reading()
+ self._items.append ( self._next )
+ self._next = None
+ return True
+ # --- end of handle_multiline_end (...) ---
- # else is a comment,
- # it's intented that multi line rules cannot contain comments
- return True
+ def handle_multiline_append ( self, line ):
+ self._next [1].add_resolved ( line )
+ return True
+ # --- end of handle_multiline_append (...) ---
- elif line == self.kw_selfdep_once:
- self._deptype_once = self._deptype | deptype.selfdep
- return True
+ def handle_comment_line ( self, line ):
+ if line[:len ( self.deptype_kw ) ] == self.deptype_kw:
+ # changing deptype ("#deptype <type>")
+ dtype_str = line.partition ( ' ' )[2].lower()
+ self._deptype = self._parse_deptype ( dtype_str )
- elif len ( line ) > 1 and line [-1] == self.multiline_start:
- l = line [:-1].rstrip()
- rule_class, resolving, kwargs = self._kwmap.lookup ( l )
+ elif line in self.breakparse:
+ self.stop_reading = True
- self._next = (
- self._get_effective_deptype(),
- rule_class ( resolving_package=resolving, **kwargs ),
- )
- return True
+ # else is a "real" comment
+ return True
+ # --- end of handle_comment_line (...) ---
+ def handle_option_line ( self, line ):
+ if line == self.kw_selfdep_once:
+ self._deptype_once = self._deptype | deptype.selfdep
+ return True
else:
- return self._single_line_rule (
- *self.single_line_separator.split ( line, 1 )
- )
- # --- end of add (...) ---
+ return False
+ # --- end of handle_option_line (...) ---
+
+
+# --- end of SimpleRuleMaker ---
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/depres/simpledeprule/
@ 2013-07-23 7:51 André Erdmann
0 siblings, 0 replies; 19+ messages in thread
From: André Erdmann @ 2013-07-23 7:51 UTC (permalink / raw
To: gentoo-commits
commit: 85ff4fac2f8260042d242da5f28fea2532520c03
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Fri Jul 19 17:40:51 2013 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Fri Jul 19 17:40:51 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=85ff4fac
remove old depres console
---
roverlay/depres/simpledeprule/console.py | 674 -------------------------------
1 file changed, 674 deletions(-)
diff --git a/roverlay/depres/simpledeprule/console.py b/roverlay/depres/simpledeprule/console.py
deleted file mode 100644
index a845d41..0000000
--- a/roverlay/depres/simpledeprule/console.py
+++ /dev/null
@@ -1,674 +0,0 @@
-# R overlay -- simple dependency rules, console
-# -*- coding: utf-8 -*-
-# Copyright (C) 2012 André Erdmann <dywi@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.
-
-"""dependency resolution console
-
-This module provides console access to a (self-managed) dependency resolver
-and is meant for testing.
-
-Furthermore, its commands can be given through a stdin-pipe:
-echo -e 'lc\n? <dep str>\n? <dep str2>' | roverlay depres
-"""
-__all__ = [ 'DepResConsole', ]
-
-import re
-import os
-import sys
-import shlex
-import logging
-
-from roverlay import config, strutil
-from roverlay.errorqueue import ErrorQueue
-from roverlay.depres import deptype
-from roverlay.depres.depresolver import DependencyResolver
-from roverlay.depres.channels import EbuildJobChannel
-from roverlay.depres.simpledeprule import rules
-from roverlay.depres.simpledeprule.pool import SimpleDependencyRulePool
-from roverlay.depres.simpledeprule.rulemaker import SimpleRuleMaker
-
-class PackageDirRuleMaker ( object ):
- """Scans a distdir and creates selfdep rules for it.
- Part of the console module 'cause only used here. The overlay package
- has its own implementation that automatically uses all added packages
- for resolving dependencies.
- """
- def __init__ ( self, fuzzy=True ):
- """Initializes a PackageDirRuleMaker that will create fuzzy rules if
- 'fuzzy' is True, else normal ones.
- """
- self.fuzzy = fuzzy
- self.package_regex = re.compile (
- "^(?P<name>[^_]+)_.+{}$".format (
- config.get_or_fail ( 'R_PACKAGE.suffix_regex' )
- )
- )
- # --- end of __init__ (...) ---
-
- def _scan ( self, distdir ):
- """
- Traverses through a distdir and yields the names of found R packages.
-
- arguments:
- * distdir --
- """
- for dirpath, dirnames, filenames in os.walk ( distdir ):
- for filename in filenames:
- m = self.package_regex.match ( filename )
- if m is not None:
- yield m.group ( 'name' )
- # --- end of _scan (...) ---
-
- def make_rules ( self, distdir ):
- """Consecutively creates and yields dependency rules for R packages
- found in the given distdir.
-
- arguments:
- * distdir --
- """
- cat = config.get_or_fail ( 'OVERLAY.category' ) + '/'
- if self.fuzzy:
- for dep in self._scan ( distdir ):
- yield rules.SimpleFuzzyDependencyRule (
- resolving_package = strutil.fix_ebuild_name ( cat + dep ),
- dep_str = dep,
- is_selfdep=2
- )
- else:
- for dep in self._scan ( distdir ):
- yield rules.SimpleDependencyRule (
- resolving_package = strutil.fix_ebuild_name ( cat + dep ),
- dep_str = dep,
- is_selfdep=2
- )
- # --- end of make_rules (...) ---
-
-
-class DepResConsole ( object ):
- # !! The console is really inefficient in terms of using cached data,
- # saving functions calls, ...
- # It's assumed that the user is still slower ;)
-
- shlex = shlex.shlex()
- whitespace = re.compile ( "\s+" )
-
- # the command usage dict
- CMD_USAGE = {
- 'add_pool' : """
- Creates a new pool on top of any existing ones.
-
- Arguments: None (ignored)
-
- Usage:
- * add_pool|<<
- """,
- 'addrule' : """
- Creates a new dependency rule and adds it to the current rule pool.
- The console supports single-line rules only at this time.
-
- Arguments: a list of quoted rule strings if shlex mode is active,
- else one rule string
-
- Usage:
- * +|addrule <rule>
- * +|addrule "<rule>" ["<rule>"]*
-
- """,
- 'help' : """
- Prints a general help message, a list of all help topics if --list\\
- is given, or a specific help message for the given command.
-
- Arguments: None, '--list', or a command
-
- Usage:
- * help
- * help --list
- * help <command>
- """,
- 'load' : """
- Loads a rule file or directory into a new dependency rule pool.
-
- Arguments: a file
-
- Usage:
- * load|li|l <file|dir>
- """,
- 'load_conf' : """
- Loads the rule files listed in the config file.
-
- Arguments: None (ignored)
-
- Usage:
- * load_conf|lc
- """,
- 'mkhelp' : """
- Verifies that all usable commands have a help message.
-
- Arguments: None (ignored)
-
- Usage:
- * mkhelp
- """,
- 'print': """
- Prints the content of the current pool or all pools.
-
- Arguments: 'all' (=> print all pools)
-
- Usage:
- * print
- * print all
- """,
- 'resolve': """
- Resolves one or more dependency strings.
-
- Arguments: a list of quoted dependency strings if shlex mode is\\
- active, else one dependency string.
-
- Usage:
- * resolve|r|? <dependency string>
- * resolve|r|? "<dependency string>" ["<dependency string>"]*
- """,
- 'scandir' : """
- Scans a directory for R packages and creates dependency rules\\
- for them.
-
- Arguments: a directory
-
- Usage:
- * scandir|sd <directory>
- """,
- 'set' : """
- Set or unset modes. Prints all modes and their state when called\\
- with no args.
- Currently, the only available mode is 'shlex' which enables/disables\\
- shell-like argument parsing.\\
- Shlex mode allows to specify more than one arg when running certain
- commands, but requires args to be enclosed with quotes.
-
- Arguments: None or a mode
-
- Usage:
- * set
- * unset
- * set <mode>
- * unset <mode>
- """,
- 'unwind' : """
- Removes the top-most (latest) dependency rule pool and all of its\\
- rules.
-
- Arguments: None (ignored)
-
- Usage:
- * unwind|>>
- """,
- 'write' : """
- Writes the rules of the top-most (latest) dependency rule pool to\\
- a file that later be loaded.
-
- Arguments: file to write
-
- Usage:
- * write|w <file>
- """,
- 'cd' : """
- Changes the working directory to the given one. Also creates it\\
- if necessary.
-
- Arguments: a directory
-
- Usage:
- * cd <directory>
- """,
- }
-
- CMD_USAGE_REDIRECT = {
- 'r' : 'resolve',
- '?' : 'resolve',
- 'sd' : 'scandir',
- '+' : 'addrule',
- 'li' : 'load',
- 'l' : 'load',
- 'lc' : 'load_conf',
- 'w' : 'write',
- 'p' : 'print',
- '>>' : 'unwind',
- '<<' : 'add_pool',
- 'unset' : 'set',
- 'h' : 'help',
- }
-
- def _create_command_table ( self ):
- # the command table
- # each command string is mapped to a function/method
- self.cmd_table = {
- 'resolve' : self.cmd_resolve,
- 'scandir' : self.cmd_rule_scandir,
- 'addrule' : self.cmd_rule_add,
- 'load' : self.cmd_rule_load,
- 'load_conf' : self.cmd_rule_load_from_config,
- 'write' : self.cmd_pool_write,
- 'print' : self.cmd_pool_print,
- 'unwind' : self.cmd_pool_unwind,
- 'add_pool' : self.cmd_pool_add,
- 'cd' : self.cmd_cd,
- 'set' : self.cmd_set,
- 'unset' : self.cmd_unset,
- 'help' : self.cmd_help,
- 'mkhelp' : self.cmd_mkhelp,
- }
-
- for alias, real in self.__class__.CMD_USAGE_REDIRECT.items():
- self.cmd_table [alias] = self.cmd_table [real]
- # --- end of _create_command_table (...) ---
-
- def _get_usage ( self, func_name ):
- """Returns the usage string for the given function (by name).
-
- arguments:
- * func_name
- """
- if func_name in self.__class__.CMD_USAGE_REDIRECT:
- fname = self.__class__.CMD_USAGE_REDIRECT [func_name]
- else:
- fname = func_name
-
- if fname not in self._usage_dict:
- lines = list()
- for line in self.__class__.CMD_USAGE [fname].split ( '\n' ):
- line = line.strip()
- if len ( line ) or len ( lines ):
- lines.append ( line )
-
- if len ( lines ) and not len ( lines [-1] ):
- lines.pop()
-
- self._usage_dict [fname] = '\n'.join ( lines ).replace ( '\\\n', ' ' )
-
- return self._usage_dict [fname]
- # --- end of _get_usage (...) ---
-
- def _print_usage ( self, func_name ):
- """Prints a usage message for the given function (by name)."""
- print (
- "command {!r}, usage:\n".format ( func_name ) + \
- self._get_usage ( func_name )
- )
- # --- end of _print_usage (...) ---
-
- def usage ( self ):
- """Prints a usage message for the command currently running and
- returns False."""
- self._print_usage ( self._current_command )
- return False
- # --- end of usage (...) ---
-
- def __init__ ( self ):
- """Initializes a dependency resolution console."""
- self.err_queue = ErrorQueue()
-
- # set up the resolver
- self.resolver = DependencyResolver ( err_queue=self.err_queue )
- # log everything
- self.resolver.set_logmask ( -1 )
- # disable passing events to listeners
- self.resolver.set_listenermask ( 0 )
-
- # dependency rule pools (a set of rules) are organized in a FIFO
- # structure that allows to create and delete new pools at runtime
- self.poolstack = self.resolver.static_rule_pools
- self.pool_id = 0
-
- # this rule maker is used to convert input (strings) into dependency
- # rules
- self._rule_maker = SimpleRuleMaker()
-
- # this rule maker is used to create rules for R packages found in
- # directories
- self._dir_rule_maker = PackageDirRuleMaker()
-
- # used for relative file paths (rule file writing,...)
- self._cwd = None
-
- # shlex mode:
- # if True: split command args using shell syntax
- # else : treat command args as one arg
-
- # e.g. 'resolve zoo >= 5',
- # => command is 'resolve'
- # => args:
- # shlex: [ 'zoo', '>=' , '5', ]
- # no-shlex: [ 'zoo >= 5', ]
- self.shlex_active = False
-
- # each command line is prefixed by this string
- self.PS1 = "cmd % "
-
- # output streams
- self.stdout = sys.stdout.write
- self.stderr = sys.stderr.write
-
- self._create_command_table()
-
- self._usage_dict = dict()
- self._current_command = None
-
- # the command table of exit commands
- # each listed command can be used to exit the depres console
- self.cmd_exit = frozenset (( 'q', 'qq', 'exit' ))
-
- if sys.version_info < ( 3, 0 ):
- self._get_input = raw_input
- else:
- self._get_input = input
- # --- end of __init__ (...) ---
-
- def _getpool ( self, new=False ):
- """Returns a dependency rule pool. Creates a new one if no pool exists
- or 'new' is set to True.
-
- arguments:
- * new -- defaults to True
- """
- if not self.poolstack or ( new and not self.poolstack [-1].empty() ):
- pool = SimpleDependencyRulePool (
- "pool" + str ( self.pool_id ),
- deptype_mask=deptype.RESOLVE_ALL
- )
- self.pool_id += 1
- self.poolstack.append ( pool )
- self.resolver._reset_unresolvable()
-
- return self.poolstack [-1]
- # --- end of _getpool (...) ---
-
- def cmd_mkhelp ( self, argv, line ):
- missing = list()
- for cmd in self.cmd_table:
- try:
- self._get_usage ( cmd )
- except KeyError:
- missing.append ( cmd )
-
- if missing:
- print (
- "Please write help messages for the following commands: " + \
- ', '.join ( sorted ( missing ) )
- )
- return False
- else:
- print ( "Everything looks ok." )
- return True
- # --- end of cmd_mkhelp (...) ---
-
- def cmd_cd ( self, argv, line ):
- if argv:
- self._cwd = os.path.abspath ( os.path.expanduser ( argv [0] ) )
- if not os.path.isdir ( self._cwd ):
- os.makedirs ( self._cwd )
- self.stdout ( "cwd = {!r}\n".format ( self._cwd ) )
- return True
- else:
- return self.usage()
- # --- end of cmd_cd (...) ---
-
- def cmd_rule_scandir ( self, argv, line ):
- """Scans a directory for R packages and creates rules for them.
-
- Usage: scandir <directory>
- """
- if argv and os.path.isdir ( argv[0] ):
- pool = self._getpool ( new=True )
- self.stdout ( "new rules:\n" )
- for r in self._dir_rule_maker.make_rules ( argv [0] ):
- self.stdout ( str ( r ) + "\n" )
- pool.add ( r )
- self.stdout ( "--- ---\n" )
- pool.sort()
-
- else:
- self.stderr ( "arg0 is not a dir\n" )
- return self.usage()
- # --- end of cmd_rule_scandir (...) ---
-
- def cmd_rule_load_from_config ( self, argv, line ):
- load = config.get_or_fail ( "DEPRES.simple_rules.files" )
- self.resolver.get_reader().read ( load )
- # don't write into ^this pool
- self._getpool ( new=True )
- # --- end of cmd_rule_load_from_config (...) ---
-
- def cmd_rule_load ( self, argv, line ):
- if argv:
- self.resolver.get_reader().read ( argv )
- else:
- return self.usage()
- # --- end of cmd_rule_load (...) ---
-
- def cmd_rule_add ( self, argv, line ):
- if not line:
- return self.usage()
- elif self._rule_maker.add ( line ):
- rules = self._rule_maker.done()
- pool = self._getpool()
-
- self.stdout ( "new rules:\n" )
- for _deptype, r in rules:
- self.stdout ( str ( r ) + "\n" )
- pool.rules.append ( r )
- self.stdout ( "--- ---\n" )
-
- pool.sort()
-
- self.resolver._reset_unresolvable()
-
- return True
- else:
- return False
- # --- end of cmd_addrule (...) ---
-
- def cmd_pool_print ( self, argv, line ):
- if argv and len ( argv ) > 0:
- if argv[0] == "all":
- _last = len ( self.poolstack )
- for n, p in enumerate ( self.poolstack ):
- self.stdout ( "showing pool {}/{}.\n".format (
- n + 1, _last
- ))
- p.export_rules ( sys.stdout )
- else:
- self.stdout ( "unknown arg1 {!r}.\n".format ( argv[0] ) )
- return self.usage()
- else:
- if len ( self.poolstack ):
- self.poolstack [-1].export_rules ( sys.stdout )
- # --- end of cmd_pool_print (...) ---
-
- def cmd_pool_write ( self, argv, line ):
- if not argv:
- return self.usage()
-
- if argv[0][0] == os.sep:
- f = argv [0]
- elif self._cwd is not None:
- f = self._cwd + os.sep + argv [0]
- else:
- f = os.path.abspath ( argv[0] )
-
- if os.access ( f, os.F_OK ):
- self.stdout ( "file {!r} exists!\n".format ( f ) )
- return False
-
- elif len ( self.poolstack ):
- try:
- fh = open ( f, 'w' )
- self.poolstack[-1].export_rules ( fh )
- fh.close()
- self.stdout ( "Wrote {!r}.\n".format ( f ) )
- return True
- finally:
- if 'fh' in locals() and fh: fh.close()
-
- else:
- self.stdout ( "no pool in use.\n" )
- return False
- # --- end of cmd_pool_write (...) ---
-
-
- def cmd_pool_unwind ( self, argv, line ):
- if self.poolstack:
- self.poolstack.pop()
- self.stdout ( "Pool removed from resolver.\n" )
- else:
- self.stdout ( "Resolver has no pools.\n" )
- # --- end of cmd_pool_unwind (...) ---
-
- def cmd_pool_add ( self, argv, line ):
- self._getpool ( new=True )
- self.stdout ( "New pool created.\n" )
- # --- end of cmd_pool_add (...) ---
-
- def run ( self ):
- cmd = None
-
- self.stdout (
- '== depres console ==\n'
- 'Run \'help\' to list all known commands\n'
- 'More specifically, \'help <cmd>\' prints a help message for the '
- 'given command, and \'help --list\' lists all help topics available\n'
- 'Use \'load_conf\' or \'lc\' to load the configured rule files\n'
- )
- if self.shlex_active:
- self.stdout (
- 'Note: shlex mode is enabled by default. '
- 'This splits all args according to shell syntax. '
- 'You can disable this (useful when resolving) '
- 'with \'unset shlex\'.\n'
- )
- self.stdout ( "\n" )
- self.cmd_help()
- self.stdout ( "\n" )
-
- while True:
- try:
- #self.stdout ( "\n" )
- cmd, argv, line = self.split_line ( self._get_input ( self.PS1 ) )
-
- if cmd is None:
- pass
- elif cmd in self.cmd_exit:
- break
- elif cmd in self.cmd_table:
- self._current_command = cmd
- ret = self.cmd_table [cmd] ( argv=argv, line=line )
- if ret is True:
- self.stdout ( "command succeeded.\n" )
- elif ret is False:
- self.stdout ( "command failed.\n" )
- else:
- self.stdout ( "command {!r} not found.\n".format ( cmd ) )
- self.cmd_help()
-
- except KeyboardInterrupt:
- self.stdout ( "\nuse \'exit\' to exit (or close stdin)\n" )
- except EOFError:
- self.stderr ( "\nexiting...\n" )
- break
- except Exception as e:
- logging.exception ( e )
- self.stderr ( str ( e ) + "\n" )
-
- self.resolver.close()
- # --- end of run (...) ---
-
- def split_line ( self, line ):
- l = line.strip()
- if not l:
- return ( None, None, None )
-
- linev = self.__class__.whitespace.split ( l, 1 )
-
- if len ( linev ) == 0:
- return ( None, None, None )
- elif len ( linev ) == 1:
- return ( linev [0].lower(), None, None )
- elif self.shlex_active:
- return ( linev [0].lower(), shlex.split ( linev [1] ), linev [1] )
- else:
- return ( linev [0].lower(), ( linev [1], ), linev [1] )
- # --- end of split_line (...) ---
-
- def cmd_help ( self, argv=None, *ignored, **kwargs_ignored ):
- if argv:
- if argv [0] == '--list':
- print (
- "The following help topics are available: " + \
- ', '.join ( self.__class__.CMD_USAGE ) + "."
- )
- else:
- for cmd in argv:
- self._print_usage ( cmd )
- else:
- self.stdout ( "commands: {}\n".format (
- ', '.join ( self.cmd_table.keys() )
- ) )
- self.stdout ( "exit-commands: {}\n".format (
- ', '.join ( self.cmd_exit )
- ) )
- # --- end of cmd_help (...) ---
-
- def cmd_resolve ( self, argv, line ):
- dep_list = argv
- if not dep_list:
- self.stdout ( "Resolve what?\n" )
- return self.usage()
- else:
- channel = EbuildJobChannel (
- err_queue=self.err_queue, name="channel"
- )
- self.resolver.register_channel ( channel )
-
- self.stdout ( "Trying to resolve {!r}.\n".format ( dep_list ) )
-
- channel.add_dependencies ( dep_list, deptype.ALL )
- deps = channel.satisfy_request (
- close_if_unresolvable=False,
- preserve_order=True
- )
- channel.close()
-
- if deps is None:
- self.stdout (
- 'Channel returned None. '
- 'At least one dep couldn\'t be resolved.\n'
- )
- else:
- self.stdout ( "Resolved as: {!r}\n".format ( deps [0] ) )
- # --- end of cmd_resolve (...) ---
-
- def _cmd_set_or_unset ( self, argv, is_set ):
- if not argv:
- self.stdout ( "shlex mode is {}.\n".format (
- "on" if self.shlex_active else "off"
- ) )
- elif argv [0] == 'shlex':
- self.shlex_active = is_set
- elif argv [0].lower() == "ps1":
- if is_set:
- self.PS1 = argv [1] + ' '
- else:
- self.PS1 = "cmd % "
- else:
- self.stdout ( "unknown args: {}.\n".format ( argv ) )
- return self.usage()
- # --- end of _cmd_set_or_unset (...) ---
-
- def cmd_set ( self, argv, line ):
- self._cmd_set_or_unset ( argv, True )
- # --- end of cmd_set (...) ---
-
- def cmd_unset ( self, argv, line ):
- self._cmd_set_or_unset ( argv, False )
- # --- end of cmd_unset (...) ---
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/depres/simpledeprule/
@ 2013-08-21 10:10 André Erdmann
0 siblings, 0 replies; 19+ messages in thread
From: André Erdmann @ 2013-08-21 10:10 UTC (permalink / raw
To: gentoo-commits
commit: ca3d1659b093752071b3faf46b649d2145b118ab
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Wed Aug 21 10:09:14 2013 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Wed Aug 21 10:09:14 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=ca3d1659
fix rule printing / selfdep multi-line rule parsing
is_selfdep=N was missing in SimpleRuleMaker.handle_multiline_begin().
---
roverlay/depres/simpledeprule/abstractrules.py | 32 +++++++++++++++----------
roverlay/depres/simpledeprule/rulemaker.py | 33 ++++++++++++++++----------
roverlay/depres/simpledeprule/rules.py | 16 ++++---------
3 files changed, 45 insertions(+), 36 deletions(-)
diff --git a/roverlay/depres/simpledeprule/abstractrules.py b/roverlay/depres/simpledeprule/abstractrules.py
index a94d2f3..37d3958 100644
--- a/roverlay/depres/simpledeprule/abstractrules.py
+++ b/roverlay/depres/simpledeprule/abstractrules.py
@@ -18,6 +18,8 @@ TMP_LOGGER = logging.getLogger ('simpledeps')
class SimpleRule ( deprule.DependencyRule ):
"""A dependency rule that represents an ignored package in portage."""
+ INDENT = 3 * ' '
+
def __init__ ( self,
dep_str=None, priority=50, resolving_package=None,
is_selfdep=0, logger_name='simple_rule',
@@ -137,25 +139,31 @@ class SimpleRule ( deprule.DependencyRule ):
resolving = self.__class__.RULE_PREFIX + resolving
# -- end if;
- if self.is_selfdep:
- if self.is_selfdep == 1:
- yield '@selfdep'
+
+ if self.is_selfdep == 2:
yield resolving
- elif len ( self.dep_alias ) == 0:
- pass
+ elif self.dep_alias:
+ if self.is_selfdep == 1:
+ yield '@selfdep'
- elif len ( self.dep_alias ) == 1:
- yield "{} :: {}".format ( resolving, next ( iter ( self.dep_alias ) ) )
+ if len ( self.dep_alias ) == 1:
+ yield "{} :: {}".format (
+ resolving, next ( iter ( self.dep_alias ) )
+ )
- else:
- yield resolving + ' {'
- for alias in self.dep_alias:
- yield "\t" + alias
- yield '}'
+ else:
+ yield resolving + ' {'
+ for alias in self.dep_alias:
+ yield self.INDENT + alias
+ yield '}'
+ # --- end of export_rule (...) ---
def __str__ ( self ):
return '\n'.join ( self.export_rule() )
+ # --- end of __str__ (...) ---
+
+# --- end of SimpleRule ---
class FuzzySimpleRule ( SimpleRule ):
diff --git a/roverlay/depres/simpledeprule/rulemaker.py b/roverlay/depres/simpledeprule/rulemaker.py
index cfb2736..083fd97 100644
--- a/roverlay/depres/simpledeprule/rulemaker.py
+++ b/roverlay/depres/simpledeprule/rulemaker.py
@@ -90,24 +90,30 @@ class SimpleRuleMaker ( roverlay.util.mapreader.MapFileParser ):
# --- end of _parse_deptype (...) ---
def _get_effective_deptype ( self, clear_temporary=True ):
+ """Returns a 2-tuple ( <deptype>, <deptype_is_selfdep> ) based on
+ self._deptype and self._deptype_once. deptype_is_selfdep is an int
+ (0 or 1), "true" selfdeps (2) cannot be recognized here.
+
+ arguments:
+ * clear_temporary -- clear self._deptype_once
+ """
if self._deptype_once is not deptype.NONE:
+ ret = self._deptype_once
if clear_temporary:
- ret = self._deptype_once
self._deptype_once = deptype.NONE
- return ret
- else:
- self._deptype_once
else:
- return self._deptype
+ ret = self._deptype
+
+ return ( ret, 1 if ( ret & deptype.selfdep ) else 0 )
# --- end of _get_effective_deptype (...) ---
def handle_entry_line ( self, dep, dep_str='' ):
# single line rule, either selfdep,
# e.g. '~zoo' -> fuzzy sci-R/zoo :: zoo
# or normal rule 'dev-lang/R :: R'
- # selfdeps are always single line statements (!)
+ # selfdeps (rule stubs) are always single line statements (!)
- rule_deptype = self._get_effective_deptype()
+ rule_deptype, is_selfdep = self._get_effective_deptype()
rule_class, resolving, kwargs = self._kwmap.lookup ( dep )
if dep_str:
@@ -115,9 +121,7 @@ class SimpleRuleMaker ( roverlay.util.mapreader.MapFileParser ):
new_rule = rule_class (
resolving_package = resolving,
dep_str = dep_str,
- is_selfdep = (
- 1 if ( rule_deptype & deptype.selfdep ) else 0
- ),
+ is_selfdep = is_selfdep,
**kwargs
)
@@ -143,11 +147,16 @@ class SimpleRuleMaker ( roverlay.util.mapreader.MapFileParser ):
# --- end of handle_entry_line (...) ---
def handle_multiline_begin ( self, line ):
+ rule_deptype, is_selfdep = self._get_effective_deptype()
rule_class, resolving, kwargs = self._kwmap.lookup ( line )
self._next = (
- self._get_effective_deptype(),
- rule_class ( resolving_package=resolving, **kwargs ),
+ rule_deptype,
+ rule_class (
+ resolving_package = resolving,
+ is_selfdep = is_selfdep,
+ **kwargs
+ ),
)
return True
# --- end of handle_multiline_begin (...) ---
diff --git a/roverlay/depres/simpledeprule/rules.py b/roverlay/depres/simpledeprule/rules.py
index 7e40ed7..306e27d 100644
--- a/roverlay/depres/simpledeprule/rules.py
+++ b/roverlay/depres/simpledeprule/rules.py
@@ -146,12 +146,8 @@ class SimpleIgnoreDependencyRule ( SimpleRule ):
priority=50,
**kw
)
+# --- end of SimpleIgnoreDependencyRule ---
- def __str__ ( self ):
- if self.is_selfdep:
- return self.__class__.RULE_PREFIX + next ( iter ( self.dep_alias ) )
- else:
- return super ( self.__class__, self ) . __str__()
class SimpleDependencyRule ( SimpleRule ):
@@ -170,9 +166,11 @@ class SimpleDependencyRule ( SimpleRule ):
resolving_package=resolving_package,
**kw
)
-
# --- end of __init__ (...) ---
+# --- end of SimpleDependencyRule ---
+
+
class SimpleFuzzyIgnoreDependencyRule ( FuzzySimpleRule ):
RULE_PREFIX = '%'
@@ -185,12 +183,6 @@ class SimpleFuzzyIgnoreDependencyRule ( FuzzySimpleRule ):
**kw
)
- def __str__ ( self ):
- if self.is_selfdep:
- return self.__class__.RULE_PREFIX + next ( iter ( self.dep_alias ) )
- else:
- return super ( self.__class__, self ) . __str__()
-
def handle_version_relative_match ( self, *args, **kwargs ):
raise Exception ( "should-be unreachable code" )
# --- end of handle_version_relative_match (...) ---
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/depres/simpledeprule/
@ 2013-08-21 13:51 André Erdmann
0 siblings, 0 replies; 19+ messages in thread
From: André Erdmann @ 2013-08-21 13:51 UTC (permalink / raw
To: gentoo-commits
commit: a1abd9d960f5a595d3a5f4720f454d57f06d8bbc
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Wed Aug 21 11:02:28 2013 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Wed Aug 21 11:02:28 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=a1abd9d9
remove unused import in dep rule maker
---
roverlay/depres/simpledeprule/rulemaker.py | 1 -
1 file changed, 1 deletion(-)
diff --git a/roverlay/depres/simpledeprule/rulemaker.py b/roverlay/depres/simpledeprule/rulemaker.py
index 083fd97..1edbdb9 100644
--- a/roverlay/depres/simpledeprule/rulemaker.py
+++ b/roverlay/depres/simpledeprule/rulemaker.py
@@ -21,7 +21,6 @@ from roverlay import config
from roverlay.depres import deptype
from roverlay.depres.simpledeprule import rules
-from roverlay.depres.simpledeprule.abstractrules import *
from roverlay.depres.simpledeprule.pool import SimpleDependencyRulePool
class SimpleRuleMaker ( roverlay.util.mapreader.MapFileParser ):
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/depres/simpledeprule/
@ 2013-08-27 15:39 André Erdmann
0 siblings, 0 replies; 19+ messages in thread
From: André Erdmann @ 2013-08-27 15:39 UTC (permalink / raw
To: gentoo-commits
commit: 18ea92d1aeffa20e0f333fb0d187017a98cbfd67
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Tue Aug 27 15:29:45 2013 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Tue Aug 27 15:29:45 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=18ea92d1
dep rule parser: '#! ERROR' statement
lets the dep parser raise an exception, which causes roverlay to exit.
---
roverlay/depres/simpledeprule/rulemaker.py | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/roverlay/depres/simpledeprule/rulemaker.py b/roverlay/depres/simpledeprule/rulemaker.py
index 1edbdb9..f58f96b 100644
--- a/roverlay/depres/simpledeprule/rulemaker.py
+++ b/roverlay/depres/simpledeprule/rulemaker.py
@@ -25,7 +25,8 @@ from roverlay.depres.simpledeprule.pool import SimpleDependencyRulePool
class SimpleRuleMaker ( roverlay.util.mapreader.MapFileParser ):
- breakparse = set (( '! NOPARSE', '! BREAK' ))
+ breakparse = frozenset ({ '! NOPARSE', '! BREAK' })
+ kw_error = frozenset ({ '! ERROR', })
def __init__ ( self, rule_separator=None ):
super ( SimpleRuleMaker, self ).__init__()
@@ -181,6 +182,11 @@ class SimpleRuleMaker ( roverlay.util.mapreader.MapFileParser ):
elif line in self.breakparse:
self.stop_reading = True
+ elif line in self.kw_error:
+ self.stop_reading = True
+ raise Exception ( "#! ERROR" )
+ return False
+
# else is a "real" comment
return True
# --- end of handle_comment_line (...) ---
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/depres/simpledeprule/
@ 2013-09-03 8:35 André Erdmann
0 siblings, 0 replies; 19+ messages in thread
From: André Erdmann @ 2013-09-03 8:35 UTC (permalink / raw
To: gentoo-commits
commit: 99445900f7184524d53d47239c4d5025a80c7b38
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Tue Sep 3 08:34:29 2013 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Tue Sep 3 08:34:29 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=99445900
dynamic selfdep pool: use sorted rules
sort rule dict by repo
---
roverlay/depres/simpledeprule/dynpool.py | 30 ++++++++++--------------------
1 file changed, 10 insertions(+), 20 deletions(-)
diff --git a/roverlay/depres/simpledeprule/dynpool.py b/roverlay/depres/simpledeprule/dynpool.py
index 7688bf1..c5e9394 100644
--- a/roverlay/depres/simpledeprule/dynpool.py
+++ b/roverlay/depres/simpledeprule/dynpool.py
@@ -9,17 +9,14 @@
This module provides a class, DynamicSelfdepRulePool, that creates dynamic
(i.e. exist only in memory, not as file) dependency rules that resolve
dependencies on other R packages ("sci-R/<pkg>" if OVERLAY_CATEGORY is sci-R).
-The rules are created by using a "rule keyword function" (a function/generator
-that yields keywords for rule creation), typically provided by the overlay
-package's "root" module.
+The rules are created by using a rule generator, typically provided by the
+overlay.
The DynamicSelfdepRulePool is strict about matches; it only matches strings
whose dependency type contains deptype.internal.
"""
__all__ = [ 'DynamicSelfdepRulePool', 'get' ]
-import collections
-
from roverlay.depres import deptype
from roverlay.depres.deprule import DynamicDependencyRulePool
from roverlay.depres.simpledeprule.rules import SimpleFuzzyDependencyRule
@@ -40,12 +37,8 @@ class DynamicSelfdepRulePool ( DynamicDependencyRulePool ):
# --- end of __init__ (...) ---
def sort_rules ( self ):
- # TODO: sort self.rules itself ("sort repos")
- priokey = lambda k: k.priority
-
- if self.rules:
- for rules in self.rules.values():
- rules.sort ( key=priokey )
+ # already sorted
+ pass
# --- end of sort_rules (...) ---
def iter_rules ( self ):
@@ -76,17 +69,14 @@ class DynamicSelfdepRulePool ( DynamicDependencyRulePool ):
return False
# --- end of accepts_other (...) ---
- def reload ( self ):
- self.rules = self._rule_generator.make_rule_dict()
- # --- end of reload (...) ---
-
+ def reload_rules ( self ):
+ self.rules = self._rule_generator.make_ordered_rule_dict()
+ # --- end of reload_rules (...) ---
# --- end of DynamicSelfdepRulePool ---
-def get ( rule_kw_function ):
- """Returns a default DynamicSelfdepRulePool for rule_kw_function."""
- return DynamicSelfdepRulePool (
- rule_kw_function, SimpleFuzzyDependencyRule
- )
+def get ( rule_generator ):
+ """Returns a default DynamicSelfdepRulePool for rule_generator."""
+ return DynamicSelfdepRulePool ( rule_generator, SimpleFuzzyDependencyRule )
# --- end of get (...) ---
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/depres/simpledeprule/
@ 2014-06-05 22:09 André Erdmann
0 siblings, 0 replies; 19+ messages in thread
From: André Erdmann @ 2014-06-05 22:09 UTC (permalink / raw
To: gentoo-commits
commit: 2478cb4a791c5cf184f859d28605de32d48cb2a8
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Wed May 7 01:37:39 2014 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Wed May 7 01:37:39 2014 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=2478cb4a
roverlay/depres/simpledeprule/util: add obj method
get_constructor_args()
---
roverlay/depres/simpledeprule/util.py | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/roverlay/depres/simpledeprule/util.py b/roverlay/depres/simpledeprule/util.py
index 36f88cd..1e82161 100644
--- a/roverlay/depres/simpledeprule/util.py
+++ b/roverlay/depres/simpledeprule/util.py
@@ -78,6 +78,10 @@ class SlotValueCreatorBase ( object ):
raise NotImplementedError()
# --- end of get_slot (...) ---
+ def get_constructor_args ( self ):
+ raise NotImplementedError()
+ # --- end of get_constructor_args (...) ---
+
def __str__ ( self ):
raise NotImplementedError()
# --- end of __str__ (...) ---
@@ -97,6 +101,9 @@ class SingleIndexValueCreator ( SlotValueCreatorBase ):
return None
# --- end of get_slot (...) ---
+ def get_constructor_args ( self ):
+ return ( self._index, )
+
def __str__ ( self ):
return str ( self._index )
@@ -117,11 +124,15 @@ class IndexRangeSlotValueCreator ( SlotValueCreatorBase ):
return None
# --- end of get_slot (...) ---
- def __str__ ( self ):
- return str ( self._low ) + '..' + str (
- ( self._high - 1 ) if self._high > 0 else self._high
+ def get_constructor_args ( self ):
+ return (
+ self._low,
+ ( ( self._high - 1 ) if self._high > 0 else self._high )
)
+ def __str__ ( self ):
+ return '..'.join ( map ( str, self.get_constructor_args() ) )
+
class ImmediateSlotValueCreator ( SlotValueCreatorBase ):
def __init__ ( self, v_str ):
super ( ImmediateSlotValueCreator, self ).__init__()
@@ -144,6 +155,9 @@ class ImmediateSlotValueCreator ( SlotValueCreatorBase ):
return self._value
# --- end of get_slot (...) ---
+ def get_constructor_args ( self ):
+ return ( self._value, )
+
def __str__ ( self ):
return "i" + self._value
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/depres/simpledeprule/
@ 2014-06-25 16:41 André Erdmann
0 siblings, 0 replies; 19+ messages in thread
From: André Erdmann @ 2014-06-25 16:41 UTC (permalink / raw
To: gentoo-commits
commit: 50bd6d5aac48317c46b777acf9c1836e792bff58
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Wed Jun 25 16:37:08 2014 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Wed Jun 25 16:37:08 2014 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=50bd6d5a
roverlay/depres, rule: temporary fix
do not slot-resolve dep_env with a vmod of '>' or '>='.
This is a temporary fix. A more controllable (configurable) solution will be
added once that "regenerate $list of ebuilds" has been implemented.
---
roverlay/depres/simpledeprule/rules.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/roverlay/depres/simpledeprule/rules.py b/roverlay/depres/simpledeprule/rules.py
index 306e27d..7ba4967 100644
--- a/roverlay/depres/simpledeprule/rules.py
+++ b/roverlay/depres/simpledeprule/rules.py
@@ -337,7 +337,9 @@ class SimpleFuzzySlotDependencyRule ( FuzzySimpleRule ):
res = False
vmod = fuzzy ['vmod']
- if not ( vmod & dep_env.VMOD_NOT ):
+ # FIXME: improve decision making
+ #
+ if not ( vmod & (dep_env.VMOD_NOT|dep_env.VMOD_GT) ):
# can be resolved as slot(ted) dep
if self.mode == 2:
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/depres/simpledeprule/
@ 2014-07-29 18:29 André Erdmann
2014-08-23 19:03 ` André Erdmann
0 siblings, 1 reply; 19+ messages in thread
From: André Erdmann @ 2014-07-29 18:29 UTC (permalink / raw
To: gentoo-commits
commit: 1cc91c92cd6103185598fa2e4ce9829a01a30b2d
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Tue Jul 29 17:00:06 2014 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Tue Jul 29 17:00:06 2014 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=1cc91c92
roverlay/depres, slot rules: "wide match"
In continuation of commit #50bd6d5aac48317c46b777acf9c1836e792bff58,
make the slot match behavior configurable (depending on the slot rule,
not the dep env<-package).
---
roverlay/depres/simpledeprule/rules.py | 142 +++++++++++++++++++++++----------
1 file changed, 98 insertions(+), 44 deletions(-)
diff --git a/roverlay/depres/simpledeprule/rules.py b/roverlay/depres/simpledeprule/rules.py
index 7ba4967..df767ba 100644
--- a/roverlay/depres/simpledeprule/rules.py
+++ b/roverlay/depres/simpledeprule/rules.py
@@ -27,6 +27,8 @@ from roverlay.depres.simpledeprule.util import \
from roverlay.depres.simpledeprule.abstractrules import \
SimpleRule, FuzzySimpleRule
+import roverlay.depres.depenv
+
@@ -100,6 +102,12 @@ class RuleConstructor ( object ):
# # unsafe, could be used to inject "$(rm -rf /)" etc.
# kwargs ['slot_operator'] = value
+ elif opt == 'wide_match':
+ if not has_value:
+ kwargs ['allow_wide_match'] = True
+ else:
+ raise NotImplementedError("wide_match value")
+
elif opt == '*':
kwargs ['slot_operator'] = '*'
@@ -232,8 +240,17 @@ class SimpleFuzzySlotDependencyRule ( FuzzySimpleRule ):
# 'slot' : '{slot}',
# }
- #RULE_PREFIX = '~'
- RULE_PREFIX = SimpleFuzzyDependencyRule.RULE_PREFIX
+ #RULE_PREFIX = '~'
+ RULE_PREFIX = SimpleFuzzyDependencyRule.RULE_PREFIX
+
+ # version relation operators that should never be matched in slot dep rules
+ # (bitmask)
+ VMOD_BASE_DENY_MASK = roverlay.depres.depenv.DepEnv.VMOD_NOT
+
+ # operators that should not be matched in nonwide mode (bitmask)
+ # - in addition to the base mask -
+ VMOD_WIDE_DENY_MASK = roverlay.depres.depenv.DepEnv.VMOD_GT
+
def __init__ ( self,
priority = 71,
@@ -243,6 +260,7 @@ class SimpleFuzzySlotDependencyRule ( FuzzySimpleRule ):
slotparts = None,
subslotparts = None,
slot_operator = None,
+ allow_wide_match = None,
**kw
):
super ( SimpleFuzzySlotDependencyRule, self ) . __init__ (
@@ -252,11 +270,17 @@ class SimpleFuzzySlotDependencyRule ( FuzzySimpleRule ):
**kw
)
- self.mode = 0 if slot_mode is None else slot_mode
- self.slot_restrict = slot_restrict
- self.slot_operator = slot_operator
- self.slotparts = get_slot_parser ("0") if slotparts is None else slotparts
- self.subslotparts = subslotparts
+ self.mode = 0 if slot_mode is None else slot_mode
+ self.slot_restrict = slot_restrict
+ self.slot_operator = slot_operator
+ self.slotparts = (
+ get_slot_parser ("0") if slotparts is None else slotparts
+ )
+ self.subslotparts = subslotparts
+ self.allow_wide_match = allow_wide_match
+ self.vmod_mask = self.VMOD_BASE_DENY_MASK
+ if not allow_wide_match:
+ self.vmod_mask |= self.VMOD_WIDE_DENY_MASK
if self.mode == 0:
# "default"
@@ -294,13 +318,21 @@ class SimpleFuzzySlotDependencyRule ( FuzzySimpleRule ):
def noexport ( self ):
del self.slot_operator
- del self.mode
+ del self.allow_wide_match
+
if self.slot_restrict:
self.slot_restrict.noexport()
# --- end of noexport (...) ---
def get_resolving_str ( self ):
def gen_opts():
+ if self.allow_wide_match:
+ yield "wide_match"
+
+# yield "vmod_mask={:#x}".format (
+# self.vmod_mask & ~self.VMOD_BASE_DENY_MASK
+# )
+
if self.mode == 2:
yield "open"
else:
@@ -327,52 +359,74 @@ class SimpleFuzzySlotDependencyRule ( FuzzySimpleRule ):
resolv = (
self._orig_resolving_package
if hasattr ( self, '_orig_resolving_package' )
- else self.resolving_package,
+ else self.resolving_package
),
opts = ':'.join ( gen_opts() )
)
# --- end of get_resolving_str (...) ---
def handle_version_relative_match ( self, dep_env, fuzzy ):
+ def get_slotted_result ( dep_env, fuzzy, vmod ):
+ slot_str = None
+ vslot_str = None
+ slot = self.slotparts.get_slot ( fuzzy )
+
+ if slot is not None:
+ if self.subslotparts:
+ subslot = self.subslotparts.get_slot ( fuzzy )
+ if subslot is not None:
+ slot_str = slot + '/' + subslot
+ vslot_str = (
+ self.slotparts.calculate_slot ( fuzzy, slot )
+ + '/'
+ + self.subslotparts.calculate_slot ( fuzzy, subslot )
+ )
+ else:
+ vslot_str = self.slotparts.calculate_slot ( fuzzy, slot )
+ slot_str = slot
+
+ if slot_str and (
+ not self.slot_restrict
+ or self.slot_restrict.accepts ( vslot_str )
+ ):
+ return self._resolving_fmt.format (
+ slot = slot_str,
+ version = fuzzy ['version'],
+ vmod = fuzzy ['version_modifier']
+ )
+ # -- end if <accepted slot>
+ # -- end if <have slot>
+
+ # explicit return
+ return None
+ # --- end of get_slot_result (...) ---
+
res = False
vmod = fuzzy ['vmod']
- # FIXME: improve decision making
- #
- if not ( vmod & (dep_env.VMOD_NOT|dep_env.VMOD_GT) ):
- # can be resolved as slot(ted) dep
- if self.mode == 2:
- res = self.resolving_package
- elif vmod & dep_env.VMOD_EQ:
- slot_str = None
- vslot_str = None
- slot = self.slotparts.get_slot ( fuzzy )
-
- if slot is not None:
- if self.subslotparts:
- subslot = self.subslotparts.get_slot ( fuzzy )
- if subslot is not None:
- slot_str = slot + '/' + subslot
- vslot_str = (
- self.slotparts.calculate_slot ( fuzzy, slot )
- + '/'
- + self.subslotparts.calculate_slot ( fuzzy, subslot )
- )
- else:
- vslot_str = self.slotparts.calculate_slot ( fuzzy, slot )
- slot_str = slot
-
- if slot_str and (
- not self.slot_restrict
- or self.slot_restrict.accepts ( vslot_str )
- ):
- res = self._resolving_fmt.format (
- slot=slot_str,
- version=fuzzy['version'], vmod=fuzzy['version_modifier']
- )
+ if vmod & self.vmod_mask:
+ # can never be resolved as slot(ted) dep
+ return False
- # -- end if vmod != NOT
+## MAYBE TODO
+## elif self.ident and dep_env.want_slotres_override(self.ident):
+### ^^^^^^^^^^? ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^?
+## want_slot_res, ... = dep_env.get_slotres_override(self.ident,...)
+### ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^?
+## if not want_slot_res:
+## return False
+## elif ...:
+## ...
+##
+
+ # else might be resolvable as slot(ted) dep
+ elif self.mode == 2:
+ return self.resolving_package
+ elif vmod & dep_env.VMOD_EQ:
+ return get_slotted_result ( dep_env, fuzzy, vmod )
+ else:
+ return False
+ # -- end if <vmod>
- return res
# --- end of handle_version_relative_match (...) ---
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/depres/simpledeprule/
2014-07-29 18:29 André Erdmann
@ 2014-08-23 19:03 ` André Erdmann
0 siblings, 0 replies; 19+ messages in thread
From: André Erdmann @ 2014-08-23 19:03 UTC (permalink / raw
To: gentoo-commits
commit: 1cc91c92cd6103185598fa2e4ce9829a01a30b2d
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Tue Jul 29 17:00:06 2014 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Tue Jul 29 17:00:06 2014 +0000
URL: http://sources.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=1cc91c92
roverlay/depres, slot rules: "wide match"
In continuation of commit #50bd6d5aac48317c46b777acf9c1836e792bff58,
make the slot match behavior configurable (depending on the slot rule,
not the dep env<-package).
---
roverlay/depres/simpledeprule/rules.py | 142 +++++++++++++++++++++++----------
1 file changed, 98 insertions(+), 44 deletions(-)
diff --git a/roverlay/depres/simpledeprule/rules.py b/roverlay/depres/simpledeprule/rules.py
index 7ba4967..df767ba 100644
--- a/roverlay/depres/simpledeprule/rules.py
+++ b/roverlay/depres/simpledeprule/rules.py
@@ -27,6 +27,8 @@ from roverlay.depres.simpledeprule.util import \
from roverlay.depres.simpledeprule.abstractrules import \
SimpleRule, FuzzySimpleRule
+import roverlay.depres.depenv
+
@@ -100,6 +102,12 @@ class RuleConstructor ( object ):
# # unsafe, could be used to inject "$(rm -rf /)" etc.
# kwargs ['slot_operator'] = value
+ elif opt == 'wide_match':
+ if not has_value:
+ kwargs ['allow_wide_match'] = True
+ else:
+ raise NotImplementedError("wide_match value")
+
elif opt == '*':
kwargs ['slot_operator'] = '*'
@@ -232,8 +240,17 @@ class SimpleFuzzySlotDependencyRule ( FuzzySimpleRule ):
# 'slot' : '{slot}',
# }
- #RULE_PREFIX = '~'
- RULE_PREFIX = SimpleFuzzyDependencyRule.RULE_PREFIX
+ #RULE_PREFIX = '~'
+ RULE_PREFIX = SimpleFuzzyDependencyRule.RULE_PREFIX
+
+ # version relation operators that should never be matched in slot dep rules
+ # (bitmask)
+ VMOD_BASE_DENY_MASK = roverlay.depres.depenv.DepEnv.VMOD_NOT
+
+ # operators that should not be matched in nonwide mode (bitmask)
+ # - in addition to the base mask -
+ VMOD_WIDE_DENY_MASK = roverlay.depres.depenv.DepEnv.VMOD_GT
+
def __init__ ( self,
priority = 71,
@@ -243,6 +260,7 @@ class SimpleFuzzySlotDependencyRule ( FuzzySimpleRule ):
slotparts = None,
subslotparts = None,
slot_operator = None,
+ allow_wide_match = None,
**kw
):
super ( SimpleFuzzySlotDependencyRule, self ) . __init__ (
@@ -252,11 +270,17 @@ class SimpleFuzzySlotDependencyRule ( FuzzySimpleRule ):
**kw
)
- self.mode = 0 if slot_mode is None else slot_mode
- self.slot_restrict = slot_restrict
- self.slot_operator = slot_operator
- self.slotparts = get_slot_parser ("0") if slotparts is None else slotparts
- self.subslotparts = subslotparts
+ self.mode = 0 if slot_mode is None else slot_mode
+ self.slot_restrict = slot_restrict
+ self.slot_operator = slot_operator
+ self.slotparts = (
+ get_slot_parser ("0") if slotparts is None else slotparts
+ )
+ self.subslotparts = subslotparts
+ self.allow_wide_match = allow_wide_match
+ self.vmod_mask = self.VMOD_BASE_DENY_MASK
+ if not allow_wide_match:
+ self.vmod_mask |= self.VMOD_WIDE_DENY_MASK
if self.mode == 0:
# "default"
@@ -294,13 +318,21 @@ class SimpleFuzzySlotDependencyRule ( FuzzySimpleRule ):
def noexport ( self ):
del self.slot_operator
- del self.mode
+ del self.allow_wide_match
+
if self.slot_restrict:
self.slot_restrict.noexport()
# --- end of noexport (...) ---
def get_resolving_str ( self ):
def gen_opts():
+ if self.allow_wide_match:
+ yield "wide_match"
+
+# yield "vmod_mask={:#x}".format (
+# self.vmod_mask & ~self.VMOD_BASE_DENY_MASK
+# )
+
if self.mode == 2:
yield "open"
else:
@@ -327,52 +359,74 @@ class SimpleFuzzySlotDependencyRule ( FuzzySimpleRule ):
resolv = (
self._orig_resolving_package
if hasattr ( self, '_orig_resolving_package' )
- else self.resolving_package,
+ else self.resolving_package
),
opts = ':'.join ( gen_opts() )
)
# --- end of get_resolving_str (...) ---
def handle_version_relative_match ( self, dep_env, fuzzy ):
+ def get_slotted_result ( dep_env, fuzzy, vmod ):
+ slot_str = None
+ vslot_str = None
+ slot = self.slotparts.get_slot ( fuzzy )
+
+ if slot is not None:
+ if self.subslotparts:
+ subslot = self.subslotparts.get_slot ( fuzzy )
+ if subslot is not None:
+ slot_str = slot + '/' + subslot
+ vslot_str = (
+ self.slotparts.calculate_slot ( fuzzy, slot )
+ + '/'
+ + self.subslotparts.calculate_slot ( fuzzy, subslot )
+ )
+ else:
+ vslot_str = self.slotparts.calculate_slot ( fuzzy, slot )
+ slot_str = slot
+
+ if slot_str and (
+ not self.slot_restrict
+ or self.slot_restrict.accepts ( vslot_str )
+ ):
+ return self._resolving_fmt.format (
+ slot = slot_str,
+ version = fuzzy ['version'],
+ vmod = fuzzy ['version_modifier']
+ )
+ # -- end if <accepted slot>
+ # -- end if <have slot>
+
+ # explicit return
+ return None
+ # --- end of get_slot_result (...) ---
+
res = False
vmod = fuzzy ['vmod']
- # FIXME: improve decision making
- #
- if not ( vmod & (dep_env.VMOD_NOT|dep_env.VMOD_GT) ):
- # can be resolved as slot(ted) dep
- if self.mode == 2:
- res = self.resolving_package
- elif vmod & dep_env.VMOD_EQ:
- slot_str = None
- vslot_str = None
- slot = self.slotparts.get_slot ( fuzzy )
-
- if slot is not None:
- if self.subslotparts:
- subslot = self.subslotparts.get_slot ( fuzzy )
- if subslot is not None:
- slot_str = slot + '/' + subslot
- vslot_str = (
- self.slotparts.calculate_slot ( fuzzy, slot )
- + '/'
- + self.subslotparts.calculate_slot ( fuzzy, subslot )
- )
- else:
- vslot_str = self.slotparts.calculate_slot ( fuzzy, slot )
- slot_str = slot
-
- if slot_str and (
- not self.slot_restrict
- or self.slot_restrict.accepts ( vslot_str )
- ):
- res = self._resolving_fmt.format (
- slot=slot_str,
- version=fuzzy['version'], vmod=fuzzy['version_modifier']
- )
+ if vmod & self.vmod_mask:
+ # can never be resolved as slot(ted) dep
+ return False
- # -- end if vmod != NOT
+## MAYBE TODO
+## elif self.ident and dep_env.want_slotres_override(self.ident):
+### ^^^^^^^^^^? ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^?
+## want_slot_res, ... = dep_env.get_slotres_override(self.ident,...)
+### ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^?
+## if not want_slot_res:
+## return False
+## elif ...:
+## ...
+##
+
+ # else might be resolvable as slot(ted) dep
+ elif self.mode == 2:
+ return self.resolving_package
+ elif vmod & dep_env.VMOD_EQ:
+ return get_slotted_result ( dep_env, fuzzy, vmod )
+ else:
+ return False
+ # -- end if <vmod>
- return res
# --- end of handle_version_relative_match (...) ---
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/depres/simpledeprule/
@ 2014-08-23 19:03 André Erdmann
0 siblings, 0 replies; 19+ messages in thread
From: André Erdmann @ 2014-08-23 19:03 UTC (permalink / raw
To: gentoo-commits
commit: ffe2f8e7da01aa425467f0a0449f404d8adf4e6b
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Sat Aug 23 18:38:33 2014 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Sat Aug 23 18:38:33 2014 +0000
URL: http://sources.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=ffe2f8e7
roverlay/depres, slot rules: fix get_slot_result()
---
roverlay/depres/simpledeprule/rules.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/roverlay/depres/simpledeprule/rules.py b/roverlay/depres/simpledeprule/rules.py
index 797ba98..869c5aa 100644
--- a/roverlay/depres/simpledeprule/rules.py
+++ b/roverlay/depres/simpledeprule/rules.py
@@ -402,7 +402,7 @@ class SimpleFuzzySlotDependencyRule ( FuzzySimpleRule ):
# -- end if <have slot>
# explicit return
- return None
+ return False
# --- end of get_slot_result (...) ---
res = False
^ permalink raw reply related [flat|nested] 19+ messages in thread
end of thread, other threads:[~2014-08-23 19:03 UTC | newest]
Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-13 16:34 [gentoo-commits] proj/R_overlay:master commit in: roverlay/depres/simpledeprule/ André Erdmann
-- strict thread matches above, loose matches on Subject: below --
2014-08-23 19:03 André Erdmann
2014-07-29 18:29 André Erdmann
2014-08-23 19:03 ` André Erdmann
2014-06-25 16:41 André Erdmann
2014-06-05 22:09 André Erdmann
2013-09-03 8:35 André Erdmann
2013-08-27 15:39 André Erdmann
2013-08-21 13:51 André Erdmann
2013-08-21 10:10 André Erdmann
2013-07-23 7:51 André Erdmann
2013-07-10 15:10 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-07-10 16:16 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-07-03 10:05 André Erdmann
2013-07-03 10:04 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-07-03 10:05 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-06-05 18:08 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-06-13 16:34 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-06-04 21:06 André Erdmann
2012-08-02 15:14 André Erdmann
2012-08-01 21:10 André Erdmann
2012-07-11 18:43 André Erdmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox