def main(): demos = { 'simple': simple, 'append': append, 'shared_handle': shared_handle, } if len(sys.argv) != 2 or sys.argv[1] not in demos: print(f'Usage: {sys.argv[0]} demo_name') print('Demo names:', ', '.join(demos.keys())) print('(read demo.py for details)') sys.exit(1) demo = demos[sys.argv[1]] setup_logging() temp_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'tmp') shutil.rmtree(temp_dir) os.mkdir(temp_dir) socket_path = temp_dir + '/server.sock' with ExitStack() as exit: # Start server server = SyncServer(socket_path) server_thread = Thread(name='Server', target=server.run) server_thread.start() exit.callback(server_thread.join) exit.callback(server.socket_server.shutdown) # Start client client = SyncClient(socket_path) client.start() exit.callback(client.stop) # Create objects mount = Mount('tmp', temp_dir) fs = FS(client, mount) # Run demo demo(fs)
def cloned(self) -> ContextManager['FS']: """ Create a copy of this FS, emulating what happens after fork. """ client = SyncClient(self.client.path) client.start() try: fs = FS(client=client, root_mount=self.root_mount) for fd, handle in self.handles.items(): fs._clone_handle(fd, handle) yield fs finally: client.stop()
def __init__(self, is_art, config, project_info, all_modules): SyncClient.__init__(self, is_art, config) self._project_info = project_info self._all_modules = all_modules self._is_need_sync_base_res = False
def __init__(self, is_art, config): SyncClient.__init__(self, is_art, config)
handle.sync.data = handle.pos handle.sync.modified = True return result @trace def stat(self, path: str): with self._find_dentry(path) as dentry: if dentry.file_type is None: return None return { 'type': dentry.file_type.name, 'size': dentry.size, } @trace def seek(self, fd: int, pos: int): handle = self.handles[fd] with handle.sync.use(shared=False): handle.pos = pos handle.sync.data = pos handle.sync.modified = True if __name__ == '__main__': setup_logging() client = SyncClient('server.sock') client.start() mount = Mount('tmp', '/tmp/demo') fs = FS(client, mount)
required=True) parser.add_argument("-m", "--size-and-time", help="assume files with same size and mtime are equal", action='store_true') parser.add_argument("--dry-run", help="don't copy files", action='store_true') args = parser.parse_args() root_dir = "/" proc = subprocess.Popen(args.command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=sys.stderr) client = SyncClient(proc) server_files = client.get_file_db() file_finder = FileFinder() with open(args.file_list, "r") as filters_file: file_finder.add_from_text(root_dir, filters_file) created_dirs = {} local_dirs = {} local_files = {} total_uploaded_size = 0 def create_parent_dirs(path): path_dir = os.path.dirname(path) dirs_to_create = [] while not path_dir in created_dirs and path_dir: