<s> import time <EOL> import os <EOL> class Submitter : <EOL> def __init__ ( self , sd ) : <EOL> self . sd = sd <EOL> self . input_bucket = self . sd . get_obj ( '<STR_LIT>' ) <EOL> self . output_bucket = self . sd . get_obj ( '<STR_LIT>' ) <EOL> self . output_domain = self . sd . get_obj ( '<STR_LIT>' ) <EOL> self . queue = self . sd . get_obj ( '<STR_LIT>' ) <EOL> def get_key_name ( self , fullpath , prefix ) : <EOL> key_name = fullpath [ len ( prefix ) : ] <EOL> l = key_name . split ( os . sep ) <EOL> return '<STR_LIT:/>' . join ( l ) <EOL> def write_message ( self , key , metadata ) : <EOL> if self . queue : <EOL> m = self . queue . new_message ( ) <EOL> m . for_key ( key , metadata ) <EOL> if self . output_bucket : <EOL> m [ '<STR_LIT>' ] = self . output_bucket . name <EOL> self . queue . write ( m ) <EOL> def submit_file ( self , path , metadata = None , cb = None , num_cb = <NUM_LIT:0> , prefix = '<STR_LIT:/>' ) : <EOL> if not metadata : <EOL> metadata = { } <EOL> key_name = self . get_key_name ( path , prefix ) <EOL> k = self . input_bucket . new_key ( key_name ) <EOL> k . update_metadata ( metadata ) <EOL> k . set_contents_from_filename ( path , replace = False , cb = cb , num_cb = num_cb ) <EOL> self . write_message ( k , metadata ) <EOL> def submit_path ( self , path , tags = None , ignore_dirs = None , cb = None , num_cb = <NUM_LIT:0> , status = False , prefix = '<STR_LIT:/>' ) : <EOL> path = os . path . expanduser ( path ) <EOL> path = os . path . expandvars ( path ) <EOL> path = os . path . abspath ( path ) <EOL> total = <NUM_LIT:0> <EOL> metadata = { } <EOL> if tags : <EOL> metadata [ '<STR_LIT>' ] = tags <EOL> l = [ ] <EOL> for t in time . gmtime ( ) : <EOL> l . append ( str ( t ) ) <EOL> metadata [ '<STR_LIT>' ] = '<STR_LIT:_>' . join ( l ) <EOL> if self . output_domain : <EOL> self . output_domain . put_attributes ( metadata [ '<STR_LIT>' ] , { '<STR_LIT:type>' : '<STR_LIT>' } ) <EOL> if os . path . isdir ( path ) : <EOL> for root , dirs , files in os . walk ( path ) : <EOL> if ignore_dirs : <EOL> for ignore in ignore_dirs : <EOL> if ignore in dirs : <EOL> dirs . remove ( ignore ) <EOL> for file in files : <EOL> fullpath = os . path . join ( root , file ) <EOL> if status : <EOL> print '<STR_LIT>' % fullpath <EOL> self . submit_file ( fullpath , metadata , cb , num_cb , prefix ) <EOL> total += <NUM_LIT:1> <EOL> elif os . path . isfile ( path ) : <EOL> self . submit_file ( path , metadata , cb , num_cb ) <EOL> total += <NUM_LIT:1> <EOL> else : <EOL> print '<STR_LIT>' % path <EOL> return ( metadata [ '<STR_LIT>' ] , total ) </s>
