view scripts/getan-eval.py @ 479:75131561d098

Add a redraw function on key Control-L.
author Magnus Schieder <mschieder@intevation.de>
date Wed, 16 May 2018 17:02:37 +0200
parents 59d9c5840273
children 999a438474f2
line wrap: on
line source
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# (c) 2013, 2014 by Björn Ricks <bjoern.ricks@intevation.de>
#
# This is Free Software licensed under the terms of GPLv3 or later.
# For details see LICENSE coming with the source of 'getan'.

import codecs
import locale
import sys

from datetime import date, datetime, timedelta
import argparse

from getan.template import render


def main():
    usage='getan-eval.py [options]'
    parser = argparse.ArgumentParser(prog='getan', usage=usage)

    parser.add_argument('-d', '--database', dest='database',metavar="DATABASE",
                        help='metavar="DATABASE')
    parser.add_argument('-t', '--template', dest='template',
                        metavar='TEMPLATE', help='name of getan template')
    parser.add_argument('-u', '--user', dest='user', help='name of user')
    parser.add_argument('-p', '--project', dest='project',
                        help='key of output project')
    parser.add_argument('-w', '--week', type=int, dest='week',
                        help='week of year')
    parser.add_argument('-y', '--year', type=int, dest='year', help='year')
    parser.add_argument('-c', '--lastweek', dest='lastweek',
                        help='entries of last working week',
                        action='store_true')
    parser.add_argument('-m', '--empty', dest='empty',
                        help='show projects without an entries',
                        action="store_true")
    parser.add_argument('--encoding', dest='encoding',
                        help='encoding of output', metavar='ENCODING')

    args = parser.parse_args()

    if args.lastweek:
        week = (datetime.now() - timedelta(7)).isocalendar()[1]
        year = int(date.today().strftime("%Y"))
    else:
        year = args.year
        week = args.week

    template_name = args.template or "wochenbericht"

    if not args.encoding:
        encoding = locale.getdefaultlocale()[1] or "utf-8"

    sys.stdout = codecs.getwriter(encoding)(sys.stdout.detach())

    user = None
    if args.user:
        user = args.user.decode(encoding)

    print(render(database=args.database, user=user,
                 template=template_name, year=year, week=week,
                 project=args.project, empty_projects=args.empty))


if __name__ == '__main__':
    main()

# vim:set ts=4 sw=4 si et sta sts=4 :
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)