changeset 1:8dd4076813ef draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 8652f36a3a3838dca989426961561e81432acf4f
author iuc
date Tue, 04 Apr 2017 17:50:42 -0400
parents 078e803565cf
children 3d628f1e1bef
files data_manager/data_manager.py data_manager/ncbi_taxonomy_fetcher.xml
diffstat 2 files changed, 29 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/data_manager/data_manager.py	Fri Nov 06 14:16:28 2015 -0500
+++ b/data_manager/data_manager.py	Tue Apr 04 17:50:42 2017 -0400
@@ -3,17 +3,15 @@
 import json
 import os
 import shutil
-import sys
 import tarfile
-import urllib2
 import zipfile
+try:
+    # For Python 3.0 and later
+    from urllib.request import Request, urlopen
+except ImportError:
+    # Fall back to Python 2 imports
+    from urllib2 import Request, urlopen
 
-parser = argparse.ArgumentParser(description='Create data manager json.')
-parser.add_argument('--out', dest='output', action='store', help='JSON filename')
-parser.add_argument('--name', dest='name', action='store', default=str(datetime.date.today()), help='Data table entry unique ID')
-parser.add_argument('--url', dest='url', action='store', default='ftp://ftp.ncbi.nih.gov/pub/taxonomy/taxdump.tar.gz', help='Download URL')
-
-args = parser.parse_args()
 
 def url_download(url, workdir):
     file_path = os.path.join(workdir, 'download.dat')
@@ -22,22 +20,18 @@
     src = None
     dst = None
     try:
-        req = urllib2.Request(url)
-        src = urllib2.urlopen(req)
-        dst = open(file_path, 'wb')
-        while True:
-            chunk = src.read(2**10)
-            if chunk:
-                dst.write(chunk)
-            else:
-                break
-    except Exception, e:
-        print >>sys.stderr, str(e)
+        req = Request(url)
+        src = urlopen(req)
+        with open(file_path, 'wb') as dst:
+            while True:
+                chunk = src.read(2**10)
+                if chunk:
+                    dst.write(chunk)
+                else:
+                    break
     finally:
         if src:
             src.close()
-        if dst:
-            dst.close()
     if tarfile.is_tarfile(file_path):
         fh = tarfile.open(file_path, 'r:*')
     elif zipfile.is_zipfile(file_path):
@@ -64,5 +58,12 @@
         shutil.move(os.path.join(output_path, filename), target_directory)
     file(args.output, 'w').write(json.dumps(data_manager_json))
 
+
 if __name__ == '__main__':
+    parser = argparse.ArgumentParser(description='Create data manager json.')
+    parser.add_argument('--out', dest='output', action='store', help='JSON filename')
+    parser.add_argument('--name', dest='name', action='store', default=str(datetime.date.today()), help='Data table entry unique ID')
+    parser.add_argument('--url', dest='url', action='store', default='ftp://ftp.ncbi.nih.gov/pub/taxonomy/taxdump.tar.gz', help='Download URL')
+    args = parser.parse_args()
+
     main(args)
--- a/data_manager/ncbi_taxonomy_fetcher.xml	Fri Nov 06 14:16:28 2015 -0500
+++ b/data_manager/ncbi_taxonomy_fetcher.xml	Tue Apr 04 17:50:42 2017 -0400
@@ -1,25 +1,22 @@
 <?xml version="1.0"?>
 <tool id="ncbi_taxonomy_fetcher" name="NCBI" tool_type="manage_data" version="1.0.0">
     <description>taxonomy downloader</description>
-    <stdio>
-        <exit_code description="Error" level="fatal" range="1:" />
-    </stdio>
-    <command interpreter="python">
+    <command detect_errors="exit_code">
     <![CDATA[
-        data_manager.py --out "${out_file}"
+        python '$__tool_directory__/data_manager.py' --out '${out_file}'
         #if $taxonomy_url:
-            --url "${taxonomy_url}"
+            --url '${taxonomy_url}'
         #end if
         #if $database_name:
-            --name "${database_name}"
+            --name '${database_name}'
         #end if
     ]]>
     </command>
     <inputs>
-        <param help="Enter a unique identifier, or leave blank for today's date" label="Name for this database" name="database_name" type="text" optional="True" />
-        <param label="Enter URL for taxonomy files" name="taxonomy_url" type="text" />
+        <param name="database_name" type="text" optional="true" label="Name for this database" help="Enter a unique identifier, or leave blank for today's date" />
+        <param name="taxonomy_url" type="text" label="Enter URL for taxonomy files" />
     </inputs>
     <outputs>
-        <data format="data_manager_json" name="out_file" />
+        <data name="out_file" format="data_manager_json" />
     </outputs>
 </tool>