Пример #1
0
    def _getmodels(self, nodepath, contents_dict):
        """Extract and return the list of models in source.

        Args:
            nodepath (str): Path to an entry on the server.
            contents_dict (dict): data dict from server

        Returns:
            list of rpws.models.ModelInfo
        """
        model_infos = []
        for mdict in contents_dict.get(api.NODE_MODELS_KEY, []):
            # get in-progress lock objs
            ip_locks = \
                self._getlocks(mdict[api.NODE_MODELS_LOCKINPROGRESS_KEY])
            # make lock state obj
            lock_state = models.LockState(mdict[api.NODE_MODELS_LOCKSTATE_KEY])
            # create model info obj
            minfo = models.ModelInfo(
                path=op.join(nodepath if nodepath else self.path,
                             mdict[api.NODE_MODELS_NAME_KEY]),
                name=mdict[api.NODE_MODELS_NAME_KEY],
                size=mdict[api.NODE_MODELS_SIZE_KEY],
                support_size=mdict[api.NODE_MODELS_SUPPORTSIZE_KEY],
                product_version=mdict[api.NODE_MODELS_PRODUCTVERSION_KEY],
                lock_context=mdict[api.NODE_MODELS_LOCKCONTEXT_KEY],
                lock_state=lock_state,
                locks_inprogress=ip_locks)

            model_infos.append(minfo)

        return model_infos
Пример #2
0
    def _getfolders(self, nodepath, contents_dict):
        """Extract and return the list of subfolders.

        Args:
            nodepath (str): Path to an entry on the server.
            contents_dict (dict): data dict from server

        Returns:
            list of rpws.models.FolderInfo
        """
        folder_infos = []

        for fdict in contents_dict.get(api.NODE_FOLDERS_KEY, []):
            # get in-progress lock objs
            ip_locks = self._getlocks(
                fdict[api.NODE_FOLDERS_LOCKINPROGRESS_KEY])
            # make lock state obj
            lock_state = \
                models.LockState(fdict[api.NODE_FOLDERS_LOCKSTATE_KEY])
            # create folder info obj
            finfo = models.FolderInfo(
                path=op.join(nodepath if nodepath else self.path,
                             fdict[api.NODE_FOLDERS_NAME_KEY]),
                name=fdict[api.NODE_FOLDERS_NAME_KEY],
                size=fdict[api.NODE_FOLDERS_SIZE_KEY],
                has_contents=fdict[api.NODE_FOLDERS_HASCONTENTS_KEY],
                lock_context=fdict[api.NODE_FOLDERS_LOCKCONTEXT_KEY],
                lock_state=lock_state,
                locks_inprogress=ip_locks)

            folder_infos.append(finfo)

        return folder_infos
Пример #3
0
    def getfolderinfo(self, nodepath):
        """ Returns directory info from provided directory

        API command:
            /directoryinfo

        Args:
            nodepath (str): Path to an entry on the server.

        Returns:
            rpws.models.EntryDirInfo

        Example:
            >>> rserver = RevitServer('server01', '2017')
            >>> for folder in rserver.listfolders('/example/path'):
            ...     finfo = rserver.getfolderinfo(folder.path)
            ...     print(finfo.date_created)
        """

        if nodepath:
            # directory info from the entry
            ddict = self._get(api.REQ_CMD_DIRINFO, nodepath)

            # in-progress locks
            ip_locks = self._getlocks(
                ddict[api.NODE_DIRINFO_LOCKSINPROGRESS_KEY])

            # make lock state
            lock_state = models.LockState(
                ddict[api.NODE_DIRINFO_LOCKSTATE_KEY])

            # make time stamps
            date_created = models.DateEntry.\
                fromrsdatestring(ddict[api.NODE_DIRINFO_DATECREATED_KEY])
            date_modified = models.DateEntry.\
                fromrsdatestring(ddict[api.NODE_DIRINFO_DATEMODIFIED_KEY])

            # make the directory info obj
            return models.EntryDirInfo(
                path=nodepath,
                name=op.basename(nodepath),
                size=ddict[api.NODE_DIRINFO_SIZE_KEY],
                date_created=date_created,
                date_modified=date_modified,
                exists=ddict[api.NODE_DIRINFO_EXISTS_KEY],
                folder_count=ddict[api.NODE_DIRINFO_FOLDERCOUNT_KEY],
                is_folder=ddict[api.NODE_DIRINFO_ISFOLDER_KEY],
                last_modified_by=ddict[api.NODE_DIRINFO_LASTMODIFIEDBY_KEY],
                lock_context=ddict[api.NODE_DIRINFO_LOCKCTX_KEY],
                lock_state=lock_state,
                model_count=ddict[api.NODE_DIRINFO_MODELCOUNT_KEY],
                model_size=ddict[api.NODE_DIRINFO_MODELSIZE_KEY],
                locks_inprogress=ip_locks)
Пример #4
0
    def scandir(self, nodepath=None):
        """ Returns files, folders, and models from root or provided
        directory in an entry info obj

        API command:
            /contents

        Args:
            nodepath (str, optional): Path to an entry on the server.
                                      Root if not provided.

        Returns:
            rpws.models.EntryContents

        Example:
            >>> rserver = RevitServer('server01', '2017')
            >>> for entry in rserver.scandir('/example/path'):
            ...     print(entry.path)
        """

        # get the entry contents (root if nodepath is none
        contents_dict = self._get(api.REQ_CMD_CONTENTS, nodepath)

        # get drive info
        sdriveinfo = self._getserverdriveinfo(contents_dict)

        # get the files, folders, and models
        node_files = self._getfiles(nodepath, contents_dict)
        node_folders = self._getfolders(nodepath, contents_dict)
        node_models = self._getmodels(nodepath, contents_dict)

        lock_ctx = contents_dict[api.NODE_LOCK_CTX_KEY]
        lock_state = models.LockState(contents_dict[api.NODE_LOCK_STATE_KEY])
        ip_locks = self._getlocks(contents_dict[api.NODE_LOCKS_INPROGRESS_KEY])

        return models.EntryContents(path=nodepath,
                                    drive_space=sdriveinfo.drive_space,
                                    drive_freespace=sdriveinfo.drive_freespace,
                                    files=node_files,
                                    folders=node_folders,
                                    lock_context=lock_ctx,
                                    lock_state=lock_state,
                                    locks_inprogress=ip_locks,
                                    models=node_models)