def test_detect_status_broken(self): c = self.config ex = random.choice(example.sources) self.add_broken('Frobnitz-Broken-HOWTO', ex) i = Inventory(c.pubdir, c.sourcedir) self.assertEqual(0, len(i.stale)) self.assertEqual(1, len(i.published)) self.assertEqual(0, len(i.new)) self.assertEqual(0, len(i.orphan)) self.assertEqual(1, len(i.broken))
def test_status_class_accessors(self): c = self.config ex = random.choice(example.sources) self.add_published('Published-HOWTO', ex) self.add_new('New-HOWTO', ex) self.add_stale('Stale-HOWTO', ex) self.add_orphan('Orphan-HOWTO', ex) self.add_broken('Broken-HOWTO', ex) i = Inventory(c.pubdir, c.sourcedir) self.assertTrue('Orphan-HOWTO' in i.orphans.keys()) self.assertTrue('Orphan-HOWTO' in i.orphaned.keys()) self.assertTrue(3, len(i.problems.keys())) self.assertTrue(4, len(i.work.keys())) self.assertTrue(5, len(i.all.keys())) self.assertTrue(5, len(i.sources.keys())) self.assertTrue(5, len(i.outputs.keys()))
def summary(config, *args, **kwargs): if args: return ERR_EXTRAARGS + ' '.join(args) if not config.pubdir: return ERR_NEEDPUBDIR + "for --summary" if not config.sourcedir: return ERR_NEEDSOURCEDIR + "for --summary" file = kwargs.get('file', sys.stdout) inv = kwargs.get('inv', None) if inv is None: inv = Inventory(config.pubdir, config.sourcedir) width = Namespace() width.doctype = max([len(x.__name__) for x in knowndoctypes]) width.status = max([len(x) for x in status_types]) width.count = len(str(len(inv.source.keys()))) print('By Document Status (STATUS)', '---------------------------', sep='\n', file=file) for status in status_types: count = len(getattr(inv, status, 0)) s = '{0:{w.status}} {1:{w.count}} '.format(status, count, w=width) print(s, end="", file=file) if config.verbose: print(', '.join(getattr(inv, status).keys()), file=file) else: abbrev = getattr(inv, status).keys() s = '' if abbrev: s = s + abbrev.pop(0) while abbrev: if (len(s) + len(abbrev[0])) > 48: break s = s + ', ' + abbrev.pop(0) if abbrev: s = s + ', and %d more ...' % (len(abbrev)) print(s, file=file) print('', 'By Document Type (DOCTYPE)', '--------------------------', sep='\n', file=file) summarybytype = collections.defaultdict(list) for doc in inv.source.values(): name = doc.doctype.__name__ summarybytype[name].append(doc.stem) for doctype, docs in summarybytype.items(): count = len(docs) s = '{0:{w.doctype}} {1:{w.count}} '.format(doctype, count, w=width) print(s, end="", file=file) if config.verbose: print(', '.join(docs), file=file) else: abbrev = docs s = '' if abbrev: s = s + abbrev.pop(0) while abbrev: if (len(s) + len(abbrev[0])) > 36: break s = s + ', ' + abbrev.pop(0) if abbrev: s = s + ', and %d more ...' % (len(abbrev)) print(s, file=file) print('', file=file) return os.EX_OK
def collectWorkset(config, args): # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # -- argument handling logic; try to avoid creating an inventory unless it # is necessary # workset, remainder = extractExplicitDocumentArgs(config, args) stati, remainder = getStatusNames(remainder) if len(workset): logger.info("Added %d explicit file paths from args.", len(workset)) need_inventory = False if remainder or stati: need_inventory = True if not workset: need_inventory = True # -- We only --list, --script, --build, or --publish on work-to-be-done # so, if there have been no special arguments at this point, we will # simply grab the work to be done; see below the line that says: # # docs = inv.work.values() # # -- also make one last check to see that config.pubdir and # config.sourcedir are set appropriately; just before creating an # Inventory # if need_inventory: if not config.pubdir: return None, ERR_NEEDPUBDIR + "for inventory" if not config.sourcedir: return None, ERR_NEEDSOURCEDIR + "for inventory" inv = Inventory(config.pubdir, config.sourcedir) logger.info("Inventory contains %s source and %s output documents.", len(inv.source.keys()), len(inv.output.keys())) else: inv = None if stati: docs = getDocumentsByStatus(inv.all.values(), stati) workset.update(docs) if docs: logger.info("Added %d docs, found by status class .", len(docs)) unknownargs = None if remainder: docs, unknownargs = getDocumentsByStems(inv.all.values(), remainder) workset.update(docs) logger.info("Added %d docs, found by stem name.", len(docs)) if unknownargs: return None, ERR_UNKNOWNARGS + ' '.join(unknownargs) # -- without any arguments (no files, no stems, no status_classes), the # default behaviour is to either --build, --list or --script any # available work, i.e. documents that have status new, orphan, broken, # or stale. # if not workset: if not stati and not remainder: workset.update(inv.work.values()) # -- and, of course, apply the skipping logic # workset, _ = processSkips(config, workset) docs = sorted(workset, key=lambda x: x.stem.lower()) return docs, None
def test_inventory_repr(self): c = self.config ex = random.choice(example.sources) self.add_published('Frobnitz-HOWTO', ex) i = Inventory(c.pubdir, c.sourcedir) self.assertTrue('1 published' in str(i))