view scripts/zeiterfassung.py @ 385:cf0406ed424a

Update copyright and remove empty lines
author Björn Ricks <bjoern.ricks@intevation.de>
date Mon, 05 Jan 2015 11:07:39 +0100
parents 20fde79f8e12
children b8cd8751cba0
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'''


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:mc',
        ['database=', 'user=', 'project=', 'encoding=', 'help', 'list', 'week=',
            'year=', 'empty', 'lastweek'])

    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 = 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

    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)