def __init__(self, fs_manager, action_queue): super(PublicFiles, self).__init__() self.syncdaemon_public_files = SyncdaemonPublicFiles(fs_manager, action_queue)
class PublicFiles(Referenceable, SignalBroadcaster): """An IPC interface for handling public files.""" __metaclass__ = RemoteMeta # calls that will be accessible remotely remote_calls = [ 'change_public_access', 'get_public_files', ] def __init__(self, fs_manager, action_queue): super(PublicFiles, self).__init__() self.syncdaemon_public_files = SyncdaemonPublicFiles(fs_manager, action_queue) def change_public_access(self, share_id, node_id, is_public): """Change the public access of a file.""" logger.debug('PublicFiles.change_public_access: %r, %r, %r', share_id, node_id, is_public) self.syncdaemon_public_files.change_public_access(share_id, node_id, is_public) def get_public_files(self): """Request the list of public files to the server. The result will be send in a PublicFilesList signal. """ self.syncdaemon_public_files.get_public_files() def emit_public_access_changed(self, share_id, node_id, is_public, public_url): """Emit the PublicAccessChanged signal.""" share_id = str(share_id) if share_id else '' node_id = str(node_id) path = self.syncdaemon_public_files.get_path(share_id, node_id) info = dict( share_id=str(share_id) if share_id else '', node_id=str(node_id), is_public=bool_str(is_public), public_url=public_url if public_url else '', path=path) self.emit_signal('on_public_access_changed', info) def emit_public_access_change_error(self, share_id, node_id, error): """Emit the PublicAccessChangeError signal.""" path = self.syncdaemon_public_files.get_path(share_id, node_id) info = dict( share_id=str(share_id) if share_id else '', node_id=str(node_id), path=path) self.emit_signal('on_public_access_change_error', info, str(error)) def emit_public_files_list(self, public_files): """Emit the PublicFilesList signal.""" files = [] for pf in public_files: volume_id = str(pf['volume_id']) node_id = str(pf['node_id']) public_url = str(pf['public_url']) path = self.syncdaemon_public_files.get_path(volume_id , node_id).decode('utf-8') files.append(dict(volume_id=volume_id, node_id=node_id, public_url=public_url, path=path)) self.emit_signal('on_public_files_list', files) def emit_public_files_list_error(self, error): """Emit the PublicFilesListError signal.""" self.emit_signal('on_public_files_list_error', str(error))