コード例 #1
0
def move_datafiles(file_data_dicts, event, destination, current_trial, trial_doc_folder, default_folder, expnum):
    """Moves datafile from mysql-descripted location to file structure.
    file_                   = mySQL-created dictionary that hold data location info.
    event                   = Dictionary containing event information for the event that "file_" belongs to.
    destination             = Location of Experiment file structure as defined by configuration
    current_trial           = Actually is the trial number that is being worked on.
    trial_doc_folder        = Location of Documentation Files for the event. """
    julian_folder = datetime.datetime.utcfromtimestamp(event["time"]).strftime(data_retrieval_time_format)
    file_queue_dict = {}
    pubchan_queue_list = []
    file_extensions = [".msd"]
    siteEvt = event[cfg_evt_siteEvt]

    # Generate a dictionary Queue fo all information to prepare upload.
    for file_ in file_data_dicts:
        filename = file_[cfg_fl_dfile]
        oscommand_source = "%s%s%s" % (default_folder, julian_folder, filename)
        oscommand_destination = "%sTrial-%s/Rep-1/" % (destination, current_trial)
        pubChan = "%s_%s_%s" % (file_[cfg_fl_net], file_[cfg_fl_sta], file_[cfg_fl_chan])

        file_queue_dict[filename] = [oscommand_source, oscommand_destination, pubChan]
        pubchan_queue_list.append(pubChan)

    # Generate ASCII and report.csv files for event.
    file_extensions = utils.generate_ascii(siteEvt, oscommand_destination, pubchan_queue_list, file_extensions)

    # Copy .msd files to proper directory and upload .msd and .txt files.
    for filename in file_queue_dict.keys():
        oscommand_source = file_queue_dict[filename][0]
        oscommand_destination = file_queue_dict[filename][1]
        pubChan = file_queue_dict[filename][2]

        utils.copy_file_exts(oscommand_source, oscommand_destination, [".msd"])

        # TODO: IDIOTICY
        # APPARENTLY AFTER MAKING THE FIRST UPLOAD AND POST I NEED TO WAIT BEFORE ATTEMPTING
        # THE REST, OTHERWISE THREE OF THE FILES WILL FAIL
        # WITH THIS, ALL IS HAPPY AND GOOD
        if file_data_dicts.index(file_) == 1:  # WHAT THE HELL
            time.sleep(5)  # NO SERIOUSLY, WHY IS THIS OKAY?
        upload_and_post(expnum, current_trial, oscommand_destination, filename, file_extensions)
コード例 #2
0
def move_datafiles(file_data_dicts, 
                   event, 
                   destination, 
                   current_trial, 
                   trial_doc_folder, 
                   default_folder, 
                   expnum):
    '''Moves datafile from mysql-descripted location to file structure.
    file_                   = mySQL-created dictionary that hold data location info.
    event                   = Dictionary containing event information for the event that "file_" belongs to.
    destination             = Location of Experiment file structure as defined by configuration
    current_trial           = Actually is the trial number that is being worked on.
    trial_doc_folder        = Location of Documentation Files for the event. '''
    mysqldb                 = bui.conn
    julian_folder           = datetime.datetime.utcfromtimestamp(event['time']).strftime(data_retrieval_time_format)

    # Upload every file associated with event.
    for file_ in file_data_dicts:
        filename                = file_[cfg_fl_dfile]
        oscommand_source        = "%s%s%s" % (default_folder, julian_folder, filename)
        oscommand_destination   = "%sTrial-%s/Rep-1/" % (destination, current_trial)
        pubChan                 = "%s_%s_%s" % (file_[cfg_fl_net], file_[cfg_fl_sta], file_[cfg_fl_chan])
        channel_data_dict       = mysqldb.retrieve_channel_position(pubChan, event[cfg_evt_time])
        file_extensions         = utils.find_extensions(oscommand_source)            

        report.append_report_if_valid(trial_doc_folder, 
                                      file_, 
                                      channel_data_dict, 
                                      event[cfg_evt_evid])

        utils.copy_file_exts(oscommand_source, 
                             oscommand_destination, 
                             file_extensions)

        upload_and_post(expnum, 
                        current_trial, 
                        oscommand_destination, 
                        filename, 
                        file_extensions)