def initialize(self) -> None: try: self.name, self.mode = self.args except AssertionError as e: raise StatementError(self, *e.args) except: raise StatementError(self, "Invalid arguments")
def initialize(self) -> None: try: self.name, self.contents = self.args[0], self.args[1].strip('"').strip() if len(self.args) > 2: self.start = int(self.args[2]) except: raise StatementError(self, "Invalid arguments")
def execute(self) -> None: super().execute() if self.args[0] in [ f.name for f in _file_store ]: raise StatementError(self, "File is opened") self.pprint(f'Deleting file {self.args[0]}') self.fs.current.delete_file(self.args[0])
def initialize(self) -> None: try: self.name = self.args[0] if len(self.args) > 1: self.start = int(self.args[1]) if len(self.args) > 2: self.size = int(self.args[2]) except: raise StatementError(self, "Invalid arguments")
def _open_file(statement: Statement, name: str) -> File: _f_map: Dict[str, File] = { f.name: f for f in _file_store } if name not in _f_map: raise StatementError(statement, "No such file opened") return _f_map[name]
def execute(self) -> None: super().execute() src: File = _open_file(self, self.name) src.lock.acquire() self.pprint(f'Reading from {src.name}', is_log=True) if not isinstance(src, Readable) and not isinstance(src, Hybrid): raise StatementError(self, "File opened in write-only mode") self.pprint(src.read(self.start, self.size)) src.lock.release()
def execute(self) -> None: super().execute() global _file_store self.pprint(f'Closing {self.name}', is_log=True) if self.name not in map(lambda x: x.name, _file_store): raise StatementError(self, "No such file opened") _file_store = [ f for f in _file_store if f.name != self.name ]
def execute(self) -> None: super().execute() src: File = _open_file(self, self.name) src.lock.acquire() self.pprint(f'Writing to {src.name}', is_log=True) if isinstance(src, Readable): raise StatementError(self, "File opened in read-only mode") if self.start is not None: src.write(self.contents, start=self.start) else: src.write(self.contents) src.lock.release()
def initialize(self) -> None: if len(self.args) != 2: raise StatementError(self, "Invalid arguments")
def initialize(self) -> None: if len(self.args) != 1: raise StatementError(self, "Invalid name")
def initialize(self) -> None: try: self.name, self.end = self.args[0], int(self.args[1].strip()) except: raise StatementError(self, "Invalid arguments")
def initialize(self) -> None: try: self.name = self.args[0] except: raise StatementError(self, "Invalid arguments")