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 unwind(LIOError(pathname, error.errno))
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 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 call(self, argv): if len(argv) != 1: raise OldError(u"wrong number of arguments to import") name = argv[0] if isinstance(name, pathobj.Path): raise OldError(u"no direct loading yet") elif not isinstance(name, String): raise OldError(u"expected string") # import resolution: # local/script.lc path = pathobj.concat(self.local, pathobj.to_path(name)) cache = self.scope.getcache(path) if cache: return cache.module if not self.scope.frozen: mi = moduleinfo(path) if mi.lc_present or mi.cb_present: base_module = get_base_module(self.scope) this = Module(name.string, {}, extends=base_module) # base.module self.scope.setcache(path, this, max(mi.lc_mtime, mi.cb_mtime)) mi.default_config(this, self.scope) mi.loadit(this, self.scope) return this # scope/ scope = self.scope while scope is not None: path = pathobj.concat(scope.local, pathobj.to_path(name)) cache = scope.getcache(path) if cache: return cache.module if not scope.frozen: mi = moduleinfo(path) if mi.lc_present or mi.cb_present: base_module = get_base_module(scope) this = Module(name.string, {}, extends=base_module) # base.module scope.setcache(path, this, max(mi.lc_mtime, mi.cb_mtime)) mi.default_config(this, scope) mi.loadit(this, scope) return this scope = scope.parent raise OldError(u"module '%s' not present" % name.string)
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 call(self, argv): if len(argv) != 1: raise OldError(u"wrong number of arguments to import") name = argv[0] if isinstance(name, pathobj.Path): raise OldError(u"no direct loading yet") elif not isinstance(name, String): raise OldError(u"expected string") # import resolution: # local/script.lc path = pathobj.concat(self.local, pathobj.to_path(name)) cache = self.scope.getcache(path) if cache: return cache.module if not self.scope.frozen: mi = moduleinfo(path) if mi.lc_present or mi.cb_present: base_module = get_base_module(self.scope) this = Module(name.string, {}, extends=base_module) # base.module mi.default_config(this, self.scope) mi.loadit(this, self.scope) self.scope.setcache(path, this, max(mi.lc_mtime, mi.cb_mtime)) return this # scope/ scope = self.scope while scope is not None: path = pathobj.concat(scope.local, pathobj.to_path(name)) cache = scope.getcache(path) if cache: return cache.module if not scope.frozen: mi = moduleinfo(path) if mi.lc_present or mi.cb_present: base_module = get_base_module(scope) this = Module(name.string, {}, extends=base_module) # base.module mi.default_config(this, scope) mi.loadit(this, scope) scope.setcache(path, this, max(mi.lc_mtime, mi.cb_mtime)) return this scope = scope.parent raise OldError(u"module '%s' not present" % name.string)
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 build_path_args(path, args): pathname = pathobj.to_path(path) path = pathobj.os_stringify(pathname).encode('utf-8') if '\x00' in path: raise OldError(u"NUL byte in spawnv path string") argv = [] for arg in args.contents: if isinstance(arg, pathobj.Path): a = pathobj.os_stringify(arg).encode('utf-8') else: a = as_cstring(arg) if '\x00' in a: raise OldError(u"NUL byte in spawnv arg string") argv.append(rstring.assert_str0(a)) return rstring.assert_str0(path), argv
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): x = pathobj.os_stringify(arg).encode('utf-8') else: x = as_cstring(arg) assert '\x00' not in x argv.append(x) pid = os.fork() if pid == 0: assert '\x00' not in path os.execv(path, argv) return null return Integer(pid)
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 unwind(LIOError(pathname, error.errno))
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))
def load(program, path): if path is None: path = null else: path = pathobj.to_path(path) return from_object(program, path)