source: soft/build_system/build_system/repsys/tags/V1_5_6/RepSys/util.py @ 1

Last change on this file since 1 was 1, checked in by fasma, 12 years ago

Initial Import from Mandriva's soft revision 224062 and package revision 45733

File size: 1.6 KB
Line 
1#!/usr/bin/python
2from RepSys import Error, config
3import getpass
4import sys, os
5#import commands
6
7# Our own version of commands' getstatusoutput(). We have a commands
8# module directory, so we can't import Python's standard module
9def commands_getstatusoutput(cmd):
10    """Return (status, output) of executing cmd in a shell."""
11    import os
12    pipe = os.popen('{ ' + cmd + '; } 2>&1', 'r')
13    text = pipe.read()
14    sts = pipe.close()
15    if sts is None: sts = 0
16    if text[-1:] == '\n': text = text[:-1]
17    return sts, text
18
19def execcmd(*cmd, **kwargs):
20    cmdstr = " ".join(cmd)
21    if kwargs.get("show"):
22        status = os.system(cmdstr)
23        output = ""
24    else:
25        status, output = commands_getstatusoutput("LANG=C LANGUAGE=C LC_ALL=C "+cmdstr)
26    if status != 0 and not kwargs.get("noerror"):
27        raise Error, "command failed: %s\n%s\n" % (cmdstr, output)
28    if config.getbool("global", "verbose", 0):
29        print cmdstr
30        sys.stdout.write(output)
31    return status, output
32
33def get_auth(username=None, password=None):
34    set_username = 1
35    set_password = 1
36    if not username:
37        username = config.get("auth", "username")
38        if not username:
39            username = raw_input("username: ")
40        else:
41            set_username = 0
42    if not password:
43        password = config.get("auth", "password")
44        if not password:
45            password = getpass.getpass("password: ")
46        else:
47            set_password = 0
48    if set_username:
49        config.set("auth", "username", username)
50    if set_password:
51        config.set("auth", "password", password)
52    return username, password
53
54# vim:et:ts=4:sw=4
Note: See TracBrowser for help on using the repository browser.