re_split_name = re.compile(r'^\s*([a-z0-9]+)[-/_](\S+)\s*$', re.IGNORECASE)
re_mod_pf_line = re.compile(r'\s*mod\s+\'([^\']+)\'\s*,\s*(\S+.*)\s*$', re.IGNORECASE)
+ re_pf_line_version = re.compile(r"^\s*'([^']+)'")
+ re_def_token = re.compile(r'^\s*(?:,\s*)?([^,]+)(?:\s*,|$)')
+ re_empty = re.compile(r'^\s*(?:,\s*)?$')
+ re_key_val_pair = re.compile(r"^\s*:?([a-z]+)\s*=>\s*'([^']+)'\s*$", re.IGNORECASE)
+ re_v_at_start = re.compile(r"^v", re.IGNORECASE)
# -------------------------------------------------------------------------
def __init__(
self._full_name_orig = None
self._version_upstream = None
self.local_versions = {}
+ self.expected_versions = {}
+ self.repo = None
super(ModuleInfo, self).__init__(
appname=appname, verbose=verbose, version=version,
LOG.warn("{c}: {e}".format(c=e.__class__.__name__, e=e))
return None
+ match = cls.re_pf_line_version.search(mod_def)
+ if match:
+ module_info.expected_versions[env] = match.group(1)
+ else:
+ definitions = cls.get_module_definitions(mod_def, verbose=verbose)
+ if 'git' in definitions:
+ module_info.repo = definitions['git']
+ if 'tag' in definitions:
+ tag = cls.re_v_at_start.sub('', definitions['tag'])
+ module_info.expected_versions[env] = tag
+ elif 'ref' in definitions:
+ tag = cls.re_v_at_start.sub('', definitions['ref'])
+ module_info.expected_versions[env] = tag
+ elif 'branch' in definitions:
+ module_info.expected_versions[env] = definitions['branch']
+ elif 'commit' in definitions:
+ module_info.expected_versions[env] = 'commit-id'
+
module_info.initialized = True
- if verbose > 2:
+ if verbose > 3:
LOG.debug("Initialized {c} object:\n{s}".format(
c=module_info.__class__.__name__, s=pp(module_info.as_dict())))
return module_info
+ # -------------------------------------------------------------------------
+ @classmethod
+ def get_module_definitions(cls, mod_def, verbose=0):
+
+ if verbose > 3:
+ LOG.debug("Analyzing definitions from:\n{}".format(mod_def))
+ tokens = []
+ defs = {}
+
+ rest = mod_def
+ while not cls.re_empty.search(rest):
+ if verbose > 4:
+ LOG.debug("Current def rest: {!r}.".format(rest))
+ match = cls.re_def_token.search(rest)
+ if match:
+ token = match.group(1)
+ rest = cls.re_def_token.sub('', rest)
+ tokens.append(token)
+ else:
+ LOG.warn("Could not analyze definitions in {!r}".format(rest))
+ break
+
+ if verbose > 4:
+ LOG.debug("Got def tokens:\n{}".format(pp(tokens)))
+
+ for token in tokens:
+ match = cls.re_key_val_pair.match(token)
+ if match:
+ key = match.group(1)
+ val = match.group(2)
+ defs[key] = val
+ else:
+ LOG.warn("Could not analyze definition token {!r}.".format(token))
+
+ if verbose > 4:
+ LOG.debug("Got definitions:\n{}".format(pp(defs)))
+
+ return defs
+
# =============================================================================
if __name__ == "__main__":