def open_file(self, name: str, mode: str = 'r') -> File:
     with self.conn() as soc:
         send_request(
             soc,
             encode_parameter('fs', 'open_file', self.path(), name, mode))
         return RemoteFile(self.conn,
                           asserttype(File, pickle.loads(get_request(soc))))
Beispiel #2
0
    def _start(self):
        with network.create_server_connection(network.get_local_ip(),
                                              self.port) as soc:
            while True:
                self.request = None
                try:
                    soc.listen()
                    if soc:
                        c_soc, _ = soc.accept()
                        code = self.execute(
                            network.decode_parameter(
                                notnone(network.get_request(c_soc))))
                        if code is not None:
                            print(f'=> {code}')
                            network.send_request(c_soc, pickle.dumps(code))

                        c_soc.close()
                except (OSError, AssertionError) as e:
                    print(f"Error occurred: {e}")
                    with open('log_server.log', 'a+') as f:
                        f.write(
                            f'[{datetime.datetime.now()}] ERROR {type(e)}: {e}\n'
                        )
 def delete_file(self, name: str) -> None:
     with self.conn() as soc:
         send_request(
             soc, encode_parameter('fs', 'delete_file', self.path(), name))
Beispiel #4
0
 def memory_map(self) -> Memory:
     with self.__create_connection() as soc:
         send_request(soc, encode_parameter('fs', 'memory_map'))
         return asserttype(Memory, pickle.loads(get_request(soc)))
Beispiel #5
0
 def current(self):
     with self.__create_connection() as soc:
         send_request(soc, encode_parameter('fs', 'current'))
         return RemoteFolder(
             self.__create_connection,
             asserttype(Folder, pickle.loads(get_request(soc))))
Beispiel #6
0
 def delete(self, path: str) -> None:
     with self.__create_connection() as soc:
         send_request(soc, encode_parameter('fs', 'delete', path))
Beispiel #7
0
 def save(self):
     with self.__create_connection() as soc:
         send_request(soc, encode_parameter('fs', 'save'))
Beispiel #8
0
 def create_directory(self, path: str) -> None:
     with self.__create_connection() as soc:
         send_request(soc, encode_parameter('fs', 'create_directory', path))
Beispiel #9
0
 def move(self, src: str, dest: str) -> None:
     with self.__create_connection() as soc:
         send_request(soc, encode_parameter('fs', 'move', src, dest))
Beispiel #10
0
 def change_directory(self, path: str) -> Folder:
     with self.__create_connection() as soc:
         send_request(soc, encode_parameter('fs', 'change_directory', path))
         return RemoteFolder(
             self.__create_connection,
             asserttype(Folder, pickle.loads(get_request(soc))))
Beispiel #11
0
 def truncate(self, end: int) -> None:
     with self.conn() as soc:
         send_request(soc, encode_parameter(
             'fs', 'truncate_contents', self.parent.path(), self.name, str(end)
         ))
Beispiel #12
0
 def move(self, start: int, end: int, target: int) -> None:
     with self.conn() as soc:
         send_request(soc, encode_parameter(
             'fs', 'move_contents', self.parent.path(), self.name, str(start), str(end), str(target)
         ))
Beispiel #13
0
 def read(self, start: int = 0, end: int = -1) -> Union[str, bytes]:
     with self.conn() as soc:
         send_request(soc, encode_parameter(
             'fs', 'read_contents', self.parent.path(), self.name, str(start), str(end)
         ))
         return ''.join(pickle.loads(get_request(soc)))
Beispiel #14
0
 def _write(self, contents: str, start: int = 0, append: bool = False) -> None:
     with self.conn() as soc:
         send_request(soc, encode_parameter(
             'fs', 'write_contents', self.parent.path(), self.name, contents, str(start), str(append)
         ))