<s> """<STR_LIT>""" <EOL> import fcntl <EOL> import os <EOL> import string <EOL> import subprocess <EOL> import console <EOL> try : <EOL> import hashlib as md5 <EOL> except ImportError : <EOL> import md5 <EOL> def md5sum_str ( user_str ) : <EOL> """<STR_LIT>""" <EOL> m = md5 . md5 ( ) <EOL> if not isinstance ( user_str , basestring ) : <EOL> console . error_exit ( '<STR_LIT>' ) <EOL> m . update ( user_str ) <EOL> return m . hexdigest ( ) <EOL> def md5sum ( obj ) : <EOL> """<STR_LIT>""" <EOL> return md5sum_str ( obj ) <EOL> def lock_file ( fd , flags ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> fcntl . flock ( fd , flags ) <EOL> return ( True , <NUM_LIT:0> ) <EOL> except IOError , ex_value : <EOL> return ( False , ex_value [ <NUM_LIT:0> ] ) <EOL> def unlock_file ( fd ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> fcntl . flock ( fd , fcntl . LOCK_UN ) <EOL> return ( True , <NUM_LIT:0> ) <EOL> except IOError , ex_value : <EOL> return ( False , ex_value [ <NUM_LIT:0> ] ) <EOL> def var_to_list ( var ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( var , list ) : <EOL> return var <EOL> if not var : <EOL> return [ ] <EOL> return [ var ] <EOL> def relative_path ( a_path , reference_path ) : <EOL> """<STR_LIT>""" <EOL> if not a_path : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> reference_list = os . path . abspath ( reference_path ) . split ( os . path . sep ) <EOL> path_list = os . path . abspath ( a_path ) . split ( os . path . sep ) <EOL> i = <NUM_LIT:0> <EOL> for i in range ( min ( len ( reference_list ) , len ( path_list ) ) ) : <EOL> if reference_list [ i ] . lower ( ) != path_list [ i ] . lower ( ) : <EOL> break <EOL> else : <EOL> i += <NUM_LIT:1> <EOL> rel_list = [ os . path . pardir ] * ( len ( reference_list ) - i ) + path_list [ i : ] <EOL> if not rel_list : <EOL> return os . path . curdir <EOL> return os . path . join ( * rel_list ) <EOL> def get_cwd ( ) : <EOL> """<STR_LIT>""" <EOL> p = subprocess . Popen ( [ '<STR_LIT>' ] , stdout = subprocess . PIPE , shell = True ) <EOL> return p . communicate ( ) [ <NUM_LIT:0> ] . strip ( ) <EOL> def environ_add_path ( env , key , path ) : <EOL> """<STR_LIT>""" <EOL> old = env . get ( key ) <EOL> if old : <EOL> env [ key ] = old + '<STR_LIT::>' + path <EOL> else : <EOL> env [ key ] = path <EOL> def cpu_count ( ) : <EOL> try : <EOL> import multiprocessing <EOL> return multiprocessing . cpu_count ( ) <EOL> except ImportError : <EOL> return int ( os . sysconf ( '<STR_LIT>' ) ) <EOL> def regular_variable_name ( var ) : <EOL> """<STR_LIT>""" <EOL> return var . translate ( string . maketrans ( '<STR_LIT>' , '<STR_LIT>' ) ) </s>
