Exemplo n.º 1
0
def xm_os_cpdir(lua, src, dst):
    try:
        copytree(expanduser(src), expanduser(dst))
    except OSError as e:
        set_errno(e.errno)
        return False
    return True
Exemplo n.º 2
0
def xm_os_chdir(lua, ph):
    try:
        chdir(expanduser(ph))
    except OSError as e:
        set_errno(e.errno)
        return False
    return True
Exemplo n.º 3
0
def xm_os_mkdir(lua, ph):
    try:
        makedirs(expanduser(ph), 0o755, True)
    except OSError as e:
        set_errno(e.errno)
        return False
    return True
Exemplo n.º 4
0
def xm_os_rmfile(lua, ph):
    try:
        remove(expanduser(ph))
    except OSError as e:
        set_errno(e.errno)
        return False
    return True
Exemplo n.º 5
0
 def waitprocess(proc, index):
     try:
         rvlist[index] = [proc[0], index + 1, proc[1].wait(timeout)]
     except TimeoutExpired:
         pass
     except OSError as e:
         set_errno(e.errno)
         rvlist[index] = -1
Exemplo n.º 6
0
def xm_process_openv(lua, shellname, argv, outfile=None, errfile=None):
    try:
        return procpool.add(
            Popen([shellname] + list(argv.values()),
                  stdout=open(outfile, "w") if outfile != None else None,
                  stderr=open(errfile, "w") if errfile != None else None))
    except OSError as e:
        set_errno(e.errno)
        return None
Exemplo n.º 7
0
def xm_os_cpfile(lua, src, dst):
    try:
        src = expanduser(src)
        dst = expanduser(dst)
        makedirs(dirname(dst), 0o755, True)
        copy2(src, dst)
    except OSError as e:
        set_errno(e.errno)
        return False
    return True
Exemplo n.º 8
0
def xm_process_close(lua, process):
    if not procpool.pool[process]:
        return False
    try:
        procpool.pool[process].terminate()
        procpool.pool[process] = None
        return True
    except OSError as e:
        set_errno(e.errno)
        return False
Exemplo n.º 9
0
def xm_process_wait(lua, process, timeout = None):
    if timeout < 0: timeout = None
    process = procpool.pool[process]
    try:
        return 1, process.wait(timeout)
    except TimeoutExpired:
        return 0, 0
    except OSError as e:
        set_errno(e.errno)
        return 0, 0
Exemplo n.º 10
0
def xm_os_rmdir(lua, ph, rmempty=False):
    ph = expanduser(ph)
    try:
        if rmempty:
            rmdir(ph)
        else:
            rmtree(ph)
    except OSError as e:
        set_errno(e.errno)
        return False
    return True
Exemplo n.º 11
0
def xm_os_find(lua, rootdir, pattern, recurse, mode, excludes=None):
    rootdir = path.expanduser(rootdir)
    excludes = list(excludes.values()) if excludes != None else []
    lgl = lua.globals()

    def judge(phs):
        res = []
        for ph in phs:
            if mode == 1 and path.isdir(ph) or mode == 0 and path.isfile(
                    ph) or mode not in (0, 1):
                if ph.startswith("./"):
                    ph = ph[2:]
                match = lgl.string.match
                if ph == match(ph, pattern):
                    rootlen = len(rootdir)
                    assert (rootdir != ph)
                    assert (rootlen + 1 <= len(ph))
                    phtk = ph[rootlen + 1:]
                    excluded = False
                    for exclude in excludes:
                        if match(phtk, exclude) == phtk:
                            excluded = True
                            break
                    if not excluded:
                        res.append(ph)
        return res

    try:
        if not recurse:
            res = judge([pathjoin(rootdir, nm) for nm in os.listdir(rootdir)])
        else:
            tree = []
            for (dirpath, dirnames, filenames) in os.walk(rootdir):
                tree += [pathjoin(dirpath, nm) for nm in dirnames + filenames]
            res = judge(tree)
    except OSError as e:
        set_errno(e.errno)
        return lua.table(), 0
    return lua.table(*res), len(res)
Exemplo n.º 12
0
def xm_os_mtime(lua, ph):
    try:
        return getmtime(expanduser(ph))
    except OSError as e:
        set_errno(e.errno)
        return 0
Exemplo n.º 13
0
def xm_os_getown(lua, ph):
    try:
        sts = stat(expanduser(ph))
        return lua.table(uid=sts.st_uid, gid=sts.st_gid)
    except OSError as e:
        set_errno(e.errno)