Commits

Michał Górny committed 49592d5

BashServer: don't hardcode any specific bash commands.

  • Participants
  • Parent commits fc0681e

Comments (0)

Files changed (1)

gentoopm/bash/bashserver.py

 _bash_script = '''
 while true; do
 	(
-		source %s
 		while read -r __GENTOOPM_CMD; do
 			eval ${__GENTOOPM_CMD}
-			if [[ ${#} -eq 0 ]]; then
-				# reload env file
-				break
-			else
-				printf "%%s\\0" "${@}"
-			fi
 		done
 	)
 done
 
 	def __init__(self):
 		self._tmpf = tempfile.NamedTemporaryFile('w+b')
-		self._bashproc = subprocess.Popen(['bash', '-c',
-				_bash_script % repr(self._tmpf.name)],
+		self._bashproc = subprocess.Popen(['bash', '-c', _bash_script],
 			stdin = subprocess.PIPE, stdout = subprocess.PIPE,
 			env = {})
 
 		shutil.copyfileobj(envf, f)
 		f.flush()
 
-		self._write('set --')
+		self._write('break',
+				'source %s' % repr(f.name))
 
 	def _read1(self):
 		f = self._bashproc.stdout
 
 	def _cmd_print(self, *varlist):
 		q = ' '.join(['"${%s}"' % v for v in varlist])
-		self._write('set -- %s' % q)
+		self._write('set -- %s' % q,
+				'printf "%s\\0" "${@}"')
 		return [self._read1() for v in varlist]
 
 	def __getitem__(self, k):