aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndré Erdmann <dywi@mailerd.de>2014-05-07 03:38:05 +0200
committerAndré Erdmann <dywi@mailerd.de>2014-05-07 03:38:05 +0200
commit83d2732502634d7a91c5bf379d5ee3b6a252872f (patch)
tree6ca412b9bb49bfc341aa2317405825903cdbc6db /roverlay/depres
parentroverlay/depres/simpledeprule/util: add obj method (diff)
downloadR_overlay-83d2732502634d7a91c5bf379d5ee3b6a252872f.tar.gz
R_overlay-83d2732502634d7a91c5bf379d5ee3b6a252872f.tar.bz2
R_overlay-83d2732502634d7a91c5bf379d5ee3b6a252872f.zip
roverlay/depres, rule pools: also export #deptype
Diffstat (limited to 'roverlay/depres')
-rw-r--r--roverlay/depres/deprule.py52
-rw-r--r--roverlay/depres/simpledeprule/abstractrules.py4
-rw-r--r--roverlay/depres/simpledeprule/rulemaker.py1
3 files changed, 50 insertions, 7 deletions
diff --git a/roverlay/depres/deprule.py b/roverlay/depres/deprule.py
index f7b0acc..fa7f8a1 100644
--- a/roverlay/depres/deprule.py
+++ b/roverlay/depres/deprule.py
@@ -42,7 +42,7 @@ class DependencyRule ( object ):
make_result = _make_result
- def export_rule ( self ):
+ def export_rule ( self, with_selfdep_keyword=True ):
raise NotImplementedError()
# --- end of export_rule (...) ---
@@ -65,6 +65,15 @@ class DependencyRulePoolBase ( object ):
self.rule_weight = 0
# --- end of __init__ (...) ---
+ def check_all_selfdep ( self ):
+ """
+ Returns True if this rule pool contains selfdep rules only, else False.
+ """
+ return all (
+ getattr ( rule, 'is_selfdep', None ) for rule in self.iter_rules()
+ )
+ # --- end of check_all_selfdep (...) ---
+
def empty ( self ):
"""Returns True if this pool has no rules."""
for rule in self.iter_rules():
@@ -178,25 +187,58 @@ class DependencyRulePoolBase ( object ):
pass
# --- end of accepts_other (...) ---
- def export_rules ( self ):
+ def export_deptype_header ( self, _is_all_selfdep=None ):
+ """
+ Returns a '#deptype ...' string describing this rule pool's deptype mask.
+ """
+ words = [
+ word for k, word in (
+ ( deptype.internal, "pkg" ),
+ ( deptype.external, "sys" ),
+ )
+ if k & self.deptype_mask
+ ]
+
+ if _is_all_selfdep or (
+ _is_all_selfdep is None and self.check_all_selfdep()
+ ):
+ words.append ( "selfdep" )
+
+ return "#deptype " + ( ",".join(words) if words else "none" )
+ # --- end of export_deptype_header (...) ---
+
+ def export_rules ( self, **kwargs ):
"""Exports all rules. Typically, this generates text lines."""
for rule in self.iter_rules():
- for item in rule.export_rule():
+ for item in rule.export_rule ( **kwargs ):
yield item
# --- end of export_rules (...) ---
- def export_rules_into ( self, fh ):
+ def export_rules_into ( self, fh, **kwargs ):
"""Writes all rules into the given file handle.
arguments:
* fh --
"""
NL = '\n'
- for item in self.export_rules():
+ for item in self.export_rules ( **kwargs ):
fh.write ( str ( item ) )
fh.write ( NL )
# --- end of exports_rules_into (...) ---
+ def export_to_str ( self ):
+ """Exports the rule pool (header + all rules) as a single str."""
+ NL = '\n'
+ all_selfdep = self.check_all_selfdep()
+
+ return NL.join ((
+ self.export_deptype_header ( _is_all_selfdep=all_selfdep ),
+ NL.join (
+ self.export_rules ( with_selfdep_keyword=(not all_selfdep) )
+ )
+ ))
+ # --- end of export_to_str (...) ---
+
# --- end of DependencyRulePoolBase ---
diff --git a/roverlay/depres/simpledeprule/abstractrules.py b/roverlay/depres/simpledeprule/abstractrules.py
index 37d3958..d31ffbe 100644
--- a/roverlay/depres/simpledeprule/abstractrules.py
+++ b/roverlay/depres/simpledeprule/abstractrules.py
@@ -119,7 +119,7 @@ class SimpleRule ( deprule.DependencyRule ):
pass
# --- end of noexport (...) ---
- def export_rule ( self ):
+ def export_rule ( self, with_selfdep_keyword=True ):
"""Generates text lines for this rule that can later be read using
the SimpleDependencyRuleReader.
"""
@@ -144,7 +144,7 @@ class SimpleRule ( deprule.DependencyRule ):
yield resolving
elif self.dep_alias:
- if self.is_selfdep == 1:
+ if with_selfdep_keyword and self.is_selfdep == 1:
yield '@selfdep'
if len ( self.dep_alias ) == 1:
diff --git a/roverlay/depres/simpledeprule/rulemaker.py b/roverlay/depres/simpledeprule/rulemaker.py
index 8a4acc5..d7f7163 100644
--- a/roverlay/depres/simpledeprule/rulemaker.py
+++ b/roverlay/depres/simpledeprule/rulemaker.py
@@ -33,6 +33,7 @@ class SimpleRuleMaker ( roverlay.util.mapreader.MapFileParser ):
self.logger = logging.getLogger ( self.__class__.__name__ )
self.DEPTYPE_MAP = {
+ 'none' : 0,
'all' : deptype.ALL,
'sys' : deptype.external,
'pkg' : deptype.internal,