aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'roverlay/rpackage')
-rw-r--r--roverlay/rpackage/descriptionfields.py22
-rw-r--r--roverlay/rpackage/descriptionreader.py123
2 files changed, 92 insertions, 53 deletions
diff --git a/roverlay/rpackage/descriptionfields.py b/roverlay/rpackage/descriptionfields.py
index bccc3df..dcb0803 100644
--- a/roverlay/rpackage/descriptionfields.py
+++ b/roverlay/rpackage/descriptionfields.py
@@ -132,7 +132,9 @@ class DescriptionField ( object ):
# --- end of set_default_value (...) ---
def get_flags ( self ):
- """Returns the flags of this DescriptionField or an empty list (=no flags)."""
+ """Returns the flags of this DescriptionField or
+ an empty list (=no flags).
+ """
return self.flags
# --- end of get_flags (...) ---
@@ -146,17 +148,19 @@ class DescriptionField ( object ):
# --- end of get_allowed_values (...) ---
def matches ( self, field_identifier ):
- """Returns whether field_identifier equals the name of this DescriptionField.
+ """Returns whether field_identifier equals the name of this field.
arguments:
* field_identifier --
"""
- return bool ( self.name == field_identifier ) if field_identifier else False
-
+ if field_indentifier:
+ return bool ( self.name == field_identifier )
+ else:
+ return False
# --- end of matches (...) ---
def matches_alias ( self, field_identifier ):
- """Returns whether field_identifier equals any alias of this DescriptionField.
+ """Returns whether field_identifier equals any alias of this field.
arguments:
* field_identifier --
@@ -215,8 +219,8 @@ class DescriptionField ( object ):
class DescriptionFields ( object ):
- """DescriptionFields stores several instances of DescriptionField and provides
- 'search in all' methods such as get_fields_with_flag (<flag>).
+ """DescriptionFields stores several instances of DescriptionField and
+ provides 'search in all' methods such as get_fields_with_flag (<flag>).
"""
def __init__ ( self ):
@@ -266,8 +270,8 @@ class DescriptionFields ( object ):
# --- end of get (...) ---
def find_field ( self, field_name ):
- """Determines the name of the DescriptionField to which field_name belongs
- to. Returns the name of the matching field or None.
+ """Determines the name of the DescriptionField to which field_name
+ belongs to. Returns the name of the matching field or None.
arguments:
* field_name --
diff --git a/roverlay/rpackage/descriptionreader.py b/roverlay/rpackage/descriptionreader.py
index e700907..c9daeb8 100644
--- a/roverlay/rpackage/descriptionreader.py
+++ b/roverlay/rpackage/descriptionreader.py
@@ -51,23 +51,29 @@ class DescriptionReader ( object ):
# insert default values
default_values = self.field_definition.get_fields_with_default_value()
+
for field_name in default_values.keys():
if not field_name in read_data:
read_data [field_name] = default_values [field_name]
# join values to a single string
- for field_name in self.field_definition.get_fields_with_flag ( 'joinValues' ):
-
+ for field_name in \
+ self.field_definition.get_fields_with_flag ( 'joinValues' ) \
+ :
if field_name in read_data:
read_data [field_name] = ' ' . join ( read_data [field_name] )
# ensure that all mandatory fields are set
missing_fields = set ()
- for field_name in self.field_definition.get_fields_with_flag ( 'mandatory' ):
+ for field_name in \
+ self.field_definition.get_fields_with_flag ( 'mandatory' ):
+
if field_name in read_data:
- if read_data [field_name] is None or len ( read_data [field_name] ) < 1:
+ if read_data [field_name] is None or \
+ len ( read_data [field_name] ) < 1 \
+ :
missing_fields.add ( field_name )
#else: ok
else:
@@ -77,10 +83,14 @@ class DescriptionReader ( object ):
# check for fields that allow only certain values
unsuitable_fields = set()
- restricted_fields = self.field_definition.get_fields_with_allowed_values()
+ restricted_fields = \
+ self.field_definition.get_fields_with_allowed_values()
+
for field_name in restricted_fields:
if field_name in read_data:
- if not self.field_definition.get ( field_name ).value_allowed ( read_data [field_name] ):
+ if not self.field_definition.get ( field_name ) . value_allowed (
+ read_data [field_name]
+ ):
unsuitable_fields.add ( field_name )
# summarize results
@@ -88,16 +98,23 @@ class DescriptionReader ( object ):
if not valid:
self.logger.info ( "Cannot use R package" ) # name?
if len ( missing_fields ):
- self.logger.debug ( "The following mandatory description fields are missing: %s.", str ( missing_fields ) )
+ self.logger.debug (
+ "The following mandatory description fields are missing: %s."
+ % missing_fields
+ )
if len ( unsuitable_fields ):
- self.logger.debug ( "The following fields have unsuitable values: %s.", str ( unsuitable_fields ) )
+ self.logger.debug (
+ "The following fields have unsuitable values: %s."
+ % unsuitable_fields
+ )
return valid
# --- end of _parse_read_data (...) ---
def run ( self ):
- """Reads a DESCRIPTION file and returns the read data if successful, else None.
+ """Reads a DESCRIPTION file and returns the read data if successful,
+ else None.
arguments:
* file -- path to the tarball file (containing the description file)
@@ -117,11 +134,12 @@ class DescriptionReader ( object ):
"""Extracts relevant data from value_str and returns them as list.
arguments:
- * value_str -- string that represents the (just read) values
- * field_context -- field name the value belongs to; optional, defaults to None
+ * value_str -- string that represents the (just read) values
+ * field_context -- field name the value belongs to;
+ optional, defaults to None
- It's useful to set field_context 'cause several fields ('Depends') have
- multiple values arranged in a list (dep0, dep1 [, depK]*).
+ It's useful to set field_context 'cause several fields ('Depends')
+ have multiple values arranged in a list (dep0, dep1 [, depK]*).
"""
svalue_str = value_str.strip()
@@ -134,20 +152,22 @@ class DescriptionReader ( object ):
# default return if no context given
return [ svalue_str ]
- elif field_context in self.field_definition.get_fields_with_flag ( 'isList' ):
- # split up this list (that is separated by commata and/or semicolons)
- # *beware*/fixme: py3, filter returns filter object
- return filter ( None, re.split (
- config.get ( 'DESCRIPTION.list_split_regex' ),
- svalue_str,
- 0
- ) )
-
- elif field_context in self.field_definition.get_fields_with_flag ( 'isWhitespaceList' ):
- # split up this list (that is separated whitespace)
- return filter ( None, re.split ( '\s+', svalue_str, 0 ) )
-
-
+ elif field_context in \
+ self.field_definition.get_fields_with_flag ( 'isList' ) \
+ :
+ # split up this list (separated by commata and/or semicolons)
+ # *beware*/fixme: py3, filter returns filter object
+ return filter ( None, re.split (
+ config.get ( 'DESCRIPTION.list_split_regex' ),
+ svalue_str,
+ 0
+ ) )
+
+ elif field_context in \
+ self.field_definition.get_fields_with_flag ( 'isWhitespaceList' ) \
+ :
+ # split up this list (separated by whitespace)
+ return filter ( None, re.split ( '\s+', svalue_str, 0 ) )
# default return
return [ svalue_str ]
@@ -160,15 +180,15 @@ class DescriptionReader ( object ):
arguments:
* filepath -- file to read (str; path to tarball or file)
* pkg_name -- name of the package, in tarballs the description file
- is located in <pkg_name>/ and thus this argument is required.
- Defaults to '.', set to None to disable.
+ is located in <pkg_name>/ and thus this argument
+ is required. Defaults to '.', set to None to disable.
All exceptions are passed to the caller (TarError, IOErr, <custom>).
<filepath> can either be a tarball in which case the real DESCRIPTION
file is read (<pkg_name>/DESCRIPTION) or a normal file.
"""
- self.logger.debug ( "Starting to read file '" + str ( filepath ) + "' ...\n" )
+ self.logger.debug ( "Starting to read file '%s' ...\n" % filepath )
if not ( isinstance ( filepath, str ) and filepath ):
raise Exception ( "bad usage" )
@@ -222,13 +242,15 @@ class DescriptionReader ( object ):
field_context = None
+ comment_chars = config.get ( 'DESCRIPTION.comment_chars', '#' )
+
for line in desc_lines:
field_context_ref = None
# using s(tripped)line whenever whitespace doesn't matter
sline = line.lstrip()
- if (not sline) or (line [0] == config.get ( 'DESCRIPTION.comment_char' ) ):
+ if not sline or line [0] in comment_chars:
# empty line or comment
pass
@@ -248,15 +270,21 @@ class DescriptionReader ( object ):
# line introduces a new field context, forget last one
field_context = None
- line_components = sline.partition ( config.get ( 'DESCRIPTION.field_separator' ) )
+ line_components = sline.partition (
+ config.get ( 'DESCRIPTION.field_separator' )
+ )
if line_components [1]:
# line contains a field separator, set field context
- field_context_ref = self.field_definition.get ( line_components [0] )
+ field_context_ref = self.field_definition.get (
+ line_components [0]
+ )
if field_context_ref is None:
# useless line, skip
- self.logger.info ( "Skipped a description field: '%s'.", line_components [0] )
+ self.logger.info (
+ "Skipped a description field: '%s'.", line_components [0]
+ )
elif field_context_ref.has_flag ( 'ignore' ):
# field ignored
self.logger.debug ( "Ignored field '%s'.", field_context )
@@ -265,31 +293,38 @@ class DescriptionReader ( object ):
field_context = field_context_ref.get_name()
if not field_context:
- raise Exception ( "Field name is not valid! This should've already been catched in DescriptionField..." )
+ raise Exception (
+ 'Field name is not valid! This should\'ve '
+ 'already been catched in DescriptionField...'
+ )
# create a new empty list for this field_context
read_data [field_context] = []
- # add values to read_data
- # no need to check line_components [2] 'cause [1] was a true str
- for val in make_values ( line_components [2], field_context ):
+ # add values to read_data, no need to check
+ # line_components [2] 'cause [1] was a true str
+ for val in \
+ make_values ( line_components [2], field_context ) \
+ :
read_data [field_context] . append ( val )
-
-
else:
# reaching this branch means that
# (a) line has no leading whitespace
# (b) line has no separator (:)
# this should not occur in description files (bad syntax?)
- self.logger.warning ( "Unexpected line in description file: '%s'.", line_components [0] )
+ self.logger.warning (
+ "Unexpected line in description file: '%s'."
+ % line_components [0]
+ )
# -- end for --
if self._parse_read_data ( read_data ):
- self.logger.debug ( "Successfully read file '%s' with data = %s.",
- self.fileinfo ['package_file'], str ( read_data )
- )
+ self.logger.debug (
+ "Successfully read file '%s' with data = %s."
+ % ( self.fileinfo ['package_file'], read_data )
+ )
self.desc_data = read_data
# get_desc() is preferred, but this method returns the desc data, too