Skip to content

Commit 8e24580

Browse files
beautify tool name and id
- remove '.py' extension if existent - replace '-' by '_' - for id: replace ' ' by '_' also overwrite tool xml files (wo warning)
1 parent d00a81d commit 8e24580

File tree

5 files changed

+21
-204
lines changed

5 files changed

+21
-204
lines changed

argparse2tool/dropins/argparse/__init__.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def parse_args_galaxy(self, *args, **kwargs):
179179
directory += '/'
180180
filename = argp.prog.split()[-1] + ".xml"
181181
filename = directory + filename
182-
with open(filename, 'a') as f:
182+
with open(filename, 'w') as f:
183183
f.write(data)
184184
else:
185185
print(data)
@@ -196,6 +196,14 @@ def _parse_args_galaxy_argp(self, argp, macro):
196196
except AttributeError: # handle the potential absence of print_version
197197
version = '1.0'
198198

199+
prog = argp.prog
200+
if prog is not None:
201+
prog = prog.replace("-", "_")
202+
prog = prog.replace(".py ", " ")
203+
if prog.endswith(".py"):
204+
prog = prog[:-3]
205+
206+
199207
tid = argp.prog.split()[-1]
200208

201209
# get the list of file names of the used macros
@@ -209,8 +217,8 @@ def _parse_args_galaxy_argp(self, argp, macro):
209217
else:
210218
tpe = gxt.MacrosTool
211219

