<s> """<STR_LIT>""" <EOL> import sys <EOL> import os <EOL> import errno <EOL> import datetime <EOL> from twisted . python import log , util <EOL> import vcdm <EOL> from vcdm . accounting import send_ogf_ur_accounting <EOL> conf = vcdm . config . get_config ( ) <EOL> def copyStreamToStream ( streamFrom , streamTo , input_length = sys . maxint , offset = <NUM_LIT:0> , <EOL> buffer = <NUM_LIT:2> ** <NUM_LIT:2> ** <NUM_LIT:2> ** <NUM_LIT:2> ) : <EOL> """<STR_LIT>""" <EOL> streamFrom . seek ( offset , <NUM_LIT:0> ) <EOL> nbytes = <NUM_LIT:0> <EOL> while nbytes < input_length : <EOL> chunk = streamFrom . read ( min ( input_length - nbytes , buffer ) ) <EOL> if not chunk : <EOL> break <EOL> streamTo . write ( chunk ) <EOL> nbytes += len ( chunk ) <EOL> def print_memory_stats ( location_tag = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> import psutil <EOL> p = psutil . Process ( os . getpid ( ) ) <EOL> rm , vm = p . get_memory_info ( ) <EOL> print "<STR_LIT>" % ( location_tag , rm , vm ) <EOL> except ImportError : <EOL> print "<STR_LIT>" <EOL> class AccountingLogObserver ( log . FileLogObserver ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , f ) : <EOL> log . FileLogObserver . __init__ ( self , f ) <EOL> self . aggregated_operations = <NUM_LIT:0> <EOL> def emit ( self , eventDict ) : <EOL> if eventDict . get ( '<STR_LIT:type>' ) == '<STR_LIT>' : <EOL> acc_type = eventDict . get ( '<STR_LIT>' ) <EOL> if acc_type != '<STR_LIT>' : <EOL> self . aggregated_operations += eventDict . get ( '<STR_LIT>' ) <EOL> else : <EOL> timeStr = datetime . datetime . fromtimestamp ( eventDict [ '<STR_LIT:time>' ] ) . isoformat ( ) <EOL> avatar = eventDict . get ( '<STR_LIT>' ) <EOL> amount = eventDict . get ( '<STR_LIT>' ) <EOL> acc_type = eventDict . get ( '<STR_LIT>' ) <EOL> start_time = datetime . datetime . fromtimestamp ( eventDict . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) . isoformat ( ) <EOL> end_time = datetime . datetime . fromtimestamp ( eventDict . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) . isoformat ( ) <EOL> msg = "<STR_LIT>" % ( timeStr , start_time , end_time , avatar , amount , self . aggregated_operations ) <EOL> if conf . getboolean ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> send_ogf_ur_accounting ( start_time , end_time , avatar , amount , self . aggregated_operations ) <EOL> util . untilConcludes ( self . write , msg ) <EOL> util . untilConcludes ( self . flush ) <EOL> self . aggregated_operations = <NUM_LIT:0> <EOL> def check_path ( container_path ) : <EOL> if container_path == [ '<STR_LIT:/>' ] : <EOL> return True <EOL> all_paths = [ ] <EOL> for i , value in enumerate ( container_path ) : <EOL> if i == <NUM_LIT:0> : <EOL> all_paths . append ( '<STR_LIT:/>' ) <EOL> else : <EOL> all_paths . append ( all_paths [ i - <NUM_LIT:1> ] . rstrip ( '<STR_LIT:/>' ) + '<STR_LIT:/>' + value ) <EOL> log . msg ( "<STR_LIT>" % all_paths ) <EOL> return len ( vcdm . env [ '<STR_LIT>' ] . find_path_uids ( all_paths ) ) == len ( container_path ) <EOL> def mkdir_p ( path ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> os . makedirs ( path ) <EOL> except OSError as exc : <EOL> if exc . errno == errno . EEXIST : <EOL> pass <EOL> else : raise </s>
