From d44f1123892cdb91b97babd9acc92d4c9e987bcd Mon Sep 17 00:00:00 2001 From: Cameron Hyde Date: Mon, 29 Jul 2024 07:25:49 +1000 Subject: [PATCH] PEP8 format --- .../parse_tools_to_produce_yml_files.py | 53 +++++++++++-------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/subdomains/scripts/parse_tools_to_produce_yml_files.py b/subdomains/scripts/parse_tools_to_produce_yml_files.py index 2651d926..8ba2d0c3 100644 --- a/subdomains/scripts/parse_tools_to_produce_yml_files.py +++ b/subdomains/scripts/parse_tools_to_produce_yml_files.py @@ -1,15 +1,22 @@ -# coding: utf-8 +"""Parse tools from a toolkit.yaml file to produce yml files for tool +installation. +""" + import yaml -import io import os -import re +import re import argparse import tools_au -parser = argparse.ArgumentParser(description='Create installation yaml files from a Yaml file containing the panel_view/Toolkit data') -parser.add_argument('--tk', action="store", dest='toolkit', help='Path of the toolkit.yaml file') # Toolkit.yaml file -parser.add_argument('--yml-folder', action="store", dest='dest', help='Folder containing the yml files with tool installed in the target instance') # Folder containing the .yml and yml.lock containing the tools installed in the target instance +parser = argparse.ArgumentParser( + description='Create installation yaml files from a Yaml file containing' + ' the panel_view/Toolkit data') +parser.add_argument('--tk', action="store", dest='toolkit', + help='Path of the toolkit.yaml file') +parser.add_argument('--yml-folder', action="store", dest='dest', + help='Folder containing the yml files with tool installed' + ' in the target instance') args = parser.parse_args() print(args.toolkit) @@ -18,22 +25,24 @@ with open(args.toolkit, 'r') as stream: data_loaded = yaml.safe_load(stream) -for i in range(3,len(data_loaded['items'])-2): - section=data_loaded['items'][i]['id'] - name=data_loaded['items'][i]['name'] - f = open(section+".yml", "w") - f.write("tool_panel_section_label: "+name+"\ntools:\n") - for j in data_loaded['items'][i]['items']: #for loop on toolkit sections - path=j['id'] - infos=path.replace('toolshed.g2.bx.psu.edu/repos/',"") - pattern=re.compile(r"([^\/]+)\/([^\/]+)\/") # extract the owner (group1) and the name of the tool (group2) - for match in pattern.finditer(infos): #for each tool in the seection - owner=match.group(1) - tool=match.group(2) - installed = os.popen('grep -r "'+tool+'" '+args.dest).read() #verify the tool is not already installed - if installed=='': ## if tool not installed - f.write("- name: "+tool+"\n") - f.write(" owner: "+owner+"\n") +for i in range(3, len(data_loaded['items']) - 2): + section = data_loaded['items'][i]['id'] + name = data_loaded['items'][i]['name'] + f = open(section + ".yml", "w") + f.write("tool_panel_section_label: " + name + "\ntools:\n") + for j in data_loaded['items'][i]['items']: # for loop on toolkit sections + path = j['id'] + infos = path.replace('toolshed.g2.bx.psu.edu/repos/', "") + # extract the owner (group1) and the name of the tool (group2) + pattern = re.compile(r"([^\/]+)\/([^\/]+)\/") + for match in pattern.finditer(infos): # for each tool in the seection + owner = match.group(1) + tool = match.group(2) + # verify the tool is not already installed + installed = os.popen('grep -r "' + tool + '" ' + args.dest).read() + if installed == '': # if tool not installed + f.write("- name: " + tool + "\n") + f.write(" owner: " + owner + "\n") f.close() tools_au.parse()