212-
tool = tpe(argp.prog,
213-
argp.prog.replace(" ", "_"),
220+
tool = tpe(prog,
221+
prog.replace(" ", "_"),
214222
version,
215223
argp.description,
216224
"python "+argp.prog,

examples/example-sub/bar.xml

Lines changed: 1 addition & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,4 @@
1-
<tool name="example-sub.py bar" id="example-sub.py_bar" version="2.0">
2-
<description/>
3-
<stdio>
4-
<exit_code range="1:" level="fatal"/>
5-
</stdio>
6-
<version_command>python example-sub.py bar --version</version_command>
7-
<command><![CDATA[python example-sub.py bar $false
8-
#for $i in $repeat_1:
9-
--append $i.append
10-
#end for
11-
#for $i in $repeat_2:
12-
--nargs2 "$repeat_var_2"
13-
#end for
14-
15-
#if $mode and $mode is not None:
16-
--mode $mode
17-
#end if
18-
> $default]]></command>
19-
<inputs>
20-
<param label="Store a false" checked="false" type="boolean" name="false" argument="--false" truevalue="--false" falsevalue=""/>
21-
<repeat title="Repeated Variable" name="repeat_1">
22-
<param label="Append a value" type="text" name="append" argument="--append"/>
23-
</repeat>
24-
<repeat title="repeat_title" min="2" max="2" name="repeat_2">
25-
<param optional="true" label="nargs2" type="text" name="nargs2" argument="--nargs2"/>
26-
</repeat>
27-
<param optional="true" label="Author did not provide help for this parameter... " type="select" name="mode" argument="--mode">
28-
<option value="paper">paper</option>
29-
<option value="rock">rock</option>
30-
<option selected="true" value="scissors">scissors</option>
31-
</param>
32-
</inputs>
33-
<outputs>
34-
<data name="default" format="txt" hidden="false"/>
35-
</outputs>
36-
<help><![CDATA[TODO: Write help]]></help>
37-
</tool>
38-
<tool name="example-sub.py bar" id="example-sub.py_bar" version="2.0">
39-
<description/>
40-
<macros>
41-
<import>qux.xml</import>
42-
</macros>
43-
<stdio>
44-
<exit_code range="1:" level="fatal"/>
45-
</stdio>
46-
<version_command>python example-sub.py bar --version</version_command>
47-
<command><![CDATA[python example-sub.py bar $false
48-
#for $i in $repeat_1:
49-
--append $i.append
50-
#end for
51-
#for $i in $repeat_2:
52-
--nargs2 "$repeat_var_2"
53-
#end for
54-
55-
#if $mode and $mode is not None:
56-
--mode $mode
57-
#end if
58-
@QUX_INMACRO@
59-
@QUX_OUTMACRO@
60-
> $default]]></command>
61-
<inputs>
62-
<param label="Store a false" checked="false" type="boolean" name="false" argument="--false" truevalue="--false" falsevalue=""/>
63-
<repeat title="Repeated Variable" name="repeat_1">
64-
<param label="Append a value" type="text" name="append" argument="--append"/>
65-
</repeat>
66-
<repeat title="repeat_title" min="2" max="2" name="repeat_2">
67-
<param optional="true" label="nargs2" type="text" name="nargs2" argument="--nargs2"/>
68-
</repeat>
69-
<param optional="true" label="Author did not provide help for this parameter... " type="select" name="mode" argument="--mode">
70-
<option value="paper">paper</option>
71-
<option value="rock">rock</option>
72-
<option selected="true" value="scissors">scissors</option>
73-
</param>
74-
<expand macro="qux_inmacro"/>
75-
</inputs>
76-
<outputs>
77-
<expand macro="qux_outmacro"/>
78-
<data name="default" format="txt" hidden="false"/>
79-
</outputs>
80-
<help><![CDATA[TODO: Write help]]></help>
81-
</tool>
82-
<tool name="example-sub.py bar" id="example-sub.py_bar" version="2.0">
1+
<tool name="example_sub bar" id="example_sub_bar" version="2.0">
832
<description/>
843
<macros>
854
<import>qux.xml</import>

examples/example-sub/baz.xml

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
11
<macros>
2-
<token name="EXAMPLE-SUB.PY_BAZ_INMACRO"><![CDATA[--baz $baz
3-
--qux $qux
2+
<token name="EXAMPLE_SUB_BAZ_INMACRO"><![CDATA[--baz $baz
43
@QUX_INMACRO@]]></token>
5-
<token name="EXAMPLE-SUB.PY_BAZ_OUTMACRO"><![CDATA[@QUX_OUTMACRO@]]></token>
6-
<xml name="example-sub.py_baz_inmacro">
4+
<token name="EXAMPLE_SUB_BAZ_OUTMACRO"><![CDATA[@QUX_OUTMACRO@]]></token>
5+
<xml name="example_sub_baz_inmacro">
76
<param optional="true" label="baz help" type="text" name="baz" argument="--baz"/>
8-
<param optional="true" label="qux help" type="text" name="qux" argument="--qux"/>
97
<expand macro="qux_inmacro"/>
108
</xml>
11-
<xml name="example-sub.py_baz_outmacro">
12-
<expand macro="qux_outmacro"/>
13-
</xml>
14-
</macros>
15-
<macros>
16-
<token name="EXAMPLE-SUB.PY_BAZ_INMACRO"><![CDATA[--baz $baz
17-
@QUX_INMACRO@]]></token>
18-
<token name="EXAMPLE-SUB.PY_BAZ_OUTMACRO"><![CDATA[@QUX_OUTMACRO@]]></token>
19-
<xml name="example-sub.py_baz_inmacro">
20-
<param optional="true" label="baz help" type="text" name="baz" argument="--baz"/>
21-
<expand macro="qux_inmacro"/>
22-
</xml>
23-
<xml name="example-sub.py_baz_outmacro">
9+
<xml name="example_sub_baz_outmacro">
2410
<expand macro="qux_outmacro"/>
2511
</xml>
2612
</macros>

examples/example-sub/foo.xml

Lines changed: 1 addition & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,4 @@
1-
<tool name="example-sub.py foo" id="example-sub.py_foo" version="1.0">
2-
<description/>
3-
<stdio>
4-
<exit_code range="1:" level="fatal"/>
5-
</stdio>
6-
<version_command>python example-sub.py foo --version</version_command>
7-
<command><![CDATA[python example-sub.py foo $keyword
8-
9-
#set repeat_var_2 = '" "'.join([ str($var.integers) for $var in $repeat_2 ])
10-
"$repeat_var_2"
11-
12-
$sum
13-
14-
#if $foo and $foo is not None:
15-
--foo $foo
16-
#end if
17-
18-
#set repeat_var_4 = '" "'.join([ str($var.bar) for $var in $repeat_4 ])
19-
--bar "$repeat_var_4"
20-
21-
$true
22-
> $default]]></command>
23-
<inputs>
24-
<param label="action keyword" type="text" name="keyword"/>
25-
<repeat title="repeat_title" min="1" name="repeat_2">
26-
<param label="an integer for the accumulator" value="0" type="integer" name="integers"/>
27-
</repeat>
28-
<param label="sum the integers (default: find the max)" checked="false" type="boolean" name="sum" argument="--sum" truevalue="--sum" falsevalue=""/>
29-
<param optional="true" label="foo help" type="text" name="foo" argument="--foo"/>
30-
<repeat title="repeat_title" name="repeat_4">
31-
<param optional="true" label="BAR!" value="1" type="text" name="bar" argument="--bar"/>
32-
</repeat>
33-
<param label="Store a true" checked="false" type="boolean" name="true" argument="--true" truevalue="--true" falsevalue=""/>
34-
</inputs>
35-
<outputs>
36-
<data name="default" format="txt" hidden="false"/>
37-
</outputs>
38-
<help><![CDATA[TODO: Write help]]></help>
39-
</tool>
40-
<tool name="example-sub.py foo" id="example-sub.py_foo" version="1.0">
41-
<description/>
42-
<macros>
43-
<import>baz.xml</import>
44-
<import>qux.xml</import>
45-
</macros>
46-
<stdio>
47-
<exit_code range="1:" level="fatal"/>
48-
</stdio>
49-
<version_command>python example-sub.py foo --version</version_command>
50-
<command><![CDATA[python example-sub.py foo $keyword
51-
52-
#set repeat_var_2 = '" "'.join([ str($var.integers) for $var in $repeat_2 ])
53-
"$repeat_var_2"
54-
55-
$sum
56-
57-
#if $foo and $foo is not None:
58-
--foo $foo
59-
#end if
60-
61-
#set repeat_var_4 = '" "'.join([ str($var.bar) for $var in $repeat_4 ])
62-
--bar "$repeat_var_4"
63-
64-
$true
65-
@BAZ_INMACRO@
66-
@QUX_INMACRO@
67-
@BAZ_OUTMACRO@
68-
@QUX_OUTMACRO@
69-
> $default]]></command>
70-
<inputs>
71-
<param label="action keyword" type="text" name="keyword"/>
72-
<repeat title="repeat_title" min="1" name="repeat_2">
73-
<param label="an integer for the accumulator" value="0" type="integer" name="integers"/>
74-
</repeat>
75-
<param label="sum the integers (default: find the max)" checked="false" type="boolean" name="sum" argument="--sum" truevalue="--sum" falsevalue=""/>
76-
<param optional="true" label="foo help" type="text" name="foo" argument="--foo"/>
77-
<repeat title="repeat_title" name="repeat_4">
78-
<param optional="true" label="BAR!" value="1" type="text" name="bar" argument="--bar"/>
79-
</repeat>
80-
<param label="Store a true" checked="false" type="boolean" name="true" argument="--true" truevalue="--true" falsevalue=""/>
81-
<expand macro="baz_inmacro"/>
82-
<expand macro="qux_inmacro"/>
83-
</inputs>
84-
<outputs>
85-
<expand macro="baz_outmacro"/>
86-
<expand macro="qux_outmacro"/>
87-
<data name="default" format="txt" hidden="false"/>
88-
</outputs>
89-
<help><![CDATA[TODO: Write help]]></help>
90-
</tool>
91-
<tool name="example-sub.py foo" id="example-sub.py_foo" version="1.0">
1+
<tool name="example_sub foo" id="example_sub_foo" version="1.0">
922
<description/>
933
<macros>
944
<import>qux.xml</import>

examples/example-sub/qux.xml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
<macros>
2-
<token name="EXAMPLE-SUB.PY_QUX_INMACRO"><![CDATA[]]></token>
3-
<token name="EXAMPLE-SUB.PY_QUX_OUTMACRO"><![CDATA[]]></token>
4-
<xml name="example-sub.py_qux_inmacro"/>
5-
<xml name="example-sub.py_qux_outmacro"/>
6-
</macros>
7-
<macros>
8-
<token name="EXAMPLE-SUB.PY_QUX_INMACRO"><![CDATA[--qux $qux]]></token>
9-
<token name="EXAMPLE-SUB.PY_QUX_OUTMACRO"><![CDATA[]]></token>
10-
<xml name="example-sub.py_qux_inmacro">
2+
<token name="EXAMPLE_SUB_QUX_INMACRO"><![CDATA[--qux $qux]]></token>
3+
<token name="EXAMPLE_SUB_QUX_OUTMACRO"><![CDATA[]]></token>
4+
<xml name="example_sub_qux_inmacro">
115
<param optional="true" label="qux help" type="text" name="qux" argument="--qux"/>
126
</xml>
13-
<xml name="example-sub.py_qux_outmacro"/>
7+
<xml name="example_sub_qux_outmacro"/>
148
</macros>

0 commit comments

Comments
 (0)