Skip to content

Commit

Permalink
Fix for missing included files on history export and import.
Browse files Browse the repository at this point in the history
Notes:

If a history was exported previously, galaxy would just serve the cached version.
In that case, it is better to make some changes to the history for example, by re-running
the last job and then exporting it.

Export of histories that haven't been exported previously should work without problems.

(cherry picked from commit 9ea0fee)
  • Loading branch information
vimalkvn authored and natefoo committed Oct 22, 2015
1 parent 3fe148d commit 57d0620
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
19 changes: 19 additions & 0 deletions lib/galaxy/tools/imp_exp/__init__.py
Expand Up @@ -175,6 +175,24 @@ def get_tag_str( tag, value ):
raise Exception( "Invalid dataset path: %s" % temp_dataset_file_name )
if datasets_usage_counts[ temp_dataset_file_name ] == 1:
shutil.move( temp_dataset_file_name, hda.file_name )

# Import additional files if present. Histories exported previously might not have this attribute set.
dataset_extra_files_path = ''
try:
dataset_extra_files_path = dataset_attrs[ 'extra_files_path' ]
except KeyError:
pass

if dataset_extra_files_path:
try:
file_list = os.listdir( os.path.join( archive_dir, dataset_extra_files_path ) )
except OSError:
file_list = []

if len( file_list ):
os.mkdir( hda.extra_files_path )
for extra_file in file_list:
shutil.move( os.path.join( archive_dir, dataset_extra_files_path, extra_file ), hda.extra_files_path )
else:
datasets_usage_counts[ temp_dataset_file_name ] -= 1
shutil.copyfile( temp_dataset_file_name, hda.file_name )
Expand Down Expand Up @@ -372,6 +390,7 @@ def default( self, obj ):
"uuid": ( lambda uuid: str( uuid ) if uuid else None )( obj.dataset.uuid ),
"annotation": to_unicode( getattr( obj, 'annotation', '' ) ),
"tags": get_item_tag_dict( obj ),
"extra_files_path": obj.extra_files_path
}
if not obj.visible and not include_hidden:
rval['exported'] = False
Expand Down
25 changes: 22 additions & 3 deletions lib/galaxy/tools/imp_exp/export_history.py
Expand Up @@ -14,13 +14,13 @@
from galaxy.util.json import dumps, loads


def get_dataset_filename( name, ext ):
def get_dataset_filename( name, ext, hid ):
"""
Builds a filename for a dataset using its name an extension.
"""
valid_chars = '.,^_-()[]0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
base = ''.join( c in valid_chars and c or '_' for c in name )
return base + ".%s" % ext
return base + "_%s.%s" % (hid, ext)


def create_archive( history_attrs_file, datasets_attrs_file, jobs_attrs_file, out_file, gzip=False ):
Expand Down Expand Up @@ -51,9 +51,28 @@ def create_archive( history_attrs_file, datasets_attrs_file, jobs_attrs_file, ou
for dataset_attrs in datasets_attrs:
if dataset_attrs['exported']:
dataset_file_name = dataset_attrs[ 'file_name' ] # Full file name.
dataset_hid = dataset_attrs[ 'hid']
dataset_archive_name = os.path.join( 'datasets',
get_dataset_filename( dataset_attrs[ 'name' ], dataset_attrs[ 'extension' ] ) )
get_dataset_filename( dataset_attrs[ 'name' ], dataset_attrs[ 'extension' ], dataset_hid ) )
history_archive.add( dataset_file_name, arcname=dataset_archive_name )

# Include additional files for example, files/images included in HTML output.
extra_files_path = dataset_attrs[ 'extra_files_path' ]
if extra_files_path:
try:
file_list = os.listdir( extra_files_path )
except OSError:
file_list = []

if len( file_list ):
dataset_extra_files_path = 'datasets/extra_files_path_%s' % dataset_hid
for fname in file_list:
history_archive.add( os.path.join( extra_files_path, fname ),
arcname=( os.path.join( dataset_extra_files_path, fname ) ) )
dataset_attrs[ 'extra_files_path' ] = dataset_extra_files_path
else:
dataset_attrs[ 'extra_files_path' ] = ''

# Update dataset filename to be archive name.
dataset_attrs[ 'file_name' ] = dataset_archive_name

Expand Down

0 comments on commit 57d0620

Please sign in to comment.