Ejemplo n.º 1
0
 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")
Ejemplo n.º 2
0
 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")
Ejemplo n.º 3
0
    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])
Ejemplo n.º 4
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")
Ejemplo n.º 5
0
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]
Ejemplo n.º 6
0
    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()
Ejemplo n.º 7
0
 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
     ]
Ejemplo n.º 8
0
    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()
Ejemplo n.º 9
0
 def initialize(self) -> None:
     if len(self.args) != 2:
         raise StatementError(self, "Invalid arguments")
Ejemplo n.º 10
0
 def initialize(self) -> None:
     if len(self.args) != 1:
         raise StatementError(self, "Invalid name")
Ejemplo n.º 11
0
 def initialize(self) -> None:
     try:
         self.name, self.end = self.args[0], int(self.args[1].strip())
     except:
         raise StatementError(self, "Invalid arguments")
Ejemplo n.º 12
0
 def initialize(self) -> None:
     try:
         self.name = self.args[0]
     except:
         raise StatementError(self, "Invalid arguments")