Repository 'data_manager_manual'
hg clone https://toolshed.g2.bx.psu.edu/repos/iuc/data_manager_manual

Changeset 0:81ed42c0721a (2018-01-14)
Next changeset 1:6524e573d9c2 (2018-01-15)
Commit message:
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_manual commit 9f2cdfc1302dce000f9a86d13d4af204cf1dc89d
added:
README
data_manager/data_manager_manual.py
data_manager/data_manager_manual.xml
data_manager_conf.xml
tool_data_table_conf.xml.sample
b
diff -r 000000000000 -r 81ed42c0721a README
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/README Sun Jan 14 09:52:16 2018 -0500
b
@@ -0,0 +1,1 @@
+This tool manually builds local data and populates tool data tables.
b
diff -r 000000000000 -r 81ed42c0721a data_manager/data_manager_manual.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/data_manager/data_manager_manual.py Sun Jan 14 09:52:16 2018 -0500
[
b'@@ -0,0 +1,172 @@\n+#!/usr/bin/env python\n+# Dan Blankenberg\n+\n+import json\n+import logging\n+import optparse\n+import os\n+import shutil\n+import tempfile\n+import urllib2\n+\n+from xml.etree.ElementTree import tostring\n+try:\n+    # For Python 3.0 and later\n+    from shutil import unpack_archive\n+except ImportError:\n+    # Fall back to Python 2 import\n+    from setuptools.archive_util import unpack_archive\n+\n+try:\n+    # For Python 3.0 and later\n+    from urllib.request import urlretrieve\n+except ImportError:\n+    # Fall back to Python 2 imports\n+    from urllib import urlretrieve\n+\n+_log_name = __name__\n+if _log_name == \'__builtin__\':\n+    _log_name = \'toolshed.installed.manual.data.manager\'\n+log = logging.getLogger( _log_name )\n+\n+\n+# --- These methods are called by/within the Galaxy Application\n+def exec_before_job( app, inp_data, out_data, param_dict, tool=None, **kwd ):\n+    # Look for any data tables that haven\'t been defined for this data manager before and dynamically add them to Galaxy\n+    param_dict = dict( **param_dict )\n+    data_tables_param = param_dict.get( \'data_tables\', [] )\n+    if not isinstance( data_tables_param, list ):\n+        data_tables_param = [data_tables_param]\n+    if tool:\n+        tool_shed_repository = tool.tool_shed_repository\n+    else:\n+        tool_shed_repository = None\n+    tdtm = None\n+    data_manager = app.data_managers.get_manager( tool.data_manager_id, None )\n+    for data_table_param in data_tables_param:\n+        data_table_name = data_table_param.get( \'data_table_name\', None )\n+        if data_table_name:\n+            # get data table managed by this data Manager\n+            data_table = app.tool_data_tables.get_tables().get( str( data_table_name ), None )\n+            if data_table:\n+                data_table_filename = data_table.get_filename_for_source( data_manager, None )\n+                if not data_table_filename:\n+                    if tdtm is None:\n+                        from tool_shed.tools import data_table_manager\n+                        tdtm = data_table_manager.ToolDataTableManager( app )\n+                        target_dir, tool_path, relative_target_dir = tdtm.get_target_install_dir( tool_shed_repository )\n+                    # Dynamically add this data table\n+                    log.debug( "Attempting to dynamically create a missing Tool Data Table named %s." % data_table_name )\n+                    repo_info = tdtm.generate_repository_info_elem_from_repository( tool_shed_repository, parent_elem=None )\n+                    if repo_info is not None:\n+                        repo_info = tostring( repo_info )\n+                    tmp_file = tempfile.NamedTemporaryFile()\n+                    tmp_file.write( __get_new_xml_definition( app, data_table, data_manager, repo_info, target_dir ) )\n+                    tmp_file.flush()\n+                    app.tool_data_tables.add_new_entries_from_config_file( tmp_file.name, None, app.config.shed_tool_data_table_config, persist=True )\n+                    tmp_file.close()\n+\n+\n+def __get_new_xml_definition( app, data_table, data_manager, repo_info=None, location_file_dir=None ):\n+    sub_dict = { \'table_name\': data_table.name, \'comment_char\': \'\', \'columns\': \'\', \'file_path\': \'\' }\n+    sub_dict.update( data_manager.get_tool_shed_repository_info_dict() )\n+    if data_table.comment_char:\n+        sub_dict[\'comment_char\'] = \'comment_char="%s"\' % ( data_table.comment_char )\n+    for i, name in enumerate( data_table.get_column_name_list() ):\n+        if name is not None:\n+            sub_dict[\'columns\'] = "%s\\n%s" % ( sub_dict[\'columns\'], \'<column name="%s" index="%s" />\' % ( name, i ) )\n+    location_file_dir = location_file_dir or app.config.galaxy_data_manager_data_path\n+    for filename in data_table.filenames.keys():\n+        sub_dict[\'file_path\'] = os.path.basename( filename )\n+        sub_dict[\'file_path\'] = os.path.join( location_file_dir, sub_dict[\'file_path\'] )  # os.path.abspath?\n+        if not os.path.exists( sub_dict[\'f'..b'e empty file\n+            log.debug( "Attempting to create a missing location file %s." % sub_dict[\'file_path\'] )\n+            open( sub_dict[\'file_path\'], \'wb+\' ).close()\n+        break\n+    sub_dict[ \'repo_info\' ] = repo_info or \'\'\n+    return """\n+            <tables><table name="%(table_name)s" %(comment_char)s>\n+                %(columns)s\n+                <file path="%(file_path)s" />\n+                %(repo_info)s\n+            </table></tables>\n+           """ % sub_dict\n+\n+\n+def galaxy_code_get_available_data_tables( trans ):\n+    # list of data tables\n+    return [ ( x, x, False ) for x in trans.app.tool_data_tables.get_tables().keys() ]\n+\n+\n+def galaxy_code_get_available_data_table_columns( trans, data_table_name ):\n+    return [ ( x, x, True ) for x in trans.app.tool_data_tables.get( data_table_name ).get_column_name_list() ]\n+# --- End Galaxy called Methods ---\n+\n+\n+def get_data_table_entries( params, galaxy_data_manager_data_path ):\n+    rval = {}\n+    data_tables = params.get( \'data_tables\', [] )\n+    for data_table in data_tables:\n+        entry_dict = {}\n+        for column in data_table.get( \'columns\', [] ):\n+            value = column.get( \'data_table_column_value\', \'\' )\n+            if column.get( \'is_path\', {} ).get( \'is_path_selector\', None ) == \'yes\' and column.get( \'is_path\', {} ).get( \'abspath\', None ) == \'abspath\':\n+                value = os.path.abspath( os.path.join( galaxy_data_manager_data_path, value ) )\n+            entry_dict[ column.get( \'data_table_column_name\', \'\' ) ] = value\n+        data_table_name = data_table[\'data_table_name\']\n+        rval[ data_table_name ] = rval.get( data_table_name, [] )\n+        rval[ data_table_name ].append( entry_dict )\n+    return rval\n+\n+\n+def get_file_content( params, target_directory ):\n+    directory_content = params.get( \'directory_content\', [] )\n+    for content in directory_content:\n+        target_path = os.path.join( target_directory, content.get( \'subdir\', \'\' ) )\n+        try:\n+            os.makedirs( target_path )\n+        except OSError:\n+            pass\n+        if content.get( \'file_source\', {}).get( \'file_source_selector\', None ) == \'URL\':\n+            ( filename, headers ) = urlretrieve( content.get( \'file_source\', {}).get( \'file_URL\', None ) )\n+            try:\n+                bname = headers[\'Content-Disposition\']\n+            except KeyError:\n+                bname = os.path.basename( urllib2.urlparse.urlsplit( content.get( \'file_source\', {}).get( \'file_URL\', None ) ).path )\n+        else:\n+            filename = content.get( \'file_source\', {}).get( \'file_history\', None )\n+            bname = os.path.basename( filename )\n+        file_action = content.get( \'file_action\', {}).get( \'file_action_selector\', None )\n+        if file_action == \'unpack\':\n+            unpack_archive( filename, target_path )\n+        else:\n+            filename_override = content.get( \'file_action\', {}).get( \'filename_override\', None )\n+            if filename_override:\n+                target_path = os.path.join( target_path, filename_override )\n+            else:\n+                target_path = os.path.join( target_path, bname )\n+            shutil.copyfile( filename, target_path )\n+    return len( directory_content )\n+\n+\n+def main():\n+    parser = optparse.OptionParser()\n+    parser.add_option( \'\', \'--galaxy_data_manager_data_path\', dest=\'galaxy_data_manager_data_path\', default=\'\', help=\'Root path for galaxy_data_manager_data_path\' )\n+    (options, args) = parser.parse_args()\n+\n+    filename = args[0]\n+\n+    params = json.loads( open( filename ).read() )\n+    target_directory = params[ \'output_data\' ][0][\'extra_files_path\']\n+\n+    data_table_entries = get_data_table_entries( params[\'param_dict\'], options.galaxy_data_manager_data_path )\n+\n+    # save info to json file\n+    open( filename, \'wb\' ).write( json.dumps( { "data_tables": data_table_entries} ) )\n+\n+    get_file_content( params[\'param_dict\'], target_directory )\n+\n+\n+if __name__ == "__main__":\n+    main()\n'
b
diff -r 000000000000 -r 81ed42c0721a data_manager/data_manager_manual.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/data_manager/data_manager_manual.xml Sun Jan 14 09:52:16 2018 -0500
[
@@ -0,0 +1,69 @@
+<tool id="data_manager_manual" name="Manual Data Manager" version="0.0.1" tool_type="manage_data">
+    <options sanitize="False" />
+    <description>Entry Builder</description>
+    <command detect_errors="exit_code"><![CDATA[
+        python '$__tool_directory__/data_manager_manual.py'
+        '${out_file}'
+        --galaxy_data_manager_data_path '${__app__.config.galaxy_data_manager_data_path}'
+    ]]></command>
+    <inputs>
+        <repeat name="data_tables" title="Data Table to define" min="1">
+            <param name="data_table_name" type="select" multiple="False" optional="False" label="Choose Desired Data Table"
+                dynamic_options="galaxy_code_get_available_data_tables( __trans__ )" refresh_on_change="True"/>
+        <repeat name="columns" title="Table Columns" min="1">
+            <param name="data_table_column_name" type="select" multiple="False" optional="False" label="Column Name"
+                dynamic_options="galaxy_code_get_available_data_table_columns( __trans__, data_table_name )" />
+            <!-- <param name="data_table_column_name" type="text" label="Column Name"/> -->
+            <param name="data_table_column_value" type="text" label="Value to use for data table column"/>
+            <conditional name="is_path">
+                <param name="is_path_selector" type="select" label="Value is a path">
+                    <option value="yes">Yes</option>
+                    <option value="no" selected="True">No</option>
+                </param>
+                <when value="yes">
+                    <param name="abspath" type="boolean" label="Apply abspath" checked="True" truevalue="abspath" falsevalue="" />
+                </when>
+                <when value="no"/>
+            </conditional>
+        </repeat>
+        </repeat>
+        <repeat name="directory_content" title="Directory Content">
+            <param name="subdir" type="text" label="Place in Subdirectory" value=""/>
+            <conditional name="file_source">
+                <param name="file_source_selector" type="select" label="File Content Source">
+                    <option value="history">History Item</option>
+                    <option value="URL" selected="True">URL</option>
+                </param>
+                <when value="history">
+                    <param name="file_history" type="data" multiple="false" optional="false" format="data" label="File from history" />
+                </when>
+                <when value="URL">
+                    <param name="file_URL" type="text" label="Fetch from URL" value=""/>
+                </when>
+            </conditional>
+            <conditional name="file_action">
+                <param name="file_action_selector" type="select" label="File Actions">
+                    <option value="unpack">Extract Archive</option>
+                    <option value="None" selected="True">None</option>
+                </param>
+                <when value="None">
+                    <param name="filename_override" type="text" label="Override with Filename" value=""/>
+                </when>
+                <when value="unpack">
+                </when>
+            </conditional>
+        </repeat>
+    </inputs>
+    <outputs>
+        <data name="out_file" format="data_manager_json" dbkey="dbkey"/>
+    </outputs>
+    <tests>
+    </tests>
+    <help>
+**What it does**
+
+This tool allows manually specifying data table entries and optionally providing filesystem contents.
+
+    </help>
+    <code file="data_manager_manual.py" />
+</tool>
b
diff -r 000000000000 -r 81ed42c0721a data_manager_conf.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/data_manager_conf.xml Sun Jan 14 09:52:16 2018 -0500
b
@@ -0,0 +1,4 @@
+<?xml version="1.0"?>
+<data_managers>
+    <data_manager tool_file="data_manager/data_manager_manual.xml" id="data_manager_manual" version="0.0.1" undeclared_tables="True" />
+</data_managers>
b
diff -r 000000000000 -r 81ed42c0721a tool_data_table_conf.xml.sample
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tool_data_table_conf.xml.sample Sun Jan 14 09:52:16 2018 -0500
b
@@ -0,0 +1,2 @@
+<tables>
+</tables>