def open_nobind(path, dependencies, decorator): path = pathobj.to_path(path) basename = path.getattr(u"basename") if isinstance(basename, String): if not basename.string.endswith(u".json"): path.setattr(u"basename", String(basename.string + u".json")) return open_api(path, dependencies, decorator)
def getctime(path): pathname = pathobj.to_path(path) path = pathobj.os_stringify(pathname).encode('utf-8') try: return Float(os.path.getctime(path)) except IOError as error: raise ioerror(pathname, error)
def open_nobind(path, dependencies, decorator): path = pathobj.to_path(path) basename = path.getattr(u"basename") if isinstance(basename, String): if not basename.string.endswith(u".json"): path.setattr( u"basename", String(basename.string + u".json")) return open_api(path, dependencies, decorator)
def spawnv(path, args): pathname = pathobj.to_path(path) path = pathobj.os_stringify(pathname).encode('utf-8') argv = [] for arg in args.contents: if isinstance(arg, pathobj.Path): argv.append(pathobj.os_stringify(arg).encode('utf-8')) else: argv.append(as_cstring(arg)) pid = os.spawnv(os.P_NOWAIT, path, argv) return Integer(pid)
def open_(argv): if len(argv) < 1: raise OldError(u"too few arguments to fs.open()") pathname = pathobj.to_path(argv[0]) path = pathobj.os_stringify(pathname).encode('utf-8') if len(argv) > 1: mode = as_cstring(argv[1]) mode += 'b' else: mode = 'rb' try: return File(rfile.create_file(path, 'rb')) except IOError as error: raise ioerror(pathname, error)
def which(program): if isinstance(program, String): if program.string.count(u"/") > 0: program = pathobj.to_path(program) if isinstance(program, pathobj.Path): path = pathobj.os_stringify(program).encode('utf-8') if is_exe(path): return pathobj.concat(pathobj.getcwd(), program) return null elif not isinstance(program, String): raise OldError(u"string or path expected to .which()") program = as_cstring(program) for path in os.environ.get("PATH").split(os.pathsep): path = path.strip('"') exe_file = os.path.join(path, program) if is_exe(exe_file): return from_cstring(exe_file) return null
def stat(path): pathname = pathobj.to_path(path) path = pathobj.os_stringify(pathname).encode('utf-8') try: s = os.stat(path) except IOError as error: raise ioerror(pathname, error) return Exnihilo({ u"st_mode": Integer(s.st_mode), u"st_ino": Integer(s.st_ino), u"st_dev": Integer(s.st_dev), u"st_nlink": Integer(s.st_nlink), u"st_uid": Integer(s.st_uid), u"st_gid": Integer(s.st_gid), u"st_size": Integer(s.st_size), u"st_atime": Float(s.st_atime), u"st_mtime": Float(s.st_mtime), u"st_ctime": Float(s.st_ctime), })
def read_file(argv): if len(argv) < 1: raise OldError(u"too few arguments to fs.read_file()") pathname = pathobj.to_path(argv[0]) path = pathobj.os_stringify(pathname).encode('utf-8') convert = from_cstring if len(argv) > 1: for ch in as_cstring(argv[1]): if ch == 'b': convert = to_uint8array else: raise OldError(u"unknown mode string action") try: fd = rfile.create_file(path, 'rb') try: return convert(fd.read()) finally: fd.close() except IOError as error: raise ioerror(pathname, error)
def exists(path): pathname = pathobj.to_path(path) path = pathobj.os_stringify(pathname).encode('utf-8') return boolean(os.path.exists(path))