Files
galaxy/scripts/api/fetch_to_library.py
T
Nicola Soranzo 8cdca0f343 Revert some requests import changes
introduced in https://github.com/galaxyproject/galaxy/pull/18003 .
In particular, when using requests in the tests to connect to Galaxy
or the ToolShed it's not needed to use the modified headers.

Also:
- Move some imports after conditional imports.
- Fix type annotations in `lib/tool_shed/test/base/populators.py`
- Fix typo bug in `test/unit/util/test_get_url.py`
2024-05-23 15:55:56 +01:00

29 lines
959 B
Python

import argparse
import json
import requests
import yaml
def main():
parser = argparse.ArgumentParser(description="Upload a directory into a data library")
parser.add_argument("-u", "--url", dest="url", required=True, help="Galaxy URL")
parser.add_argument("-a", "--api", dest="api_key", required=True, help="API Key")
parser.add_argument("target", metavar="FILE", type=str, help="file describing data library to fetch")
args = parser.parse_args()
with open(args.target) as f:
target = yaml.safe_load(f)
histories_url = args.url + "/api/histories"
new_history_response = requests.post(histories_url, data={"key": args.api_key})
fetch_url = args.url + "/api/tools/fetch"
payload = {"key": args.api_key, "targets": json.dumps([target]), "history_id": new_history_response.json()["id"]}
response = requests.post(fetch_url, data=payload)
print(response.content)
if __name__ == "__main__":
main()