Mercurial > repos > tduigou > data_manager_cache
changeset 0:e0b92d203870 draft
"planemo upload commit f40274f6b9f6a15eb4022aab21286d4c96cd8475-dirty"
| author | tduigou |
|---|---|
| date | Mon, 04 Jul 2022 13:28:30 +0000 |
| parents | |
| children | 35c33747b9e3 |
| files | data_manager/cache_fetcher.py data_manager/cache_fetcher.xml data_manager_conf.xml tool-data/cache.loc.sample tool_data_table_conf.xml.sample |
| diffstat | 5 files changed, 112 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data_manager/cache_fetcher.py Mon Jul 04 13:28:30 2022 +0000 @@ -0,0 +1,53 @@ +from os import ( + path as os_path, + mkdir as os_mkdir +) + +from requests import get as r_get + +from tempfile import ( + NamedTemporaryFile +) + +import argparse + +def download( + url: str, + file: str = "" +) -> str: + """ + Download a file from 'url' and save it as 'file'. + Parameters: + url -- URL the file is downloaded from + file -- (Optional) filename the downloaded file is saved into (default: "") + Returns: + A filename where the downloaded file has stored into + """ + r = r_get(url) + if not file: + f = NamedTemporaryFile( + mode='wb', + delete=False + ) + file = f.name + else: + f = open(file, 'wb') + f.write(r.content) + f.close() + return file + +parser = argparse.ArgumentParser(description="Download a cache file") +parser.add_argument('-u','--url', required=True, default=None, type=str, help="URL the file is downloaded from") +parser.add_argument('-o','--outfile', required=True, default=None, type=str, help="A filename where the downloaded file has stored into") + +args = parser.parse_args() + +url= args.url #"https://gitlab.com/breakthewall/rrCache-data/-/raw/master/" +filename= os_path.basename(args.outfile) #"cid_strc.json.gz" +cache_dir=os_path.dirname(args.outfile) #'${GALAXY_DATA_MANAGER_DATA_PATH}'+'/rpextractsink/cache/' +full_filename=os_path.join(cache_dir,filename) #'${GALAXY_DATA_MANAGER_DATA_PATH}'+'/rpextractsink/cache/cid_strc.json.gz' + +if not os_path.isdir(cache_dir): + os_mkdir(cache_dir) + +download(url+filename, full_filename) \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data_manager/cache_fetcher.xml Mon Jul 04 13:28:30 2022 +0000 @@ -0,0 +1,30 @@ +<?xml version="1.0"?> +<tool id="cache_fetcher" name="cache data manager" tool_type="manage_data" profile="18.09" version="0.0.1"> + <description>Download cache file</description> + <requirements> + <requirement type="package" version="3.7">python</requirement> + </requirements> + <command detect_errors="exit_code"><![CDATA[ + python '$__tool_directory__/cache_fetcher.py' + --outfile '$out_file' + --url '$url' + ]]> + </command> + <inputs> + <param name="url" type="text" value="https://gitlab.com/breakthewall/rrCache-data/-/raw/master/" label="URL to download the cache file" optional="False" /> + </inputs> + <outputs> + <data name="out_file" format="data_manager_json" /> + </outputs> + <tests> + <test> + <param name="url" value="https://gitlab.com/breakthewall/rrCache-data/-/raw/master/"/> + <output name="out_file" value="cid_strc.json.gz" compare="contains"/> + </test> + </tests> + <help><![CDATA[ +This tool fetches a cache file. + ]]></help> + <citations> + </citations> +</tool>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data_manager_conf.xml Mon Jul 04 13:28:30 2022 +0000 @@ -0,0 +1,19 @@ +<?xml version="1.0"?> +<data_managers> + <data_manager tool_file="data_manager/cache_fetcher.xml" id="cache_fetcher"> + <data_table name="cache"> + <output> + <column name="value" /> + <column name="name" /> + <column name="path" output_ref="out_file"> + <move type="file" relativize_symlinks="True"> + <source>${path}</source> + <target base="${GALAXY_DATA_MANAGER_DATA_PATH}">rpextractsink/cache/${name}.json.gz</target> + </move> + <value_translation>${GALAXY_DATA_MANAGER_DATA_PATH}/rpextractsink/cache/${name}.json.gz</value_translation> + <value_translation type="function">abspath</value_translation> + </column> + </output> + </data_table> + </data_manager> +</data_managers> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tool-data/cache.loc.sample Mon Jul 04 13:28:30 2022 +0000 @@ -0,0 +1,3 @@ +## Cache file +#Value Name Path +cid_strc cid_strc.json.gz rpextractsink/cache/cid_strc.json.gz
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tool_data_table_conf.xml.sample Mon Jul 04 13:28:30 2022 +0000 @@ -0,0 +1,7 @@ +<tables> + <!-- Location of cache file --> + <table name="cache" comment_char="#"> + <columns>value, name, path</columns> + <file path="tool-data/cache.loc" /> + </table> +</tables> \ No newline at end of file
