def analyze_rst(*packages): """ Example: >>> from lino.utils.code import analyze_rst >>> print analyze_rst('lino') """ fields = 'count_code count_doc count_comment count_total'.split() headers = [ "name", "code lines", "doc lines", "comment lines", "total lines" ] rows = [] total_sums = [0] * len(fields) for package in packages: sums = [0] * len(fields) for name, filename in codefiles(package + '*'): sf = SourceFile(name, filename) for i, k in enumerate(fields): sums[i] += getattr(sf, k) rows.append([package] + [str(n) for n in sums]) for i, k in enumerate(fields): total_sums[i] += sums[i] rows.append(['total'] + [str(n) for n in total_sums]) return rstgen.table(headers, rows)
def model_overview(model): headers = ["name", "type"] #~ formatters = [ #~ lambda f: f.name, #~ lambda f: f.__class__.__name__, #~ ] headers.append("verbose name") #~ for lng in babel.AVAILABLE_LANGUAGES: #~ headers.append("verbose name (" + lng + ")") #~ headers.append("help text") #~ formatters.append(lambda f: f.help_text) def verbose_name(f): settings.SITE.set_language(None) label_en = force_unicode(_(f.verbose_name)) babel_labels = [] for lng in settings.SITE.languages[1:]: dbutils.set_language(lng.django_code) label = force_unicode(_(f.verbose_name)) if label != label_en: babel_labels.append(label) if babel_labels: label_en += " (%s)" % ",".join(babel_labels) return label_en def rowfmt(f): cells = [ f.name, fieldtype(f), verbose_name(f) ] #~ for lng in babel.AVAILABLE_LANGUAGES: #~ babel.set_language(lng) #~ cells.append(force_unicode(_(f.verbose_name))) #~ cells.append(f.help_text) return cells rows = [rowfmt(f) for f in model._meta.fields] s = rstgen.table(headers, rows) model_reports = [r for r in dbtables.master_reports if r.model is model] if model_reports: s += '\n\nMaster tables: %s\n\n' % rptlist(model_reports) if getattr(model, '_lino_slaves', None): s += '\n\nSlave tables: %s\n\n' % rptlist(model._lino_slaves.values()) #~ s += '\n\nSlave reports: ' #~ s += ', '.join([name for name,rpt in model._lino_slaves.items()]) #~ s += '\n\n' return s
def model_overview(model): headers = ["name", "type"] #~ formatters = [ #~ lambda f: f.name, #~ lambda f: f.__class__.__name__, #~ ] headers.append("verbose name") #~ for lng in babel.AVAILABLE_LANGUAGES: #~ headers.append("verbose name (" + lng + ")") #~ headers.append("help text") #~ formatters.append(lambda f: f.help_text) def verbose_name(f): settings.SITE.set_language(None) label_en = force_text(_(f.verbose_name)) babel_labels = [] for lng in settings.SITE.languages[1:]: dbutils.set_language(lng.django_code) label = force_text(_(f.verbose_name)) if label != label_en: babel_labels.append(label) if babel_labels: label_en += " (%s)" % ",".join(babel_labels) return label_en def rowfmt(f): cells = [f.name, fieldtype(f), verbose_name(f)] #~ for lng in babel.AVAILABLE_LANGUAGES: #~ babel.set_language(lng) #~ cells.append(force_text(_(f.verbose_name))) #~ cells.append(f.help_text) return cells rows = [rowfmt(f) for f in model._meta.fields] s = rstgen.table(headers, rows) model_reports = [r for r in kernel.master_tables if r.model is model] if model_reports: s += '\n\nMaster tables: %s\n\n' % rptlist(model_reports) if getattr(model, '_lino_slaves', None): s += '\n\nSlave tables: %s\n\n' % rptlist( list(model._lino_slaves.values())) #~ s += '\n\nSlave reports: ' #~ s += ', '.join([name for name,rpt in model._lino_slaves.items()]) #~ s += '\n\n' return s
def analyze_rst(*packages): """ Example: >>> from lino.utils.code import analyze_rst >>> print analyze_rst('lino') """ fields = 'count_code count_doc count_comment count_total'.split() headers = ["name"] + fields rows = [] total_sums = [0] * len(fields) for package in packages: sums = [0] * len(fields) for name, filename in codefiles(package + '*'): sf = SourceFile(name, filename) for i, k in enumerate(fields): sums[i] += getattr(sf, k) rows.append([package] + [str(n) for n in sums]) for i, k in enumerate(fields): total_sums[i] += sums[i] rows.append(['total'] + [str(n) for n in total_sums]) return rstgen.table(headers, rows)