Added end all command.
1.1 --- a/cronrec.py Fri Oct 01 18:59:45 2010 +0200
1.2 +++ b/cronrec.py Fri Oct 01 22:02:28 2010 +0200
1.3 @@ -1,9 +1,9 @@
1.4 #!/usr/local/bin/python
1.5
1.6 """
1.7 -A time recording tool.
1.8 +tim - A time recording tool, because time is money.
1.9 Author: Eugen Sawin (sawine@me73.com)
1.10 -Dependencies: libsqlite3-dev
1.11 +Dependencies: Python 2.7 and libsqlite3-dev
1.12 """
1.13
1.14 import os
1.15 @@ -20,7 +20,7 @@
1.16
1.17 config = {}
1.18
1.19 -# Trying to get the user's home directory path
1.20 +# Try to get the user's home directory path
1.21 try: # Windows
1.22 from win32com.shell import shellcon, shell
1.23 HOMEDIR = shell.SHGetFolderPath(0, shellcon.CSIDL_LOCAL_APPDATA, 0, 0)
1.24 @@ -100,6 +100,15 @@
1.25 db.end(db_file(), project, activity, datetime.now())
1.26 print "ends %s:%s" % (project, activity)
1.27
1.28 +def status(args):
1.29 + result = db.find_active_tasks(db_file())
1.30 + if result:
1.31 + print "Currently active tasks:"
1.32 + for r in result:
1.33 + print "Project: %s Activity: %s" % r
1.34 + else:
1.35 + print "There are no active tasks."
1.36 +
1.37 def main():
1.38 global config
1.39 config = read_config()
1.40 @@ -114,9 +123,12 @@
1.41 sub_begin.set_defaults(func=begin)
1.42
1.43 sub_end = subs.add_parser("end")
1.44 - sub_end.add_argument("label", type=str)
1.45 + sub_end.add_argument("label", type=str, nargs="?", default="all:all")
1.46 sub_end.set_defaults(func=end)
1.47
1.48 + sub_end = subs.add_parser("status")
1.49 + sub_end.set_defaults(func=status)
1.50 +
1.51 args = parser.parse_args()
1.52 args.func(args)
1.53
2.1 --- a/db.py Fri Oct 01 18:59:45 2010 +0200
2.2 +++ b/db.py Fri Oct 01 22:02:28 2010 +0200
2.3 @@ -117,6 +117,27 @@
2.4 cur.close()
2.5 return activity
2.6
2.7 +def find_active_tasks(db_file):
2.8 + con, cur = session(db_file)
2.9 + sql = "select project, activity from tasks where end is null"
2.10 + cur.execute(sql)
2.11 + results = []
2.12 + if cur:
2.13 + for id in cur:
2.14 + results.append((id_name(db_file, "projects", id[0]),
2.15 + id_name(db_file, "activities", id[1])))
2.16 + cur.close()
2.17 + return results
2.18 +
2.19 +def id_name(db_file, table, id):
2.20 + con, cur = session(db_file)
2.21 + values = (id,)
2.22 + sql = "select name from %s where rowid=?" % table
2.23 + cur.execute(sql, values)
2.24 + id = cur.fetchone()
2.25 + cur.close()
2.26 + return id[0]
2.27 +
2.28 def row_id(db_file, table, name):
2.29 con, cur = session(db_file)
2.30 values = (name,)
2.31 @@ -146,9 +167,14 @@
2.32 activity = find_last_activity(db_file, time)
2.33 elif not project:
2.34 project = find_last_project(db_file, time)
2.35 +
2.36 con, cur = session(db_file)
2.37 - values = (time, project_id(db_file, project), activity_id(db_file, activity))
2.38 - sql = "update tasks set end=? where project=? and activity=?"
2.39 + if activity == "all" and project == "all":
2.40 + values = (time,)
2.41 + sql = "update tasks set end=? where end is null"
2.42 + else:
2.43 + values = (time, project_id(db_file, project), activity_id(db_file, activity))
2.44 + sql = "update tasks set end=? where project=? and activity=?"
2.45 cur.execute(sql, values)
2.46 con.commit()
2.47 cur.close()