From f14245aaed065b12c2f11643b11d71a33ec7590a Mon Sep 17 00:00:00 2001 From: Jeremy Goecks Date: Wed, 29 Sep 2010 16:46:42 -0400 Subject: [PATCH] Move export_history.py script into lib/galaxy/tools/imp_exp so that it's simpler to execute. --- export_history.sh | 4 --- lib/galaxy/tools/actions/history_imp_exp.py | 3 --- lib/galaxy/tools/imp_exp/__init__.py | 7 +++--- .../galaxy/tools/imp_exp}/export_history.py | 25 ++++++------------- 4 files changed, 12 insertions(+), 27 deletions(-) delete mode 100755 export_history.sh rename {scripts => lib/galaxy/tools/imp_exp}/export_history.py (78%) diff --git a/export_history.sh b/export_history.sh deleted file mode 100755 index edb0fa20793..00000000000 --- a/export_history.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -cd `dirname $0` -python ./scripts/export_history.py $@ diff --git a/lib/galaxy/tools/actions/history_imp_exp.py b/lib/galaxy/tools/actions/history_imp_exp.py index 8b0babe3e0c..6bc9f272f55 100644 --- a/lib/galaxy/tools/actions/history_imp_exp.py +++ b/lib/galaxy/tools/actions/history_imp_exp.py @@ -54,9 +54,6 @@ class ExportHistoryToolAction( ToolAction ): job_wrapper = JobExportHistoryArchiveWrapper( job ) cmd_line = job_wrapper.setup_job( trans, jeha, include_hidden=incoming[ 'include_hidden' ], \ include_deleted=incoming[ 'include_deleted' ] ) - - # Save jeha. - trans.sa_session.flush() # # Add parameters to job_parameter table. diff --git a/lib/galaxy/tools/imp_exp/__init__.py b/lib/galaxy/tools/imp_exp/__init__.py index 18b58a2db7b..0851e91ee83 100644 --- a/lib/galaxy/tools/imp_exp/__init__.py +++ b/lib/galaxy/tools/imp_exp/__init__.py @@ -199,9 +199,10 @@ class JobExportHistoryArchiveWrapper( object, UsesHistory, UsesAnnotations ): options = "" if jeha.compressed: options = "-G" - return "%s %s %s %s %s %s" % ( os.path.join( os.path.abspath( os.getcwd() ), "export_history.sh" ), \ - options, history_attrs_filename, datasets_attrs_filename, \ - jobs_attrs_filename, jeha.dataset.file_name ) + return "python %s %s %s %s %s %s" % ( + os.path.join( os.path.abspath( os.getcwd() ), "lib/galaxy/tools/imp_exp/export_history.py" ), \ + options, history_attrs_filename, datasets_attrs_filename, jobs_attrs_filename, \ + jeha.dataset.file_name ) def cleanup_after_job( self, db_session ): """ Remove temporary directory and attribute files generated during setup for this job. """ diff --git a/scripts/export_history.py b/lib/galaxy/tools/imp_exp/export_history.py similarity index 78% rename from scripts/export_history.py rename to lib/galaxy/tools/imp_exp/export_history.py index b9ceb302fda..f5fa8b9fbf7 100644 --- a/scripts/export_history.py +++ b/lib/galaxy/tools/imp_exp/export_history.py @@ -2,20 +2,13 @@ """ Export a history to an archive file using attribute files. -NOTE: This should not be called directly. Use the set_metadata.sh script in Galaxy's -top level directly. - usage: %prog history_attrs dataset_attrs job_attrs out_file -G, --gzip: gzip archive file - -D, --delete_dir: delete attribute files' directory if operation completed successfully """ + from galaxy import eggs -import os, pkg_resources, tempfile, tarfile -pkg_resources.require( "bx-python" ) -import sys, traceback, fileinput from galaxy.util.json import * -from warnings import warn -from bx.cookbook import doc_optparse +import optparse, sys, os, tempfile, tarfile def create_archive( history_attrs_file, datasets_attrs_file, jobs_attrs_file, out_file, gzip=False ): """ Create archive from the given attribute/metadata files and save it to out_file. """ @@ -63,17 +56,15 @@ def create_archive( history_attrs_file, datasets_attrs_file, jobs_attrs_file, ou # Status. return 'Created history archive.' except Exception, e: - return 'Error creating history archive: %s' + str( e ), sys.stderr + return 'Error creating history archive: %s' % str( e ), sys.stderr if __name__ == "__main__": # Parse command line. - options, args = doc_optparse.parse( __doc__ ) - try: - gzip = bool( options.gzip ) - delete_dir = bool( options.delete_dir ) - history_attrs, dataset_attrs, job_attrs, out_file = args - except: - doc_optparse.exception() + parser = optparse.OptionParser() + parser.add_option( '-G', '--gzip', dest='gzip', action="store_true", help='Compress archive using gzip.' ) + (options, args) = parser.parse_args() + gzip = bool( options.gzip ) + history_attrs, dataset_attrs, job_attrs, out_file = args # Create archive. status = create_archive( history_attrs, dataset_attrs, job_attrs, out_file, gzip )