diff options
author | Mageia SVN-Git Migration <svn-git-migration@mageia.org> | 2011-01-04 16:09:44 +0000 |
---|---|---|
committer | Mageia SVN-Git Migration <svn-git-migration@mageia.org> | 2011-01-04 16:09:44 +0000 |
commit | 846c9e0ef180aa5411803eb1906896dc5e2fc5b9 (patch) | |
tree | f82d50447e2f648e76d051cb20ca4c44b1dde8a8 /RepSys/util.py | |
parent | 085ad0c1554260fe8f87955ed1ba74e06413f416 (diff) | |
download | mgarepo-846c9e0ef180aa5411803eb1906896dc5e2fc5b9.tar mgarepo-846c9e0ef180aa5411803eb1906896dc5e2fc5b9.tar.gz mgarepo-846c9e0ef180aa5411803eb1906896dc5e2fc5b9.tar.bz2 mgarepo-846c9e0ef180aa5411803eb1906896dc5e2fc5b9.tar.xz mgarepo-846c9e0ef180aa5411803eb1906896dc5e2fc5b9.zip |
Synthesized commit during git-svn import combining previous Mandriva history with Magiea.
This commit consitsts of the following subversion commits:
------------------------------------------------------------------------
r202 | boklm | 2011-01-04 16:09:44 +0000 (Tue, 04 Jan 2011) | 1 line
add repsys
------------------------------------------------------------------------
Diffstat (limited to 'RepSys/util.py')
-rwxr-xr-x[-rw-r--r--] | RepSys/util.py | 52 |
1 files changed, 48 insertions, 4 deletions
diff --git a/RepSys/util.py b/RepSys/util.py index 83f2ebe..84840b9 100644..100755 --- a/RepSys/util.py +++ b/RepSys/util.py @@ -2,11 +2,13 @@ from RepSys import Error, config +import subprocess import getpass import sys import os import re import logging +from cStringIO import StringIO #import commands log = logging.getLogger("repsys") @@ -26,14 +28,35 @@ def commands_getstatusoutput(cmd): def execcmd(*cmd, **kwargs): cmdstr = " ".join(cmd) if kwargs.get("show"): - status = os.system(cmdstr) - output = "" + if kwargs.get("geterr"): + err = StringIO() + pipe = subprocess.Popen(cmdstr, shell=True, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + of = pipe.stdout.fileno() + ef = pipe.stderr.fileno() + while True: + odata = os.read(of, 8192) + sys.stdout.write(odata) + edata = os.read(ef, 8192) + err.write(edata) + sys.stderr.write(edata) + status = pipe.poll() + if status is not None and not (odata and edata): + break + output = err.getvalue() + else: + status = os.system(cmdstr) + output = "" else: status, output = commands_getstatusoutput( "LANG=C LANGUAGE=C LC_ALL=C "+cmdstr) + verbose = config.getbool("global", "verbose", 0) if status != 0 and not kwargs.get("noerror"): - raise Error, "command failed: %s\n%s\n" % (cmdstr, output) - if config.getbool("global", "verbose", 0): + if kwargs.get("cleanerr") and not verbose: + raise Error, output + else: + raise Error, "command failed: %s\n%s\n" % (cmdstr, output) + if verbose: print cmdstr sys.stdout.write(output) return status, output @@ -92,6 +115,27 @@ def get_helper(name): if not os.path.isfile(hpath): log.warn("providing unexistent helper: %s", hpath) return hpath + +def rellink(src, dst): + """Creates relative symlinks + + It will find the common ancestor and append to the src path. + """ + asrc = os.path.abspath(src) + adst = os.path.abspath(dst) + csrc = asrc.split(os.path.sep) + cdst = adst.split(os.path.sep) + dstname = cdst.pop() + i = 0 + l = min(len(csrc), len(cdst)) + while i < l: + if csrc[i] != cdst[i]: + break + i += 1 + dstextra = len(cdst[i:]) + steps = [os.path.pardir] * dstextra + steps.extend(csrc[i:]) + return os.path.sep.join(steps) # vim:et:ts=4:sw=4 |