Skip to content

Commit 585ff1f

Browse files
committed
Fixed the parse symbols
1 parent 55bd2dc commit 585ff1f

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

Modules/Cluster.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,37 @@
9797
__CLUSTER_ATTEMPTS__, __CLUSTER_PORT__]
9898

9999

100+
SPECIAL_SYMBOLS = ["$", ";", "|"]
101+
102+
103+
def parse_symbols(string):
104+
r"""
105+
REPLACE SPECIAL SYMBOLS
106+
=======================
107+
108+
In a string that must be used on a shell command, replace all the special symbols
109+
in a way that they are correctly passed through the SHELL.
110+
111+
for example $USER => \$USER
112+
113+
Parameters
114+
----------
115+
string : str
116+
The string to be parsed
117+
118+
Results
119+
-------
120+
output : str
121+
The string after the symbols are replaced
122+
"""
123+
new_str = string
124+
for symbol in SPECIAL_SYMBOLS:
125+
new_str = new_str.replace(symbol, "\\" + symbol)
126+
return new_str
127+
128+
129+
130+
100131
class Cluster(object):
101132

102133
def __init__(self, hostname=None, pwd=None, extra_options="", workdir = "",
@@ -1214,7 +1245,7 @@ def parse_string(self, string):
12141245
if self.use_active_shell:
12151246
cmd = "{ssh} {host} -t '{shell} --login -c \"echo {string}\"'".format(ssh = self.sshcmd,
12161247
host = self.hostname,
1217-
string = string.replace("$", "\$"),
1248+
string = parse_symbols(string),
12181249
shell = self.terminal)
12191250
#print cmd
12201251

0 commit comments

Comments
 (0)