changeset 348:328ec66517b0

Fix coding style for pep8
author Björn Ricks <bjoern.ricks@intevation.de>
date Mon, 03 Mar 2014 11:37:37 +0100
parents 3a1786947673
children c97a4b6a6887
files getan/backend.py
diffstat 1 files changed, 22 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/getan/backend.py	Mon Mar 03 11:34:31 2014 +0100
+++ b/getan/backend.py	Mon Mar 03 11:37:37 2014 +0100
@@ -22,7 +22,7 @@
 DEFAULT_DATABASE = "time.db"
 
 CREATE_TABLES = [
-"""
+    """
 CREATE TABLE projects (
     id          INTEGER PRIMARY KEY AUTOINCREMENT,
     key         VARCHAR(16) NOT NULL CONSTRAINT unique_key UNIQUE,
@@ -30,7 +30,7 @@
     active      BOOLEAN DEFAULT 1
 )
 """,
-"""
+    """
 CREATE TABLE entries (
     id          INTEGER PRIMARY KEY AUTOINCREMENT,
     project_id  INTEGER REFERENCES projects(id),
@@ -89,27 +89,29 @@
 
 logger = logging.getLogger()
 
+
 class InvalidProjectKeyError(Exception):
     pass
 
+
 class Backend(object):
 
-    def __init__(self, database = DEFAULT_DATABASE):
+    def __init__(self, database=DEFAULT_DATABASE):
         self.database = database
         self.ensure_exists()
-        self.con      = db.connect(database,
-                                   detect_types=db.PARSE_DECLTYPES |
-                                   db.PARSE_COLNAMES)
+        self.con = db.connect(database,
+                              detect_types=db.PARSE_DECLTYPES |
+                              db.PARSE_COLNAMES)
         self.con.text_factory = lambda x: unicode(x, "utf-8", "ignore")
 
-
     def ensure_exists(self):
         """ Creates the database file if it does not exist. """
-        if os.path.isfile(self.database): return
+        if os.path.isfile(self.database):
+            return
 
         con, cur = None, None
         try:
-            con = db.connect(self.database);
+            con = db.connect(self.database)
             cur = con.cursor()
             try:
                 for sql in CREATE_TABLES:
@@ -119,15 +121,16 @@
                 con.rollback()
                 raise
         finally:
-            if cur: cur.close()
-            if con: con.close()
-
+            if cur:
+                cur.close()
+            if con:
+                con.close()
 
     def load_projects(self):
         """ Loads active projects from database and returns them as array """
         logger.debug("load active projects from database.")
         cur = None
-        try :
+        try:
             cur = self.con.cursor()
             cur.execute(LOAD_ACTIVE_PROJECTS)
 
@@ -139,8 +142,8 @@
                     break
                 # check key
                 if not row[1]:
-                    raise InvalidProjectKeyError("Project with id %s needs " \
-                            "a key" % row[0])
+                    raise InvalidProjectKeyError("Project with id %s needs "
+                                                 "a key" % row[0])
                 proj = Project(*row)
                 proj.entries = self.load_entries(proj.id)
                 projects.append(proj)
@@ -151,7 +154,6 @@
         finally:
             close(cur)
 
-
     def load_entries(self, project_id):
         """ Loads all entries that belong to a specific project """
         logger.debug("load entries that belong to project %s" % project_id)
@@ -174,7 +176,6 @@
         finally:
             close(cur)
 
-
     def insert_project_entry(self, project, stop_time, desc):
         if project is None:
             return
@@ -217,7 +218,6 @@
         finally:
             close(cur)
 
-
     def move_entries(self, entries, new_project_id):
         if entries is None or new_project_id is None:
             return
@@ -253,13 +253,15 @@
         cur = None
         try:
             cur = self.con.cursor()
-            cur.execute(UPDATE_PROJECT, (project.key, project.desc, project.id))
+            cur.execute(
+                UPDATE_PROJECT, (project.key, project.desc, project.id))
             self.con.commit()
             logger.debug("Updated project: (%d) %s %s" % (project.id,
-                project.key, project.desc))
+                                                          project.key, project.desc))
         finally:
             close(cur)
 
+
 def close(cur):
     """ This function closes a database cursor if it is existing """
     if cur:
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)