def add(args, helpers): if "duration" in args and "end" in args: raise ValueError("please use either duration OR end, not both") elif not ("duration" in args or "end" in args): raise ValueError("duration OR end is required") for key in (x for x in ("start", "end") if x in args): try: args[key] = helpers.datetime.parse(args[key]) except ValueError: time = datetime.datetime.strptime(args[key], helpers.config["time_format"]).time() args[key] = datetime.datetime.combine(datetime.date.today(), time) if "duration" in args: duration = helpers.duration.parse(args["duration"]) elif "end" in args: duration = args["end"] - args["start"] args["duration"] = duration task = Task.get(int(args["tasknum"])) log = Log.add(task["id"], **args) helpers.pprint(log, helpers.config["log"]["format"])
def current( args, helpers ): task = Task.current() if task: helpers.pprint( task, helpers.config['task']['format'] ) print "Description: %s" % task['body']
def create( args, helpers ): start = args.pop('start') creator_id = User.find_id_by_username( helpers.config['username'] ) #Parse duration and date if 'duration' in args: args['duration'] = helpers.duration.parse( args['duration'] ) if 'due_at' in args: args['due_at'] = helpers.date.parse( args['due_at'] ) #Transform project name into project id found = Project.find_id_by_name( args.pop( 'project') ) if len( found ) == 0: print "ERROR: project does not exist (project name not found)" sys.exit( 1 ) elif len ( found ) > 1: print "ERROR: more than one project with the same name (try putting in a longer project name for searching)" sys.exit( 1 ) args['project_id'] = found[0] #Transform usernames into user ids user_ids = [ creator_id[0] ] for username in args.pop( 'users', '' ): user_id = User.find_id_by_username( username ) if len( user_id ) == 0: print "ERROR: no user found for username %s" % username sys.exit( 1 ) elif len( user_id ) > 1: print "ERROR: more than one user found with username '%s' (try a longer username)" sys.exit( 1 ) if not user_id: print "ERROR: user does not exist (username not found)" sys.exit( 1 ) user_ids.append( user_id[0] ) user_ids = list( set( user_ids ) ) args['user_ids'] = user_ids task = Task.create( **args ) if start: task.start() helpers.pprint( task, helpers.config['task']['format'] )
def show( args, helpers ): task = Task.get( args['tasknum'] ) pprint.pprint( task )
def cancel( args, helpers ): Task.cancel()
def stop( args, helpers ): if 'log' in args: updatelog( {'description' : args['log']}, helpers ) Task.stop()
def updatelog( args, helpers ): Task.updatelog( args['description'] )
def start( args, helpers ): task = Task.get( args['tasknum'] ) task.start()