1.1 --- a/cronrec.py Thu Sep 30 16:19:14 2010 +0200
1.2 +++ b/cronrec.py Fri Oct 01 00:45:07 2010 +0200
1.3 @@ -10,7 +10,8 @@
1.4 import sys
1.5 import argparse
1.6 from datetime import datetime
1.7 -import sqlite3
1.8 +
1.9 +import db
1.10
1.11 WD = "working_path"
1.12 CONFIG = {WD: str}
1.13 @@ -31,14 +32,6 @@
1.14 DEF_PROJECT = "default"
1.15 DEF_ACTIVITY = "default"
1.16
1.17 -def db_session():
1.18 - global config
1.19 - if WD not in config:
1.20 - print "Error: working directory is not configured. Use init command."
1.21 - sys.exit()
1.22 - con = sqlite3.connect(config[WD] + "/" + DB_FILE)
1.23 - return con, con.cursor()
1.24 -
1.25 def read_config():
1.26 config = {}
1.27 with open(CONFIG_FILE, "r") as config_stream:
1.28 @@ -56,10 +49,14 @@
1.29 config_input.write("\n".join([CONFIG_SEP.join((k, v))
1.30 for k, v in config.iteritems() if k in CONFIG]))
1.31
1.32 -def db_init(db_file):
1.33 - con, cur = db_session()
1.34 - sql = "create table projects()"
1.35 -
1.36 +def db_file():
1.37 + global config
1.38 + if WD not in config:
1.39 + print "Working directory path is not configured. \
1.40 +Please use the init command."
1.41 + return None
1.42 + return config[WD] + "/" + DB_FILE
1.43 +
1.44 def init(args):
1.45 global config
1.46 last_wd = None
1.47 @@ -68,9 +65,8 @@
1.48 config[WD] = args.working_path
1.49 write_config(config)
1.50 path_exists = os.path.exists(config[WD]) and os.path.isdir(config[WD])
1.51 - db_file = config[WD] + "/" + DB_FILE
1.52 - db_exists = path_exists and os.path.exists(db_file)
1.53 - and os.path.isfile(db_file)
1.54 + db_exists = path_exists and os.path.exists(db_file())\
1.55 + and os.path.isfile(db_file())
1.56 if last_wd != config[WD]:
1.57 print "Changed working directory from %s to %s." % (last_wd, config[WD])
1.58 else:
1.59 @@ -80,16 +76,10 @@
1.60 os.makedirs(config[WD])
1.61 print "Working directory %s created." % config[WD]
1.62 elif db_exists:
1.63 - print "Database file %s already exists, please delete it before\
1.64 - initiating a new database at this location." % db_file
1.65 + print "Database file %s already exists, please delete it before \
1.66 +initiating a new database at this location." % db_file()
1.67 if not db_exists:
1.68 - db_init(db_file)
1.69 -
1.70 -def db_begin(project, activity, time):
1.71 - con, cur = db_session()
1.72 - cur.execute("")
1.73 - con.commit()
1.74 - cur.close()
1.75 + db.init(db_file())
1.76
1.77 def begin(args):
1.78 project = None
1.79 @@ -103,7 +93,7 @@
1.80 project = DEF_PROJECT
1.81 if not activity:
1.82 activity = DEF_ACTIVITY
1.83 - db_begin(project, activity, datetime.now())
1.84 + db.begin(db_file(), project, activity, datetime.now())
1.85 print "begins %s:%s" % (project, activity)
1.86
1.87 def end(args):