def add_job(values): """Parses add arguments and fires add time record action""" jobid = values[0] try: start_time = datetime.strptime(values[1],DateFormat.COMPACT) end_time = datetime.strptime(values[2],DateFormat.COMPACT) except ValueError: msg = "Format for times %s %s are not a valid, use this format: dd/mm/yyyy-hh:mm" % (values[1], values[2]) print(argparse.ArgumentTypeError(msg)) return if start_time > end_time: msg = "Start time cannot be later than end time (unless you've a time machine): %s %s" % (values[1], values[2]) print(argparse.ArgumentTypeError(msg)) return try: jobname = backend.insert_completed_job(jobid, start_time, end_time) print('Time record for the job "' + jobname + '" has been saved') except ValueError as msg: print(msg) return except IOError: print("No job category found. Please check and add some") return
def add_job(values): """Parses add arguments and fires add time record action""" jobid = values[0] try: start_time = datetime.strptime(values[1], DateFormat.COMPACT) end_time = datetime.strptime(values[2], DateFormat.COMPACT) except ValueError: msg = "Format for times %s %s are not a valid, use this format: dd/mm/yyyy-hh:mm" % ( values[1], values[2]) print(argparse.ArgumentTypeError(msg)) return if start_time > end_time: msg = "Start time cannot be later than end time (unless you've a time machine): %s %s" % ( values[1], values[2]) print(argparse.ArgumentTypeError(msg)) return try: jobname = backend.insert_completed_job(jobid, start_time, end_time) print('Time record for the job "' + jobname + '" has been saved') except ValueError as msg: print(msg) return except IOError: print("No job category found. Please check and add some") return
def end_job(): """Parses end argument and fires end job action""" end_time = datetime.now() try: details = backend.pop_from_currents() jobname = backend.insert_completed_job(details["jobid"], details["start_time"], end_time) except KeyError: print("Error: There is no job started before") return print('The job "' + jobname + '" has ended and saved')