Esempio n. 1
0
 def remove_section(self, section):
     for i in tolist(section):
         object = self[i]
         if object:
             id = object._section
             self.parser.remove_section(id)
     self.save()
def printVirtualHostAliases(virtualHost):
    vh = AdminConfig.getid("/VirtualHost:" + virtualHost)
    if len(vh) > 0:
        for al in tolist(AdminConfig.showAttribute(vh, 'aliases')):
            print "%s:%s" % (AdminConfig.showAttribute(
                al, 'hostname'), AdminConfig.showAttribute(al, 'port'))
    else:
        print "VirtualHost '%s' not found" % (virtualHost)
Esempio n. 3
0
def subopen(args, stdin=None, shell=False, cwd=None, env=None):
    temp = None
    pid = None
    close_fds = True
    rstrip = True
    try:
        if stdin is not None and isstring(stdin):
            temp = tempfile()
            write(temp, stdin)
            stdin = open(temp)
        args = tolist(args)
        for i, arg in enumerate(args):
            if not isinstance(arg, int):
                if PY3:
                    args[i] = str(arg)  # python3
                else:
                    args[i] = __builtin__.unicode(arg)  # python2
        if not env:
            env = os.environ.copy()
        process = subprocess.Popen(args,
                                   stdin=stdin,
                                   stderr=subprocess.PIPE,
                                   stdout=subprocess.PIPE,
                                   close_fds=close_fds,
                                   shell=shell,
                                   cwd=cwd,
                                   env=env,
                                   universal_newlines=False  # ,
                                   # startupinfo=startupinfo#,
                                   # creationflags=creationflags
                                   )
        pid = process.pid
        stdoutdata, stderrdata = process.communicate()
        if PY3:
            # python3. process.communicate returns bytes
            stdoutdata = str(stdoutdata, "utf-8")  # stdoutdata
            stderrdata = str(stderrdata, "utf-8")  # stderrdata
        # rstrip
        if rstrip and stdoutdata:
            stdoutdata = stdoutdata.rstrip()
        if rstrip and stderrdata:
            stderrdata = stderrdata.rstrip()
        returncode = process.returncode
        return (returncode, stdoutdata, stderrdata)
        # raise CalledProcessError(returncode,args,err)
        # if returncode!=0:
        # raise CalledProcessError(returncode,args,stderrdata)
        # return stdoutdata
    finally:
        try:
            if pid:
                os.killpg(pid, signal.SIGTERM)
        except Exception:
            pass
            # print(format_exc())
        rm(temp)
Esempio n. 4
0
def ismatch(string, pattern):
    if string == pattern:
        return True
    if pattern is None:
        return False
    for s in list(set(tolist(string))):
        if s == pattern:
            return True
        if not isstring(s):
            s = str(s)
        for p in tolist(pattern):
            if s == p:
                return True
            if isregex(p):
                return bool(p.match(s))
            if inspect.isfunction(p):
                return p(s)
            if fnmatch.fnmatch(s, str(p)):
                return True
    return False
Esempio n. 5
0
def load_module(name, path=None):
    """imp.load_module replacement
    todo: isfile, isdir
    """
    if name:
        name = str(name)
    asname = name
    if name in sys.modules.keys():  # already loaded
        return sys.modules[name]
    if path:
        if isinstance(path, list):
            pass
            # modpath = path
        else:
            path = str(path)
            assert_exists(path)
            if os.path.isdir(path):
                path = [path]
            if not isinstance(path, list) and os.path.isfile(path):
                asname = os.path.basename(path).replace(".py", "")
                path = [os.path.dirname(path)]
    else:
        path = [os.getcwd()]
    # path = [] # python2 default
    # path = None # python3

    try:
        t = imp.find_module(asname, path)
    except Exception:
        return
    warnings.simplefilter("ignore", RuntimeWarning)
    warnings.simplefilter("ignore", ImportWarning)
    syspath = sys.path
    if path:
        sys.path += tolist(path)
    module = imp.load_module(name, *t)
    sys.path = syspath
    return module
Esempio n. 6
0
 def add_section(self, section):
     for section in tolist(section):
         if section not in self:
             self.parser.add_section(section)
     self.save()
Esempio n. 7
0
 def remove_option(self, section, option):
     for option in tolist(option):
         if self.has_option(section, option):
             self.parser.remove_option(section, option)
     self.save()