import copy
import json
import datetime
+import re
# Third party modules
import six
if is_sequence(self.query['vendor']):
for vendor in self.query['vendor']:
v = vendor.strip().lower()
- if v:
+ if v and v not in q_vendors:
q_vendors.append(v)
else:
v = self.query['vendor'].strip().lower()
- if v:
+ if v and v not in q_vendors:
q_vendors.append(v)
if q_vendors:
if self.filters is None:
self.filters = {}
self.filters['vendor'] = q_vendors
+ if 'name' in self.query:
+ q_names = []
+ if is_sequence(self.query['name']):
+ for name in self.query['name']:
+ v = name.strip().lower()
+ if v and v not in q_names:
+ q_names.append(v)
+ else:
+ v = self.query['name'].strip().lower()
+ if v and v not in q_names:
+ q_names.append(v)
+ if q_names:
+ if self.filters is None:
+ self.filters = {}
+ self.filters['name'] = q_names
+
+ if 're' in self.query:
+ q_re = []
+ if is_sequence(self.query['re']):
+ for regex in self.query['re']:
+ v = regex.strip()
+ if v:
+ q_re.append(v)
+ else:
+ v = self.query['re'].strip()
+ if v:
+ q_re.append(v)
+ if q_re:
+ if self.filters is None:
+ self.filters = {}
+ for regex in q_re:
+ regex_compiled = None
+ try:
+ regex_compiled = re.compile(regex, re.IGNORECASE)
+ except Exception as e:
+ LOG.error("{c}: Invalid regular expression {r!r}: {e}".format(
+ c=e.__class__.__name__, r=regex, e=e))
+ else:
+ if 're' not in self.filters:
+ self.filters['re'] = []
+ if regex_compiled not in self.filters['re']:
+ self.filters['re'].append(regex_compiled)
# -------------------------------------------------------------------------
def run(self):
self.output_modules_json(module_infos)
elif self.output_type == 'html':
self.output_modules_html(module_infos)
+ else:
+ self.output_modules_txt(module_infos)
# -------------------------------------------------------------------------
def output_modules_json(self, module_infos):
# -------------------------------------------------------------------------
def output_modules_html(self, module_infos):
+ if not module_infos:
+ self.print_out()
+ self.print_out('<h2>Keine passenden Module gefunden.</h2>')
+ self.print_out()
+ return
+
self.print_out('<table>')
self.print_out(' <colgroup span="9"></colgroup>')
self.print_out(' <thead>')
msg = "<br/>Insgesamt <b>{nr} Modul{e}</b> gefunden.".format(nr=nr_modules, e=plural_e)
self.print_out(msg)
+ # -------------------------------------------------------------------------
+ def output_modules_txt(self, module_infos):
+
+ if not module_infos:
+ self.print_out()
+ self.print_out('Keine passenden Module gefunden.')
+ self.print_out()
+ return
+
+ label = {
+ 'name': 'Name',
+ 'full_name': 'Vollständiger Name',
+ 'repo': "Repository",
+ 'forge_version': 'Puppet Forge',
+ 'version_development': 'Development',
+ 'version_test': 'Test',
+ 'version_production': 'Production',
+ 'date_checked': 'Letzter Check',
+ }
+
+ if self.verbose > 2:
+ LOG.debug("Labels:\n{}".format(pp(label)))
+
+ width = {}
+ for key in label.keys():
+ width[key] = len(label[key])
+
+ if self.verbose > 2:
+ LOG.debug("Breiten vor Ermittlung:\n{}".format(pp(width)))
+
+ nr_modules = 0
+
+ for module_info in module_infos:
+ nr_modules += 1
+ output_data = self.get_output_data(module_info)
+ for key in label.keys():
+ wi = width[key]
+ txt = output_data.get(key, '')
+ if txt is not None and len(txt) > wi:
+ width[key] = len(txt)
+
+ if self.verbose > 2:
+ LOG.debug("Breiten nach Ermittlung:\n{}".format(pp(width)))
+
+ tpl = "{{name:<{name}}} | "
+ tpl += "{{full_name:<{full_name}}} | "
+ tpl += "{{repo:<{repo}}} | "
+ tpl += "{{forge_version:^{forge_version}}} | "
+ tpl += "{{version_development:^{version_development}}} | "
+ tpl += "{{version_test:^{version_test}}} | "
+ tpl += "{{version_production:^{version_production}}} | "
+ tpl += "{{date_checked:<{date_checked}}}"
+
+ tpl = tpl.format(**width)
+
+ if self.verbose > 2:
+ LOG.debug("Zeilen-Template:\n{}".format(tpl))
+
+ plural_e = 'e'
+ if nr_modules == 1:
+ plural_e = ''
+ msg = "\nInsgesamt {nr} Modul{e} gefunden:\n".format(nr=nr_modules, e=plural_e)
+ self.print_out(msg)
+
+ self.print_out()
+ header = tpl.format(**label)
+ self.print_out(header)
+ self.print_out('=' * len(header))
+
+ for module_info in module_infos:
+ nr_modules += 1
+ output_data = self.get_output_data(module_info)
+ if not output_data['forge_version']:
+ output_data['forge_version'] = '~'
+ if not output_data['forge_homepage_url']:
+ output_data['forge_homepage_url'] = '~'
+ if not output_data['repo']:
+ output_data['repo'] = '~'
+ self.print_out(tpl.format(**output_data))
+
+ self.print_out()
+
# -------------------------------------------------------------------------
def get_output_data(self, module_info):
'version_test': module_info.local_version_output('test'),
'version_production': module_info.local_version_output('production'),
}
- if self.verbose > 2:
+ if self.verbose > 3:
LOG.debug("Output data:\n{}".format(pp(output_data)))
return output_data
if self.verbose > 3:
LOG.debug("Content of {f!r}:\n{c}".format(f=self.cache_file, c=pp(data)))
if not data:
- raise ShowModulesUncriticalError(
- "Cache file {!r} has no content.".format(self.cache_file))
+ LOG.debug("Did not found any matching modules.")
return data
if not do_display:
return False
+ do_display = False
+ if 'name' in self.filters:
+ for name in self.filters['name']:
+ if name == module_info.name:
+ do_display = True
+ break
+ if not do_display:
+ return False
+
+ do_display = False
+ if 're' in self.filters:
+ for regex in self.filters['re']:
+ if regex.search(module_info.full_name):
+ do_display = True
+ break
+ if not do_display:
+ return False
+
return True
# =============================================================================