'Add datasets to library using any upload_option'

def upload_library_dataset(self, cntrller, library_id, folder_id, filename='', server_dir='', replace_id='', upload_option='upload_file', file_type='auto', dbkey='hg18', space_to_tab='', link_data_only='copy_files', preserve_dirs='Yes', filesystem_paths='', roles=[], ldda_message='', hda_ids='', template_refresh_field_name='1_field_name', template_refresh_field_contents='', template_fields=[], show_deleted='False', strings_displayed=[]):

    params = dict(cntrller=cntrller, library_id=library_id, folder_id=folder_id)
    url = '/library_common/upload_library_dataset'
    if replace_id:
        params['replace_id'] = replace_id
    self.visit_url(url, params=params)
    if template_refresh_field_contents:
        self.refresh_form(template_refresh_field_name, template_refresh_field_contents)
    for tup in template_fields:
        tc.fv('1', tup[0], tup[1])
    tc.fv('upload_library_dataset', 'library_id', library_id)
    tc.fv('upload_library_dataset', 'folder_id', folder_id)
    tc.fv('upload_library_dataset', 'show_deleted', show_deleted)
    tc.fv('upload_library_dataset', 'ldda_message', ldda_message)
    tc.fv('upload_library_dataset', 'file_type', file_type)
    tc.fv('upload_library_dataset', 'dbkey', dbkey)
    if space_to_tab:
        tc.fv('upload_library_dataset', 'space_to_tab', space_to_tab)
    for role_id in roles:
        tc.fv('upload_library_dataset', 'roles', role_id)
    self.refresh_form('upload_option', upload_option)
    if (upload_option == 'import_from_history'):
        for check_str in strings_displayed:
            self.check_page_for_string(check_str)
        if hda_ids:
            try:
                tc.fv('add_history_datasets_to_library', 'hda_ids', hda_ids)
            except:
                tc.fv('add_history_datasets_to_library', 'hda_ids', '1')
        tc.submit('add_history_datasets_to_library_button')
    else:
        if (upload_option in ['upload_paths', 'upload_directory']):
            tc.fv('upload_library_dataset', 'link_data_only', link_data_only)
        if (upload_option == 'upload_paths'):
            tc.fv('upload_library_dataset', 'filesystem_paths', filesystem_paths)
        if ((upload_option == 'upload_directory') and server_dir):
            tc.fv('upload_library_dataset', 'server_dir', server_dir)
        if (upload_option == 'upload_file'):
            if filename:
                filename = self.get_filename(filename)
                tc.formfile('upload_library_dataset', 'files_0|file_data', filename)
        for check_str in strings_displayed:
            self.check_page_for_string(check_str)
        tc.submit('runtool_btn')
    self.library_wait(library_id)
