Michał Górny avatar Michał Górny committed fc0681e

BashServer: commonize command writing code.

Comments (0)

Files changed (1)


 		shutil.copyfileobj(envf, f)
-		self._bashproc.stdin.write('set --\n'.encode('ASCII'))
-		self._bashproc.stdin.flush()
+		self._write('set --')
 	def _read1(self):
 		f = self._bashproc.stdout
 			buf += f.read(1)
 		return buf[1:-1].decode('utf-8')
-	def __getitem__(self, k):
-		self._bashproc.stdin.write(('set -- "${%s}"\n' % k).encode('ASCII'))
+	def _write(self, *cmds):
+		for cmd in cmds:
+			self._bashproc.stdin.write(('%s\n' % cmd).encode('ASCII'))
-		return self._read1()
-	def copy(self, *varlist):
+	def _cmd_print(self, *varlist):
 		q = ' '.join(['"${%s}"' % v for v in varlist])
-		self._bashproc.stdin.write(('set -- %s\n' % q).encode('ASCII'))
-		self._bashproc.stdin.flush()
+		self._write('set -- %s' % q)
+		return [self._read1() for v in varlist]
+	def __getitem__(self, k):
+		return self._cmd_print(k)[0]
-		ret = [self._read1() for v in varlist]
+	def copy(self, *varlist):
+		ret = self._cmd_print(*varlist)
 		return dict(zip(varlist, ret))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.