public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/gentoopm:master commit in: gentoopm/bash/
Date: Fri, 15 Jul 2011 16:08:21 +0000 (UTC)	[thread overview]
Message-ID: <fc0681e6122c0e1da42d9082d4337d434580d471.mgorny@gentoo> (raw)

commit:     fc0681e6122c0e1da42d9082d4337d434580d471
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Fri Jul 15 14:57:48 2011 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Fri Jul 15 14:57:48 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoopm.git;a=commit;h=fc0681e6

BashServer: commonize command writing code.

---
 gentoopm/bash/bashserver.py |   22 ++++++++++++----------
 1 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/gentoopm/bash/bashserver.py b/gentoopm/bash/bashserver.py
index f8740fd..1690627 100644
--- a/gentoopm/bash/bashserver.py
+++ b/gentoopm/bash/bashserver.py
@@ -48,8 +48,7 @@ class BashServer(BashParser):
 		shutil.copyfileobj(envf, f)
 		f.flush()
 
-		self._bashproc.stdin.write('set --\n'.encode('ASCII'))
-		self._bashproc.stdin.flush()
+		self._write('set --')
 
 	def _read1(self):
 		f = self._bashproc.stdout
@@ -58,16 +57,19 @@ class BashServer(BashParser):
 			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'))
 		self._bashproc.stdin.flush()
 
-		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))



             reply	other threads:[~2011-07-15 16:08 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-15 16:08 Michał Górny [this message]
  -- strict thread matches above, loose matches on Subject: below --
2013-08-05  8:50 [gentoo-commits] proj/gentoopm:master commit in: gentoopm/bash/ Michał Górny
2013-08-04 12:52 Michał Górny
2011-07-17 21:21 Michał Górny
2011-07-15 16:08 Michał Górny
2011-07-15 16:08 Michał Górny
2011-07-15 13:32 Michał Górny
2011-07-15 12:34 Michał Górny
2011-07-10 21:37 Michał Górny
2011-07-10 21:37 Michał Górny
2011-07-10 21:37 Michał Górny

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fc0681e6122c0e1da42d9082d4337d434580d471.mgorny@gentoo \
    --to=mgorny@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox