[Getan-commits] [PATCH 1 of 3] Update coding style for pep8

Wald Commits scm-commit at wald.intevation.org
Mon Jan 26 14:11:09 CET 2015


# HG changeset patch
# User Björn Ricks <bjoern.ricks at intevation.de>
# Date 1422274192 -3600
# Node ID 0fd096670ae72fddd53d595acf7427bba19d5621
# Parent  b8cd8751cba097f75cc561e288ffb4a937cd2771
Update coding style for pep8

diff -r b8cd8751cba0 -r 0fd096670ae7 scripts/getan-report.py
--- a/scripts/getan-report.py	Tue Jan 06 10:18:44 2015 +0100
+++ b/scripts/getan-report.py	Mon Jan 26 13:09:52 2015 +0100
@@ -1,5 +1,8 @@
 #!/usr/bin/env python3
-"""write a daily report accessing a database from http://hg.intevation.de/getan 1.1dev3."""
+"""
+write a daily report accessing a database from
+http://hg.intevation.de/getan 1.1dev3.
+"""
 # hastily done, written to learn the getan database format and its manipulation
 # Free Software under GNU GPL v>=3
 # 20130109 bernhard at intevation.de
@@ -13,49 +16,50 @@
 #   added command line options, requires argparse module now (e.g. Python>=3.2)
 # 20141104 bernhard at intevation.de:
 #   migration to argparse complete, added -t option
-# TODO: 
+# TODO:
 #  * use python v>=3.2 variants in the code where noted.
 
 import argparse
 import datetime
 import logging
 import sqlite3
-import sys
 
-factor = {'privat' : 0}
+factor = {'privat': 0}
 
 l = logging
 l.basicConfig(level=logging.INFO,
-#l.basicConfig(level=logging.DEBUG,
-                    format='%(message)s')
+              # l.basicConfig(level=logging.DEBUG,
+              format='%(message)s')
 #                    format='%(asctime)s %(levelname)s %(message)s')
 
+
 def hhhmm_from_timedelta(td):
     """Return a string '-HHH:MM' from the timedelta parameter.
 
     Accounts for way the integer division works for negative numbers:
         -2 // 60 == -1
         -2 % 60 == 58
-    by first working on the positive number and then adding the minus 
+    by first working on the positive number and then adding the minus
     to the string.
 
     For python >=3.1. Successor of hhmm_from_timedelta() from
     http://intevation.de/cgi-bin/viewcvs-misc.cgi/worklog.py/ .
     """
-    total_minutes = abs(round(td.days*24*60 + td.seconds/60))
+    total_minutes = abs(round(td.days * 24 * 60 + td.seconds / 60))
     # variant for Python v>3.2:
-    #total_minutes = abs(round(td/datetime.timedelta(minutes=1)))
+    # total_minutes = abs(round(td/datetime.timedelta(minutes=1)))
 
-    hours = total_minutes//60
-    minutes = total_minutes%60
+    hours = total_minutes // 60
+    minutes = total_minutes % 60
 
     h_string = "{}".format(hours)
 
-    if(td.days<0):
+    if(td.days < 0):
         h_string = "-" + h_string
 
     return "{:>3s}:{:02d}".format(h_string, minutes)
 
+
 def self_test():
     """Run some simple tests on hhhmm_from_timedelta().
 
@@ -65,13 +69,14 @@
     l.info(hhhmm_from_timedelta(datetime.timedelta(minutes=1)))
     l.info(hhhmm_from_timedelta(datetime.timedelta(minutes=-2)))
 
+
 def main():
     parser = argparse.ArgumentParser(description=__doc__)
     parser.add_argument("-t", action='store_true',
-        help="timesorted output and default reportday to today")
+                        help="timesorted output and default reportday to today")
     parser.add_argument("dbfilename")
-    parser.add_argument("reportday", nargs='?', 
-        help="day to report  yyyy-mm-dd")
+    parser.add_argument("reportday", nargs='?',
+                        help="day to report  yyyy-mm-dd")
 
     args = parser.parse_args()
     l.debug(args)
@@ -82,17 +87,18 @@
     elif args.t:
         # start with today 00:00
         report_range_start = datetime.datetime.combine(
-                            datetime.date.today(), datetime.time())
+            datetime.date.today(), datetime.time())
     else:
         # start with yesterday 00:00
         report_range_start = datetime.datetime.combine(
-                    datetime.date.today() - datetime.timedelta(days=1),
-                    datetime.time())
+            datetime.date.today() - datetime.timedelta(days=1),
+            datetime.time())
     report_range_end = report_range_start + datetime.timedelta(days=1)
 
-
     l.info("Opening sqlite3 database '%s'" % args.dbfilename)
-    conn = sqlite3.connect(args.dbfilename, detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES)
+    conn = sqlite3.connect(
+        args.dbfilename,
+        detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES)
     c = conn.cursor()
 
     tasks = {}
@@ -105,7 +111,7 @@
         task_total[t[0]] = datetime.timedelta()
 
 # from getan 1.0 20130103
-#CREATE TABLE entries (
+# CREATE TABLE entries (
 #    id          INTEGER PRIMARY KEY AUTOINCREMENT,
 #    project_id  INTEGER REFERENCES projects(id),
 #    start_time  TIMESTAMP NOT NULL,
@@ -113,7 +119,7 @@
 #    description VARCHAR(256),
 #
 #    CHECK (strftime('%s', start_time) <= strftime('%s', stop_time))
-#);
+# );
 
     total_time = datetime.timedelta()
 
@@ -123,23 +129,25 @@
         c.execute('select * from entries order by project_id')
     for e in c:
         l.debug(e)
-        length = e[3]-e[2]
+        length = e[3] - e[2]
 
         desc = tasks[e[1]]
 
         if e[2] >= report_range_start and e[2] < report_range_end:
             if args.t:
                 print("{2}: {3} {4}\n\t\t\t{0} {1}".
-                  format(e[2], e[3], desc, e[4],hhhmm_from_timedelta(length)))
+                      format(e[2], e[3], desc, e[4],
+                             hhhmm_from_timedelta(length)))
             else:
                 print("{0} {2}: {3} {4}".
-                  format(e[2], e[3], desc, e[4],hhhmm_from_timedelta(length)))
+                      format(e[2], e[3], desc, e[4],
+                             hhhmm_from_timedelta(length)))
             if desc in factor:
-                ##python3.1 does not allow timedelta division. 
-                ##TODO: Make python3.1 save or update to python3.2.
-                #l.info("applying factor %f to entry %s" % (factor[desc], e))
-                #length = (length * int(factor[desc]*1000))/1000
-                #Until python3.2 we only honor a factor of zero:
+                # python3.1 does not allow timedelta division.
+                # TODO: Make python3.1 save or update to python3.2.
+                # l.info("applying factor %f to entry %s" % (factor[desc], e))
+                # length = (length * int(factor[desc]*1000))/1000
+                # Until python3.2 we only honor a factor of zero:
                 if factor[desc] == 0:
                     length = datetime.timedelta(0)
                     l.info("not counting {}".format(e))


More information about the Getan-commits mailing list