aboutsummaryrefslogtreecommitdiffstats
path: root/RepSys/util.py
diff options
context:
space:
mode:
authorFrederic Lepied <flepied@mandriva.com>2005-12-07 10:06:33 +0000
committerFrederic Lepied <flepied@mandriva.com>2005-12-07 10:06:33 +0000
commit2c78c40c9bfae22d1501022b2e52cf938b5a957e (patch)
tree33a030236dd735f665e7b1ff1a9fba203742ecc0 /RepSys/util.py
parentaa9174bf0cce8d6a3c6e4d9e795be717da184406 (diff)
downloadmgarepo-2c78c40c9bfae22d1501022b2e52cf938b5a957e.tar
mgarepo-2c78c40c9bfae22d1501022b2e52cf938b5a957e.tar.gz
mgarepo-2c78c40c9bfae22d1501022b2e52cf938b5a957e.tar.bz2
mgarepo-2c78c40c9bfae22d1501022b2e52cf938b5a957e.tar.xz
mgarepo-2c78c40c9bfae22d1501022b2e52cf938b5a957e.zip
Diffstat (limited to 'RepSys/util.py')
-rw-r--r--RepSys/util.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/RepSys/util.py b/RepSys/util.py
new file mode 100644
index 0000000..0337bc1
--- /dev/null
+++ b/RepSys/util.py
@@ -0,0 +1,54 @@
+#!/usr/bin/python
+from RepSys import Error, config
+import getpass
+import sys, os
+#import commands
+
+# Our own version of commands' getstatusoutput(). We have a commands
+# module directory, so we can't import Python's standard module
+def commands_getstatusoutput(cmd):
+ """Return (status, output) of executing cmd in a shell."""
+ import os
+ pipe = os.popen('{ ' + cmd + '; } 2>&1', 'r')
+ text = pipe.read()
+ sts = pipe.close()
+ if sts is None: sts = 0
+ if text[-1:] == '\n': text = text[:-1]
+ return sts, text
+
+def execcmd(*cmd, **kwargs):
+ cmdstr = " ".join(cmd)
+ if kwargs.get("show"):
+ status = os.system(cmdstr)
+ output = ""
+ else:
+ status, output = commands_getstatusoutput("LANG=C "+cmdstr)
+ if status != 0 and not kwargs.get("noerror"):
+ raise Error, "command failed: %s\n%s\n" % (cmdstr, output)
+ if config.getbool("global", "verbose", 0):
+ print cmdstr
+ sys.stdout.write(output)
+ return status, output
+
+def get_auth(username=None, password=None):
+ set_username = 1
+ set_password = 1
+ if not username:
+ username = config.get("auth", "username")
+ if not username:
+ username = raw_input("username: ")
+ else:
+ set_username = 0
+ if not password:
+ password = config.get("auth", "password")
+ if not password:
+ password = getpass.getpass("password: ")
+ else:
+ set_password = 0
+ if set_username:
+ config.set("auth", "username", username)
+ if set_password:
+ config.set("auth", "password", password)
+ return username, password
+
+# vim:et:ts=4:sw=4