summaryrefslogtreecommitdiffstats
path: root/mountconfig/SimpleCommandRunner.py
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-03-13 05:43:39 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-03-13 05:43:39 +0000
commit19ae07d0d443ff8b777f46bcbe97119483356bfd (patch)
treedae169167c23ba7c61814101995de21d6abac2e8 /mountconfig/SimpleCommandRunner.py
downloadtde-guidance-19ae07d0d443ff8b777f46bcbe97119483356bfd.tar.gz
tde-guidance-19ae07d0d443ff8b777f46bcbe97119483356bfd.zip
Added KDE3 version of KDE Guidance utilities
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kde-guidance@1102646 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'mountconfig/SimpleCommandRunner.py')
-rw-r--r--mountconfig/SimpleCommandRunner.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/mountconfig/SimpleCommandRunner.py b/mountconfig/SimpleCommandRunner.py
new file mode 100644
index 0000000..d533563
--- /dev/null
+++ b/mountconfig/SimpleCommandRunner.py
@@ -0,0 +1,69 @@
+###########################################################################
+# SimpleCommandRunner.py - description #
+# ------------------------------ #
+# begin : Tue May 17 2005 #
+# copyright : (C) 2005 by Simon Edwards #
+# email : [email protected] #
+# #
+###########################################################################
+# #
+# This program is free software; you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation; either version 2 of the License, or #
+# (at your option) any later version. #
+# #
+###########################################################################
+from qt import *
+from kdecore import *
+import locale
+
+debug = False
+#debug = True
+
+
+class SimpleCommandRunner(QObject):
+ ########################################################################
+ def __init__(self):
+ QObject.__init__(self)
+
+ ########################################################################
+ def run(self,cmdlist,STDOUT_only=False):
+ """Run the given command and return the result.
+
+ Keyword arguments:
+ cmdlist - Command and arguments. Given as a list of strings. The first item is
+ the executable.
+ STDOUT_only - Do not return STDERR in the output stream.
+
+ Returns a tuple (rc,output). rc is the numeric return code from
+ the command, or None if the command couldn't be started. output
+ is the output from stdout and stderr.
+ """
+ global debug
+ if debug: print cmdlist
+ self.STDOUT_only = STDOUT_only
+ self.output = u""
+ proc = KProcess()
+ proc.setEnvironment("LANG","US")
+ proc.setEnvironment("LC_ALL","US")
+ self.connect(proc,SIGNAL("receivedStdout(KProcess *,char *,int)"),self.slotStdout)
+ self.connect(proc,SIGNAL("receivedStderr(KProcess *,char *,int)"),self.slotStderr)
+ proc.setArguments(cmdlist)
+ rc = None
+ if proc.start(proc.Block,proc.AllOutput)==True:
+ if proc.normalExit():
+ rc = proc.exitStatus()
+ return (rc,self.output)
+
+ ########################################################################
+ def slotStdout(self,proc,buffer,buflen):
+ global debug
+ if debug: print "slotStdout() |"+buffer+"|"
+ self.output += buffer.decode(locale.getpreferredencoding())
+
+ ########################################################################
+ def slotStderr(self,proc,buffer,buflen):
+ global debug
+ if debug: print "slotStderr() |"+buffer+"|"
+ if not self.STDOUT_only:
+ self.output += buffer.decode(locale.getpreferredencoding())