def load_folders(folders) -> Dict[str, KPGroup]: # sort folders so that in the case of nested folders, the parents would be guaranteed to show up before the children folders.sort(key=lambda x: x['name']) # dict to store mapping of Bitwarden folder id to keepass group groups_by_id: Dict[str, KPGroup] = {} # build up folder tree folder_root: FolderType.Folder = FolderType.Folder(None) folder_root.keepass_group = kp.root_group groups_by_id[None] = kp.root_group for folder in folders: if folder['id'] is not None: new_folder: FolderType.Folder = FolderType.Folder(folder['id']) # regex lifted from https://github.com/bitwarden/jslib/blob/ecdd08624f61ccff8128b7cb3241f39e664e1c7f/common/src/services/folder.service.ts#L108 folder_name_parts: List[str] = re.sub(r'^\/+|\/+$', '', folder['name']).split('/') FolderType.nested_traverse_insert(folder_root, folder_name_parts, new_folder, '/') # create keepass groups based off folder tree def add_keepass_group(folder: FolderType.Folder): parent_group: KPGroup = folder.parent.keepass_group new_group: KPGroup = kp.add_group(parent_group, folder.name) folder.keepass_group = new_group groups_by_id[folder.id] = new_group FolderType.bfs_traverse_execute(folder_root, add_keepass_group) return groups_by_id
def folders(self): folders = [] # Update folders self._folders = folder.Folder('vm').folders # Create VmPie.folder object for each folder for folder_name in self._folders: folders.append(folder.Folder(folder_name.name)) # Return folders return folders
def folder(self, path=None, entryid=None, recurse=False, create=False, guid=None): """Return :class:`Folder` with given path/entryid. :param path: The path of the folder :param entryid: The entryid of the folder :param create: Create folder if it doesn't exist """ if guid: # 01 -> entryid format version, 03 -> object type (folder) entryid = '00000000' + self.guid + '0100000003000000' + guid + '00000000' if entryid is not None: try: return _folder.Folder(self, entryid) except (MAPIErrorInvalidEntryid, MAPIErrorNotFound): # XXX move to Folder raise NotFoundError("no folder with entryid: '%s'" % entryid) return self.subtree.folder(path, recurse=recurse, create=create)
def root(self): """:class:`Folder` designated as store root.""" try: return _folder.Folder( self, _benc(HrGetOneProp(self._root, PR_ENTRYID).Value)) except (MAPIErrorNotFound, NotFoundError): pass
def common_views(self): """:class:`Folder` contains folders for managing views for the message store.""" try: return _folder.Folder( self, _benc(self.prop(PR_COMMON_VIEWS_ENTRYID).value)) except NotFoundError: pass
def ImportFolderDeletion(self, flags, sourcekeys): if hasattr(self.importer, 'delete'): for sourcekey in sourcekeys: folder = _folder.Folder(self.importer.store, _check_mapiobj=False) folder._sourcekey = _benc(sourcekey) self.importer.delete(folder, flags)
def todo_search(self): """:class`Folder` designated as To-Do Search folder.""" try: return _folder.Folder( self, self._extract_ipm_ol2007_entryid(RSF_PID_TODO_SEARCH)) except NotFoundError: pass
def junk(self): """:class:`Folder` designated as junk.""" # PR_ADDITIONAL_REN_ENTRYIDS is a multi-value property, 4th entry is the junk folder try: return _folder.Folder(self, _benc(HrGetOneProp(self._root, PR_ADDITIONAL_REN_ENTRYIDS).Value[4])) except (MAPIErrorNotFound, NotFoundError): pass
def inbox(self): """:class:`Folder` designated as inbox.""" try: return _folder.Folder( self, _benc(self.mapiobj.GetReceiveFolder(u'IPM', MAPI_UNICODE)[0])) except (MAPIErrorNotFound, NotFoundError): pass
def findroot(self): """:class:`Folder` designated as search-results root.""" try: return _folder.Folder( self, _benc(HrGetOneProp(self.mapiobj, PR_FINDER_ENTRYID).Value)) except (MAPIErrorNotFound, NotFoundError): pass
def folder(self): """ Parent :class:`Folder` of an item """ if self._folder: return self._folder try: return _folder.Folder(self.store, _benc(HrGetOneProp(self.mapiobj, PR_PARENT_ENTRYID).Value)) except (MAPIErrorNotFound, NotFoundError): pass
def tasks(self): """:class:`Folder` designated as tasks.""" try: return _folder.Folder( self, _hex(HrGetOneProp(self._root, PR_IPM_TASK_ENTRYID).Value)) except (MAPIErrorNotFound, NotFoundError): pass
def contacts(self): """:class:`Folder` designated as contacts.""" try: return _folder.Folder( self, _hex(HrGetOneProp(self._root, PR_IPM_CONTACT_ENTRYID).Value)) except (MAPIErrorNotFound, NotFoundError): pass
def reminders(self): """:class:`Folder` designated as reminders.""" try: return _folder.Folder( self, _benc(HrGetOneProp(self._root, PR_REM_ONLINE_ENTRYID).Value)) except (MAPIErrorNotFound, NotFoundError): pass
def rss(self): """:class`Folder` designated as RSS items.""" try: return _folder.Folder( self, self._extract_ipm_ol2007_entryid(RSF_PID_RSS_SUBSCRIPTION)) except NotFoundError: pass
def journal(self): """:class:`Folder` designated as journal.""" try: return _folder.Folder( self, _benc(HrGetOneProp(self._root, PR_IPM_JOURNAL_ENTRYID).Value)) except (MAPIErrorNotFound, NotFoundError): pass
def outbox(self): """:class:`Folder` designated as outbox.""" try: return _folder.Folder( self, _benc(HrGetOneProp(self.mapiobj, PR_IPM_OUTBOX_ENTRYID).Value)) except (MAPIErrorNotFound, NotFoundError): pass
def suggested_contacts(self): """:class`Folder` designated as Suggested contacts.""" try: return _folder.Folder( self, self._extract_ipm_ol2007_entryid(RSF_PID_SUGGESTED_CONTACTS)) except NotFoundError: pass
def drafts(self): """:class:`Folder` designated as drafts.""" try: return _folder.Folder( self, _benc(HrGetOneProp(self._root, PR_IPM_DRAFTS_ENTRYID).Value)) except (MAPIErrorNotFound, NotFoundError): pass
def sentmail(self): """:class:`Folder` designated as sentmail.""" try: return _folder.Folder( self, _benc( HrGetOneProp(self.mapiobj, PR_IPM_SENTMAIL_ENTRYID).Value)) except (MAPIErrorNotFound, NotFoundError): pass
def _create_folder_tree(root_folder=None): vcenter = get_vcenter() folders = {} if root_folder is None: # What if multiple datacenters are available? childEntity[0]... root_folder = folder.Folder('vm', _pyVmomiFolder=vcenter._connection.content. rootFolder.childEntity[0].vmFolder) elif isinstance(root_folder, vim.Folder): root_folder = folder.Folder(root_folder.name, _pyVmomiFolder=root_folder) elif isinstance(root_folder, str): root_folder = folder.Folder(root_folder) _get_folders_tree(root_folder, folders) return folders
def wastebasket(self): """:class:`Folder` designated as wastebasket.""" try: return _folder.Folder( self, _benc( HrGetOneProp(self.mapiobj, PR_IPM_WASTEBASKET_ENTRYID).Value)) except (MAPIErrorNotFound, NotFoundError): pass
def calendar(self): """:class:`Folder` designated as calendar.""" try: return _folder.Folder( self, _benc( HrGetOneProp(self._root, PR_IPM_APPOINTMENT_ENTRYID).Value)) except (MAPIErrorNotFound, NotFoundError): pass
def _split(mapiobj, store): notif = Notification(mapiobj) notif.mapiobj = mapiobj notif.object = None notif.object_type = None notif.event_type = None # object if mapiobj.ulObjType == MAPI_MESSAGE: item = _item.Item() item.store = store item.server = store.server item._entryid = mapiobj.lpEntryID notif.object_type = 'item' notif.object = item elif mapiobj.ulObjType == MAPI_FOLDER: folder = _folder.Folder(store=store, entryid=_benc(mapiobj.lpEntryID), _check_mapiobj=False) notif.object = folder notif.object_type = 'folder' # event if mapiobj.ulEventType in (fnevObjectCreated, fnevObjectCopied): notif.event_type = 'created' yield notif elif mapiobj.ulEventType == fnevObjectModified: notif.event_type = 'updated' yield notif elif mapiobj.ulEventType == fnevObjectDeleted: item._folder = store.folder(entryid=_benc(mapiobj.lpParentID)) notif.event_type = 'deleted' yield notif elif mapiobj.ulEventType == fnevObjectMoved: notif.event_type = 'created' yield notif notif = copy.copy(notif) item = _item.Item() item.store = store item.server = store.server item._entryid = mapiobj.lpOldID notif.object = item item._folder = store.folder(entryid=_benc(mapiobj.lpOldParentID)) notif.event_type = 'deleted' yield notif
def __init__(self, vm_name, guest_username=consts.DEFAULT_GUEST_USERNAME, guest_password=consts.DEFAULT_GUEST_PASSWORD, parent=None, _pyVmomiVM=None): """ @summary: Initiate the virtual machine object. @param vm_name: The name of the virtual machine on ESX server. @type vm_name: string @param guest_username: The user account name of the guest OS. @type guest_username: string @param guest_password: The login password to the guest OS. @type guest password: string @param parent: ??? @type parent: ??? """ self.name = vm_name self._parent = None if isinstance(parent, folder.Folder): self._parent = parent elif isinstance(parent, vim.Folder): self._parent = folder.Folder(folder_name=parent.name, _pyVmomiFolder=parent) if isinstance(_pyVmomiVM, vim.VirtualMachine): self._pyVmomiVM = _pyVmomiVM else: self._pyVmomiVM = utils.get_obj_by_name( name=vm_name, vimtypes=[vim.VirtualMachine], folder=self._parent._pyVmomiFolder if self._parent else None ) self._moid = self._pyVmomiVM._moId self.username = guest_username self.password = guest_password try: self.template = self._pyVmomiVM.config.template self.os_name = self._pyVmomiVM.config.guestFullName self._vmx = self._pyVmomiVM.config.files.vmPathName except AttributeError: # TODO: Usually cause when a vm doesnt exist anymore. What should we do? pass # TODO: Find a better way to do that self.remote = RemotePlugin(self) # Load collected plugins if they're compatible with the guest OS for plugin in vmpie._plugins: if self._is_plugin_compatible(plugin): self.load_plugin(plugin) self._path = "" self._datastores = []
def subtree(self): """:class:`Folder` designated as IPM.Subtree.""" try: if self.public: ipmsubtreeid = HrGetOneProp(self.mapiobj, PR_IPM_PUBLIC_FOLDERS_ENTRYID).Value else: ipmsubtreeid = HrGetOneProp(self.mapiobj, PR_IPM_SUBTREE_ENTRYID).Value return _folder.Folder(self, _benc(ipmsubtreeid)) except (MAPIErrorNotFound, NotFoundError): pass
def __init__(self, datacenter_name): self.name = datacenter_name self.pyVmomiDatacenter = utils.get_obj_by_name( name=datacenter_name, vimtypes=[vim.Datacenter]) # Get names of the folders in datacenters self._folders = folder.Folder('vm').folders # Get datastores for the datacenter self.datastores = [ datastore.Datastore(ds.name) for ds in self.pyVmomiDatacenter.datastore ]
def folder(self, path=None, entryid=None, recurse=False, create=False): """ Return :class:`Folder` with given path or entryid """ if entryid is not None: try: return _folder.Folder(self, entryid) except (MAPIErrorInvalidEntryid, MAPIErrorNotFound): # XXX move to Folder raise NotFoundError("no folder with entryid: '%s'" % entryid) return self.subtree.folder(path, recurse=recurse, create=create)
def folder(self, path=None, entryid=None, recurse=False, create=False): """Return :class:`Folder` with given path/entryid. :param path: The path of the folder :param entryid: The entryid of the folder :param create: Create folder if it doesn't exist """ if entryid is not None: try: return _folder.Folder(self, entryid) except (MAPIErrorInvalidEntryid, MAPIErrorNotFound): # XXX move to Folder raise NotFoundError("no folder with entryid: '%s'" % entryid) return self.subtree.folder(path, recurse=recurse, create=create)
def ImportFolderChange(self, props): if hasattr(self.importer, 'update'): eid = _benc(PpropFindProp(props, PR_ENTRYID).Value) folder = _folder.Folder(store=self.importer.store, entryid=eid) self.importer.update(folder)