def pubws_get_identity_files(workspace, email_info, identity, share_id, sender=False): workspace_id = workspace.id name = identity['email'] node = KfsNode.get_by(workspace_id=workspace_id, share_id=share_id, parent_inode_id=0, inode_type=kfs_lib.KFS_DIR, name=name) if node: #log.debug("Directory '%s' found: inode_id=%i." % ( name, node.inode_id ) ) name = kfs_lib.get_kfs_skurl_subject(email_info['date'], email_info['subject']) node2 = KfsNode.get_by(workspace_id=workspace_id, share_id=share_id, parent_inode_id=node.inode_id, inode_type=kfs_lib.KFS_DIR, name=name) if node2: #log.debug("Directory '%s' found: inode_id=%i." % ( name, node2.inode_id ) ) if sender: name = "Original attachments" node3 = KfsNode.get_by(workspace_id=workspace_id, share_id=share_id, parent_inode_id=node2.inode_id, inode_type=kfs_lib.KFS_DIR, name=name) if node3: #log.debug("Directory 3 '%s' existing." % ( name ) ) return node3.getFiles() else: #log.debug("Directory 3 '%s' not found." % ( name ) ) pass else: #log.debug("Directory 2 '%s' existing." % ( name ) ) return node2.getFiles() else: #log.debug("Directory 2 '%s' not found." % ( name ) ) pass else: #log.debug("Directory '%s' not found." % ( name ) ) pass return None
def ws_kfs_state_request(kfs_dir): data = {} workspace_id = kfs_dir.workspace_id share_id = kfs_dir.share_id dir_inode_id = kfs_dir.inode_id # Get the current KFS path components. dir_node = KfsNode.get_by(workspace_id=workspace_id, share_id=share_id, inode_id=dir_inode_id) if not dir_node: raise Exception("Invalid KFS directory.") assert dir_node.isDir() components = dir_node.getPathComponents() data['components'] = components # Convert the components to dictionaries and add HTML-escaped names. client_components = [] for c in components: d = c.to_dict() d['esc_name'] = cgi.escape(c.name) client_components.append(d) data['components'] = client_components #log.debug("kfs_state_request(): KFS Path: '%s'." % ( "/".join(map(lambda x: x.name, client_components)) ) ) # Get sub-directories. nodes = dir_node.getSubdirs() # Convert nodes list. l = [] for node in nodes: # FIXME: should use a custom object which would initialize from nodes and contain only needed infos. d = node.to_dict() d['esc_name'] = cgi.escape(node.name) d['files_count'] = node.getOKFilesCount() d['subdirs_count'] = node.getSubdirsCount() del d['file_hash'] # cannot be jsonified - not used anyways l.append(d) data['dirs'] = l log.debug("kfs_state_request(): Directory %s has %i sub-directories." % (str(kfs_dir), len(l))) # Get files inside the current directory. nodes = dir_node.getAllButDeletedFiles() # Convert nodes list. l = [] for node in nodes: # FIXME: should use a custom object which would initialize from nodes and contain only needed infos. d = node.to_dict() d['esc_name'] = cgi.escape(node.name) del d['file_hash'] # cannot be jsonified - not used anyways l.append(d) data['files'] = l log.debug("kfs_state_request(): Directory %s has %i files." % (str(kfs_dir), len(l))) return data
def ws_kfs_state_request(kfs_dir): data = {} workspace_id = kfs_dir.workspace_id share_id = kfs_dir.share_id dir_inode_id = kfs_dir.inode_id # Get the current KFS path components. dir_node = KfsNode.get_by(workspace_id=workspace_id, share_id=share_id, inode_id=dir_inode_id) if not dir_node: raise Exception("Invalid KFS directory.") assert dir_node.isDir() components = dir_node.getPathComponents() data['components'] = components # Convert the components to dictionaries and add HTML-escaped names. client_components = [] for c in components: d = c.to_dict() d['esc_name'] = cgi.escape(c.name) client_components.append(d) data['components'] = client_components #log.debug("kfs_state_request(): KFS Path: '%s'." % ( "/".join(map(lambda x: x.name, client_components)) ) ) # Get sub-directories. nodes = dir_node.getSubdirs() # Convert nodes list. l = [] for node in nodes: # FIXME: should use a custom object which would initialize from nodes and contain only needed infos. d = node.to_dict() d['esc_name'] = cgi.escape(node.name) d['files_count'] = node.getOKFilesCount() d['subdirs_count'] = node.getSubdirsCount() del d['file_hash'] # cannot be jsonified - not used anyways l.append(d) data['dirs'] = l log.debug("kfs_state_request(): Directory %s has %i sub-directories." % ( str(kfs_dir), len(l) ) ) # Get files inside the current directory. nodes = dir_node.getAllButDeletedFiles() # Convert nodes list. l = [] for node in nodes: # FIXME: should use a custom object which would initialize from nodes and contain only needed infos. d = node.to_dict() d['esc_name'] = cgi.escape(node.name) del d['file_hash'] # cannot be jsonified - not used anyways l.append(d) data['files'] = l log.debug("kfs_state_request(): Directory %s has %i files." % ( str(kfs_dir), len(l) ) ) return data