def test_generate_metadata_files(self):
     debug = True
     live = LiveEBISRARestServices(self.study_id, self.web_app_user_id, self.root_dir, debug)
     live.host_name = ''
     #live.generate_metadata_files(debug = True, action_type = 'VALIDATE')
     live.generate_metadata_files(debug = True, action_type = 'ADD')
     #live.generate_metadata_files(debug = True, action_type = 'MODIFY')
     #live.submit_files(debug = True)
     pass
def main():
    option_parser, opts, args = parse_command_line_parameters(**script_info)

    # Some needed variables
    study_id = opts.study_id
    debug = opts.debug
    action = opts.action
    web_app_user_id = 12169
    root_dir = '/home/wwwuser/user_data/studies'
    study_dir = root_dir + '/study_{0}'.format(str(study_id))
    ebi_export_log_fp = join(study_dir, 'ebi_export_log.txt')
    curl_output_fp = join(study_dir, 'curl_output.xml')
    curl_command_fp = join(study_dir, 'ebi_curl_command_{0}.sh'.format(study_id))

    # Get the live EBI function reference
    live = LiveEBISRARestServices(study_id, web_app_user_id, root_dir, debug)
    live.host_name = ''

    # Make one pass through metadata to generate files to validate. Also
    # necessary to populate the list of sequence files to send.
    live.generate_metadata_files(debug = True, action_type = 'VALIDATE')
    if len(live.errors):
        print 'Errors found while generating metadata files. Aborting. Errors are:'
        for error in live.errors:
            print 'Error: {0}'.format(error)
        return
    
    # Send the sequence files first - required for metadata to validate. If files have already been
    # sent then skip this step.
    data_access = data_access_factory(ServerConfig.data_access_type)
    statement = 'select case when ebi_files_sent is null then 0 else ebi_files_sent end as ebi_files_sent from study where study_id = {0}'.format(study_id)
    ebi_files_sent = data_access.dynamicMetadataSelect(statement).fetchone()[0]
    if ebi_files_sent != 1:
        try:
            live.submit_files(debug = True)
        except Exception, e:
            print 'Error encountered while submitting files. Aborting. Error was:'
            print str(e)
            return