Previous changeset 10:a46a509386d3 (2019-12-02) Next changeset 12:7e15490c2e58 (2020-04-24) |
Commit message:
"planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 81492a9c8b9e5649a3867bc30afe617a30fb47a1" |
modified:
create_or_update_organism.py |
b |
diff -r a46a509386d3 -r 3323060ba9a6 create_or_update_organism.py --- a/create_or_update_organism.py Mon Dec 02 05:50:13 2019 -0500 +++ b/create_or_update_organism.py Tue Apr 14 10:44:02 2020 -0400 |
[ |
@@ -2,10 +2,10 @@ from __future__ import print_function import argparse -import glob import json import logging import os +import re import shutil import stat import subprocess @@ -13,6 +13,7 @@ import tarfile import tempfile import time +from pathlib import Path from apollo import accessible_organisms from apollo.util import GuessOrg, OrgOrGuess @@ -49,6 +50,23 @@ return 'GALAXY_SHARED_DIR' not in os.environ or len(os.environ['GALAXY_SHARED_DIR'].lower().strip()) == 0 +def zip_data_dir(dataset_data_dir, tar): + tar.add(dataset_data_dir, arcname='./', recursive=False) + for r, d, f in os.walk(dataset_data_dir): + for file_name in f: + abs_file = os.path.join(r, file_name) + rel_dir = os.path.relpath(r, dataset_data_dir) + rel_file = os.path.join(rel_dir, file_name) + if not rel_file.startswith('./'): + rel_file = './' + rel_file + if os.path.islink(abs_file): + target = Path(abs_file).resolve().absolute().as_posix() + if re.match(r'.*/_metadata_files/[0-9]+/metadata_[0-9]+.dat', target): + # This is a metadata file generated by galaxy, symlink would certainly be dead on remote host, resolve it + abs_file = target + tar.add(abs_file, arcname=rel_file) + + if __name__ == '__main__': parser = argparse.ArgumentParser(description='Create or update an organism in an Apollo instance') parser.add_argument('jbrowse_src', help='Source JBrowse Data Directory') @@ -136,8 +154,7 @@ with tempfile.NamedTemporaryFile(suffix='.tar.gz') as archive: with tarfile.open(archive.name, mode="w:gz") as tar: dataset_data_dir = args.jbrowse_src - for file in glob.glob(dataset_data_dir): - tar.add(file, arcname=file.replace(dataset_data_dir, './')) + zip_data_dir(dataset_data_dir, tar) if IsBlatEnabled(): tar.add(path_2bit, arcname="./searchDatabaseData/genome.2bit") data = wa.remote.update_organism( @@ -177,8 +194,7 @@ with tempfile.NamedTemporaryFile(suffix='.tar.gz') as archive: with tarfile.open(archive.name, mode="w:gz") as tar: dataset_data_dir = args.jbrowse_src - for file in glob.glob(dataset_data_dir): - tar.add(file, arcname=file.replace(dataset_data_dir, './')) + zip_data_dir(dataset_data_dir, tar) if IsBlatEnabled(): with tempfile.TemporaryDirectory() as empty_dir: os.chmod(empty_dir, stat.S_IRUSR | stat.S_IXUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH) |