annotate cp_common_functions.py @ 6:f24c370e5ea4 draft default tip

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
author bgruening
date Sun, 05 Nov 2023 09:35:54 +0000
parents f8fa0f6718a3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
1 INDENTATION = " "
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
2 LINE_NUM_MODULES = 4
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
3
4
f8fa0f6718a3 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
bgruening
parents: 2
diff changeset
4
2
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
5 def get_json_value(json_input, keys_path):
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
6 """Returns the value specified in keys_path (using dot notation) or an empty string if the key doesn't exist"""
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
7 if not isinstance(json_input, dict):
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
8 return ""
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
9 keys = keys_path.split(".")
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
10 try:
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
11 value = json_input[keys[0]]
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
12 for key in keys[1:]:
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
13 value = value[key]
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
14 return value
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
15 except KeyError:
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
16 return ""
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
17
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
18
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
19 def concat_conditional(a, b):
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
20 if a == "" or b == "":
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
21 return ""
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
22 else:
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
23 return f"{a}_{b}"
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
24
4
f8fa0f6718a3 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
bgruening
parents: 2
diff changeset
25
2
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
26 def get_total_number_of_modules(pipeline_lines):
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
27 """Gets the number of modules from the header of the previous pipeline"""
6
f24c370e5ea4 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
bgruening
parents: 4
diff changeset
28 number_of_modules = pipeline_lines[LINE_NUM_MODULES].strip().split(":")[1]
2
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
29 return int(number_of_modules)
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
30
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
31
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
32 def get_pipeline_lines(input_pipeline):
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
33 """Returns a list with the lines in the .cppipe file"""
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
34 with open(input_pipeline) as f:
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
35 lines = f.readlines()
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
36 return lines
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
37
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
38
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
39 def update_module_count(pipeline_lines, count):
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
40 """Updates the number of modules in the .cppipe header"""
6
f24c370e5ea4 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
bgruening
parents: 4
diff changeset
41 module_count_entry = pipeline_lines[LINE_NUM_MODULES].strip().split(":")[0]
2
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
42 pipeline_lines[4] = f"{module_count_entry}:{count}\n"
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
43 return pipeline_lines
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
44
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
45
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
46 def write_pipeline(filename, lines_pipeline):
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
47 """Writes the lines composing the pipeline into a file"""
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
48 with open(filename, "w") as f:
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
49 f.writelines(lines_pipeline)
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
50
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
51
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
52 def build_header(module_name, module_number):
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
53 """Creates the first line of a module given the name and module number"""
6
f24c370e5ea4 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
bgruening
parents: 4
diff changeset
54 result = "|".join(
f24c370e5ea4 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
bgruening
parents: 4
diff changeset
55 [
f24c370e5ea4 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
bgruening
parents: 4
diff changeset
56 f"{module_name}:[module_num:{module_number}",
f24c370e5ea4 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
bgruening
parents: 4
diff changeset
57 "svn_version:\\'Unknown\\'",
f24c370e5ea4 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
bgruening
parents: 4
diff changeset
58 "variable_revision_number:4",
f24c370e5ea4 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
bgruening
parents: 4
diff changeset
59 "show_window:False",
f24c370e5ea4 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
bgruening
parents: 4
diff changeset
60 "notes:\\x5B\\x5D",
f24c370e5ea4 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
bgruening
parents: 4
diff changeset
61 "batch_state:array(\\x5B\\x5D, dtype=uint8)",
f24c370e5ea4 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
bgruening
parents: 4
diff changeset
62 "enabled:True",
f24c370e5ea4 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
bgruening
parents: 4
diff changeset
63 "wants_pause:False]\n",
f24c370e5ea4 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
bgruening
parents: 4
diff changeset
64 ]
f24c370e5ea4 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
bgruening
parents: 4
diff changeset
65 )
2
c956182d4e2c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff changeset
66 return result