view scripts/zeiterfassung.py @ 395:4bcf0bf118ff

templates/zeiterfassung2: improved: "category" instead of "project". Fixed missing newline before new workpackage.
author Bernhard Reiter <bernhard@intevation.de>
date Mon, 02 Mar 2015 12:17:28 +0100
parents 617ced8c7a40
children
line wrap: on
line source
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# zeiterfassung
# -------------
# (c) 2008 by Sascha L. Teichmann <sascha.teichmann@intevation.de>
# (c) 2011, 2012 by Björn Ricks <bjoern.ricks@intevation.de>
#
# Simple script which generates lines for zeiterfassung.txt files.
#
# This is Free Software licensed under the terms of GPLv3 or later.
# For details see LICENSE coming with the source of 'getan'.
#
import sys
import getopt
import codecs
import locale

from datetime import datetime, timedelta

from getan.template import render

DEFAULT_DATABASE = "time.db"

ZEITERFASSUNG_TEMPLATE = "zeiterfassung"

USAGE = '''usage: %s <options>
    with <options>
    [--user=|-u <user>]        : Name of user,           default: $USER
    [--database=|-d <database>]: getan database,         default: time.db
    [--project=|-p <key>]      : Key of output project,  default: all
    [--encoding=|-e encoding]  : encoding of output,     default: none
    [--week=]|-w <week>]       : week of year
    [--year=]|-y <year>]       : year
    [--list|-l]                : list all projects
    [--help|-h]                : This text
    [--emtpy|-m]               : show empty projects
    [--lastweek|-c]            : entries of last working week
    [--template|-t <template>] : jinja2 template to use, default: zeiterfassung
'''


def usage(exit_code=0):
    print USAGE % sys.argv[0],
    sys.exit(exit_code)


def main():

    database = DEFAULT_DATABASE
    user = None
    list_projects = False
    project = None
    encoding = None
    week = None
    year = None
    empty_proj = False
    database = None
    template = ZEITERFASSUNG_TEMPLATE

    opts, args = getopt.getopt(
        sys.argv[1:],
        'd:u:p:e:hl:w:y:mct:',
        ['database=', 'user=', 'project=', 'encoding=', 'help', 'list', 'week=',
            'year=', 'empty', 'lastweek', 'template='])

    for opt, val in opts:
        if opt in ("--database", "-d"):
            database = val
        elif opt in ("--user", "-u"):
            user = val
        elif opt in ("--project", "-p"):
            project = val
        elif opt in ("--encoding", "-e"):
            encoding = val
        elif opt in ("--help", "-h"):
            usage()
        elif opt in ("--list", "-l"):
            list_projects = True
        elif opt in ("--year", "-y"):
            year = int(val)
        elif opt in ("--week", "-w"):
            week = int(val)
        elif opt in ("--lastweek", "-c") and not week:
            week = (datetime.now() - timedelta(7)).isocalendar()[1]
        elif opt in ("--empty", "-m"):
            empty_proj = True
        elif opt in ("--template", "-t"):
            template = val

    if not encoding:
        encoding = locale.getdefaultlocale()[1]

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

    print render(user=user, database=database, week=week, year=year,
                 template=template, project=project, empty_projects=empty_proj)


if __name__ == '__main__':
    main()

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