<s> "<STR_LIT>" <EOL> __name__ = '<STR_LIT>' <EOL> import sys <EOL> import os . path <EOL> import datetime <EOL> from termcolor import colored <EOL> from timed import server <EOL> from timed import cmdapp <EOL> now = datetime . datetime . now <EOL> def main ( ) : <EOL> cmdapp . main ( name = '<STR_LIT>' , desc = __doc__ , config = { <EOL> '<STR_LIT>' : os . path . expanduser ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> @ cmdapp . cmd <EOL> def summary ( logfile , time_format ) : <EOL> "<STR_LIT>" <EOL> def output ( summary ) : <EOL> width = max ( [ len ( p [ <NUM_LIT:0> ] ) for p in summary ] ) + <NUM_LIT:3> <EOL> print '<STR_LIT:\n>' . join ( [ <EOL> "<STR_LIT>" % ( p [ <NUM_LIT:0> ] , '<STR_LIT:U+0020>' * ( width - len ( p [ <NUM_LIT:0> ] ) ) , <EOL> colored ( minutes_to_txt ( p [ <NUM_LIT:1> ] ) , '<STR_LIT>' ) ) for p in summary ] ) <EOL> output ( server . summarize ( read ( logfile , time_format , only_elapsed = True ) ) ) <EOL> @ cmdapp . cmd <EOL> @ cmdapp . default <EOL> def status ( logfile , time_format ) : <EOL> "<STR_LIT>" <EOL> try : <EOL> r = read ( logfile , time_format ) [ - <NUM_LIT:1> ] <EOL> if r [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] : <EOL> return summary ( logfile , time_format ) <EOL> else : <EOL> print "<STR_LIT>" % colored ( r [ <NUM_LIT:0> ] , attrs = [ '<STR_LIT>' ] ) <EOL> print "<STR_LIT>" % colored ( <EOL> server . date_to_txt ( r [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] , time_format ) , '<STR_LIT>' ) <EOL> print "<STR_LIT>" % colored ( <EOL> server . date_to_txt ( now ( ) , time_format ) , '<STR_LIT>' ) <EOL> print "<STR_LIT>" % colored ( time_elapsed ( r [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] ) , '<STR_LIT>' ) <EOL> except IndexError : <EOL> return cmdapp . help ( ) <EOL> @ cmdapp . cmd <EOL> def start ( project , logfile , time_format ) : <EOL> "<STR_LIT>" <EOL> records = read ( logfile , time_format ) <EOL> if records and not records [ - <NUM_LIT:1> ] [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] : <EOL> print "<STR_LIT>" <EOL> return <EOL> write ( server . start ( project , records ) , logfile , time_format ) <EOL> print "<STR_LIT>" % colored ( project , attrs = [ '<STR_LIT>' ] ) <EOL> print "<STR_LIT>" % colored ( server . date_to_txt ( now ( ) , time_format ) , '<STR_LIT>' ) <EOL> @ cmdapp . cmd <EOL> def stop ( logfile , time_format ) : <EOL> "<STR_LIT>" <EOL> def save_and_output ( records ) : <EOL> records = server . stop ( records ) <EOL> write ( records , logfile , time_format ) <EOL> def output ( r ) : <EOL> print "<STR_LIT>" % colored ( r [ <NUM_LIT:0> ] , attrs = [ '<STR_LIT>' ] ) <EOL> print "<STR_LIT>" % colored ( <EOL> server . date_to_txt ( r [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] , time_format ) , '<STR_LIT>' ) <EOL> print "<STR_LIT>" % colored ( <EOL> server . date_to_txt ( r [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] , time_format ) , '<STR_LIT>' ) <EOL> print "<STR_LIT>" % colored ( <EOL> time_elapsed ( r [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] , r [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] ) , '<STR_LIT>' ) <EOL> output ( records [ - <NUM_LIT:1> ] ) <EOL> save_and_output ( read ( logfile , time_format ) ) <EOL> @ cmdapp . cmd <EOL> def parse ( logfile , time_format ) : <EOL> "<STR_LIT>" <EOL> records = [ server . record_from_txt ( line , only_elapsed = True , <EOL> time_format = time_format ) for line in sys . stdin . readlines ( ) ] <EOL> def output ( summary ) : <EOL> width = max ( [ len ( p [ <NUM_LIT:0> ] ) for p in summary ] ) + <NUM_LIT:3> <EOL> print '<STR_LIT:\n>' . join ( [ <EOL> "<STR_LIT>" % ( p [ <NUM_LIT:0> ] , '<STR_LIT:U+0020>' * ( width - len ( p [ <NUM_LIT:0> ] ) ) , <EOL> colored ( minutes_to_txt ( p [ <NUM_LIT:1> ] ) , '<STR_LIT>' ) ) for p in summary ] ) <EOL> output ( server . summarize ( records ) ) <EOL> @ cmdapp . cmd <EOL> def projects ( logfile , time_format ) : <EOL> "<STR_LIT>" <EOL> print '<STR_LIT:\n>' . join ( server . list_projects ( read ( logfile , time_format ) ) ) <EOL> def read ( logfile , time_format , only_elapsed = False ) : <EOL> return [ server . record_from_txt ( line , only_elapsed = only_elapsed , <EOL> time_format = time_format ) for line in open ( <EOL> os . path . expanduser ( logfile ) , '<STR_LIT>' ) . readlines ( ) ] <EOL> def write ( records , logfile , time_format ) : <EOL> try : <EOL> open ( logfile , '<STR_LIT:w>' ) . write ( '<STR_LIT:\n>' . join ( <EOL> [ server . record_to_txt ( record , time_format ) for record in records ] ) ) <EOL> except IOError : <EOL> print "<STR_LIT>" % logfile <EOL> def time_elapsed ( start , end = None ) : <EOL> return minutes_to_txt ( server . minutes_elapsed ( start , end ) ) <EOL> def minutes_to_txt ( delta ) : <EOL> hour = delta / <NUM_LIT> <EOL> min = delta - <NUM_LIT> * hour <EOL> return "<STR_LIT>" % ( hour , min ) </s>
