view scripts/getan-report @ 536:a59622c06936

Fix generating reports if no week given unix_week() cannot handle week being None but does so for year. It just assumes the current year in this case, although this only duplicates the initialisation of year with c_year in this context. week being None gives TypeError: unsupported operand type(s) for -: 'NoneType' and 'int' load_entries() handles the case with no week given, thus call it anyhow. This fix makes it possible to invoke scripts/getan-report with a year given but no week and seeing the expected result (data for a whole year) instead of a traceback.
author Tom Gottfried <tom@intevation.de>
date Thu, 09 Jan 2020 11:32:34 +0100
parents d5acadeef0f8
children 28b1c18c900f
line wrap: on
line source
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# (c) 2013, 2014 by Björn Ricks <bjoern.ricks@intevation.de>
#     2019, 2020 Intevation GmbH
# Author(s):
#   * Björn Ricks
#   * Magnus Schieder
#
# 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
from getan.backend import DEFAULT_DATABASE


def main():
    usage='getan-report [options]'
    parser = argparse.ArgumentParser(prog='getan', usage=usage,
            description="You can find more information at https://pypi.org/project/getan/")

    parser.add_argument('-d', '--database', metavar="DATABASE_FILE",
                        help='(default: ~/.getan/%(default)s)]',
                        default=DEFAULT_DATABASE)
    parser.add_argument('-t', '--template',
                        help="""name of getan template (wochenbericht,
                                zeiterfassung, zeiterfassung2),
                                external templates must be stored in
                                ~/.getan/templates/ to be able to call them.""")
    parser.add_argument('-u', '--user', help='name of user')
    parser.add_argument('-p', '--project', help='key of output project')
    parser.add_argument('-w', '--week', type=int, help='week of year')
    parser.add_argument('-y', '--year', type=int, help='year')
    parser.add_argument('-c', '--lastweek', help='entries of last working week',
                        action='store_true')
    parser.add_argument('-m', '--empty',
                        help='show projects without an entry',
                        action="store_true")
    parser.add_argument('--encoding', help='encoding of output')

    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

    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)