2016-02-23 00:20:15 +00:00
|
|
|
#! /usr/bin/python
|
|
|
|
# -*- coding: utf8 -*-
|
|
|
|
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
|
2016-02-23 05:22:42 +00:00
|
|
|
import os
|
2016-02-23 00:20:15 +00:00
|
|
|
import sys
|
|
|
|
|
2016-02-23 05:22:42 +00:00
|
|
|
from tldp.utils import logger
|
2016-02-23 00:20:15 +00:00
|
|
|
|
2016-02-23 05:22:42 +00:00
|
|
|
import tldp.config
|
|
|
|
import tldp.inventory
|
2016-02-23 00:20:15 +00:00
|
|
|
|
2016-02-23 17:00:27 +00:00
|
|
|
from argparse import Namespace
|
2016-02-23 00:20:15 +00:00
|
|
|
|
2016-02-23 17:00:27 +00:00
|
|
|
|
|
|
|
def detail(config, args):
|
2016-02-23 05:22:42 +00:00
|
|
|
i = tldp.inventory.Inventory(config.pubdir, config.sourcedir)
|
2016-02-23 17:00:27 +00:00
|
|
|
width = Namespace()
|
|
|
|
width.status = max([len(x) for x in tldp.inventory.status_types])
|
|
|
|
width.stem = max([len(x) for x in i.source.keys()])
|
|
|
|
for arg in args:
|
|
|
|
status_class = tldp.inventory.status_classes[arg]
|
|
|
|
for status in status_class:
|
2016-02-23 05:22:42 +00:00
|
|
|
s = getattr(i, status, None)
|
|
|
|
assert s is not None
|
2016-02-23 17:00:27 +00:00
|
|
|
for stem, doc in s.items():
|
|
|
|
# -- a 'stale' or 'broken' document is implicitly a 'published'
|
|
|
|
# document as well, but we only want to list each document
|
|
|
|
# once
|
|
|
|
#
|
|
|
|
if doc.status == status:
|
|
|
|
doc.detail(width, config.verbose, file=sys.stdout)
|
2016-02-23 05:22:42 +00:00
|
|
|
return 0
|
|
|
|
|
|
|
|
|
2016-02-23 17:00:27 +00:00
|
|
|
def status(config, args):
|
2016-02-23 05:22:42 +00:00
|
|
|
i = tldp.inventory.Inventory(config.pubdir, config.sourcedir)
|
2016-02-23 17:00:27 +00:00
|
|
|
width = Namespace()
|
|
|
|
width.status = max([len(x) for x in tldp.inventory.status_types])
|
|
|
|
width.count = len(str(len(i.source.keys())))
|
2016-02-23 05:22:42 +00:00
|
|
|
for status in tldp.inventory.status_types:
|
|
|
|
if status == 'all':
|
|
|
|
continue
|
|
|
|
count = len(getattr(i, status, 0))
|
2016-02-23 17:00:27 +00:00
|
|
|
s = '{0:{w.status}} {1:{w.count}} '.format(status, count, w=width)
|
|
|
|
print(s, end="")
|
|
|
|
if config.verbose:
|
|
|
|
print('\t'.join(getattr(i, status).keys()))
|
|
|
|
else:
|
|
|
|
abbrev = getattr(i, status).keys()
|
|
|
|
displaynum = 3
|
|
|
|
if len(abbrev) > displaynum:
|
|
|
|
abbrev = abbrev[:displaynum]
|
|
|
|
remainder = count - displaynum
|
|
|
|
abbrev.append('[and %d more]' % (remainder,))
|
|
|
|
print('\t'.join(abbrev))
|
2016-02-23 05:22:42 +00:00
|
|
|
return 0
|
2016-02-23 00:20:15 +00:00
|
|
|
|
|
|
|
|
2016-02-23 17:00:27 +00:00
|
|
|
def build(config, args):
|
2016-02-23 05:22:42 +00:00
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
def run():
|
|
|
|
tag = os.path.basename(sys.argv[0]).strip('.py')
|
|
|
|
argv = sys.argv[1:]
|
2016-02-23 17:00:27 +00:00
|
|
|
config, args = tldp.config.collectconfiguration(tag, argv)
|
2016-02-23 05:22:42 +00:00
|
|
|
|
|
|
|
# -- first, and foremost, set requested logging level
|
|
|
|
#
|
|
|
|
logger.setLevel(config.loglevel)
|
2016-02-23 17:00:27 +00:00
|
|
|
|
2016-02-23 05:22:42 +00:00
|
|
|
# -- check to see if the user wishes to --list things
|
|
|
|
# this function and friends is called 'detail', because
|
|
|
|
# Python reserves a special (fundamental) meaning for the word
|
|
|
|
# list; but for the end-user they are synonyms
|
|
|
|
#
|
|
|
|
if config.detail:
|
2016-02-23 17:00:27 +00:00
|
|
|
sys.exit(detail(config, args))
|
2016-02-23 00:20:15 +00:00
|
|
|
|
2016-02-23 05:22:42 +00:00
|
|
|
# -- check to see if the user wants --status output
|
|
|
|
#
|
|
|
|
if config.status:
|
|
|
|
if config.pubdir is None:
|
|
|
|
sys.exit("Option --pubdir required for --status.")
|
|
|
|
if not config.sourcedir:
|
|
|
|
sys.exit("Option --sourcedir required for --status.")
|
2016-02-23 17:00:27 +00:00
|
|
|
sys.exit(status(config, args))
|
2016-02-23 00:20:15 +00:00
|
|
|
|
2016-02-23 05:22:42 +00:00
|
|
|
# -- our primary action is to try to build
|
|
|
|
if config.build is None:
|
|
|
|
config.all = True
|
2016-02-23 17:00:27 +00:00
|
|
|
sys.exit(build(config, args))
|
2016-02-23 00:20:15 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# -- end of file
|