-
Notifications
You must be signed in to change notification settings - Fork 26
/
cparse.sh
executable file
·141 lines (121 loc) · 3.08 KB
/
cparse.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/bash
#
# NAME
#
# cparse.sh
#
# SYNOPSIS
#
# cparse.sh <cstring> <extension> "REPO" "CONTAINER" "MMN" "ENV"
#
# DESCRIPTION
#
# cparse.sh parses a <cstring> of pattern:
#
# [<repo>/]<container>[::<mainModuleName>[^<env>]]
#
# and returns
#
# <repo> <container> <mainModuleName><extension> <env>
#
# ARGS
#
# <string>
#
# The container name string to parse.
#
# <extension>
#
# An extension to append to the <mainModuleName>. Since most
# ChRIS plugins are python modules, this usually is just ".py".
#
# RETURN
#
# REPO
# if not passed in <repo>, defaults to env variable, $CREPO.
#
# CONTAINER
#
# the <container> part of the string.
#
# MMN
# if not passed, defaults to the <container> string, with
# ".py" appended and sans a possibly leading "pl-".
#
# ENV
# if not passed, defaults to "host", else <env>.
#
# EXAMPLE
#
# cparse.sh "local/pl-dircopy::directoryCopy^moc" ".py"
#
CREPO=fnndsc
function cparse {
pluginSpec=$1
pluginExt=$2
local __repo=$3
local __container=$4
local __mainModuleName=$5
local __env=$6
export pluginSpec=$pluginSpec
export CREPO=$CREPO
l_parse=$(python3 - << EOF
import os
b_done = False
str_pluginSpec = os.environ['pluginSpec']
str_CREPO = os.environ['CREPO']
# [<repo>/]
l_spec = str_pluginSpec.split('/')
if len(l_spec) == 1:
# No leading [<repo>/]
str_repo = str_CREPO
str_remain = l_spec[0]
else:
# There is a leading [<repo>/]
str_repo = l_spec[0]
str_remain = l_spec[1]
# [^<env>]
l_spec = str_remain.split('^')
if len(l_spec) == 1:
# No trailing [^<env>]
str_env = 'host'
str_remain = l_spec[0]
else:
# There is a trailing [^<env>]
str_env = l_spec[1]
str_remain = l_spec[0]
# [:<mainModuleName]
l_spec = str_remain.split('::')
if len(l_spec) == 1:
# No trailing [::<mainModuleName>]
l_mmn = l_spec[0].split('pl-')
if len(l_mmn) == 1:
str_mmn = l_spec[0]
else:
str_mmn = l_mmn[1]
str_remain = l_spec[0]
else:
# There is a trailing [::<mainModuleName>]
str_mmn = l_spec[1]
str_remain = l_spec[0]
str_container = str_remain
print("%s %s %s %s" % (str_repo, str_container, str_mmn, str_env))
EOF
)
str_repo=$(echo $l_parse | awk '{print $1}')
str_container=$(echo $l_parse | awk '{print $2}')
str_mmn=$(echo $l_parse | awk '{print $3}')$pluginExt
str_env=$(echo $l_parse | awk '{print $4}')
eval $__repo="'$str_repo'"
eval $__container="'$str_container'"
eval $__mainModuleName="'$str_mmn'"
eval $__env="'$str_env'"
}
function cparse_do {
TESTNAME="local/pl-dircopy:directoryCopy^moc"
cparse "$1" "$2" "REPO" "CONTAINER" "MMN" "ENV"
echo $REPO
echo $CONTAINER
echo $MMN
echo $ENV
}