Пример #1
0
 def __setstate__(self, from_wire: Any):
     self._site_uuid, self._namespace, name = from_wire
     self._storage_path = get_storage_path(self._site_uuid)
     self._create = False
     self._encname = name.encode('utf-8')
     _, self._env, self._namedb, self._attrdb, self._versdb, self._descdb = \
     get_environment_threadsafe(
         self._storage_path,
         self._namespace,
         create = False
     )
     self._userdb = []
     with transaction_context(self._env, write=False) as (txn, _, _):
         self._uuid_bytes = txn.get(key=self._encname, db=self._namedb)
         self._uuid_bytes = bytes(self._uuid_bytes) \
         if isinstance(self._uuid_bytes, memoryview) else self._uuid_bytes
         if self._uuid_bytes is None:
             raise ObjectNotFoundError()
         result = txn.get(key=self._uuid_bytes, db=self._descdb)
         result = bytes(result) if isinstance(result,
                                              memoryview) else result
         descriptor = orjson.loads(result)
         self._versioned = descriptor['versioned']
     self.__bind_databases(descriptor=descriptor)
     self.__class__.__initialize_class__()
Пример #2
0
def enable_tasks(*, site_uuid: Optional[str] = None) -> bool:
    if site_uuid is None:
        if thread.local.default_site is not None:
            storage_path, site_uuid = thread.local.default_site
        else:
            raise SiteNotSpecifiedError()
    else:
        storage_path = get_storage_path(site_uuid)
    monitor_name = constants.MONITOR_DAEMON_MODULE.split('.')[-1]
    with pidtable:
        if not any(
            True for entry in pidtable.get_snapshot().values() \
            if isinstance(entry['node_uid'], str) and \
            entry['node_uid'].split('-')[0] == monitor_name and \
            isinstance(entry['cluster_uid'], str) and \
            entry['cluster_uid'] == site_uuid
        ):
            node_uid = '-'.join([
                monitor_name,
                str(pidtable.next_counter_value()),
                str(uuid.uuid4())
            ])
            process_uid = str(uuid.uuid4())
            pid = launch_node(
                node_uid,
                constants.MONITOR_DAEMON_MODULE,
                site_uuid,
                {
                    constants.DEFAULT_SITE_PATH_ENVNAME: storage_path,
                    constants.PROCESS_UID_ENVNAME: process_uid
                }
            )
            pidtable.set_pid_entry(
                pid = pid, process_uid = process_uid,
                node_uid = node_uid, cluster_uid = site_uuid
            )
            return True
        return False
Пример #3
0
class Namespace():

    def __init__(
        self,
        namespace: Optional[str] = None,
        /, *,
        create: bool = False,
        site_uuid: Optional[str] = None,
        include_hidden: bool = False
    ):
        self._path = resolve_namespace(namespace)
        self._create = create
        self._include_hidden = include_hidden
        if site_uuid is not None:
            self._site_uuid = site_uuid
            self._storage_path = get_storage_path(self._site_uuid)
        else:
            if thread.local.default_site is not None:
                self._storage_path, self._site_uuid = thread.local.default_site
            else:
                raise SiteNotSpecifiedError()

    @property
    def site_uuid(self) -> str:
        return self._site_uuid

    @property
    def path(self) -> str:
        return self._path

    @property
Пример #4
0
    def objects(
        self,
        /, *,
        include_hidden: Optional[bool] = None
    ) -> Iterator[Object]:
        return cast(Iterator[Object], self.entities(include_hidden = include_hidden))

def directories(
    path: Optional[str] = None,
    /, *,
    site_uuid: Optional[str] = None,
    include_hidden: bool = False
) -> Iterator[Directory]:
    if site_uuid is not None:
        storage_path = get_storage_path(site_uuid)
    else:
        if thread.local.default_site is not None:
            storage_path, _ = thread.local.default_site
        else:
            raise SiteNotSpecifiedError()
    if path is not None:
        storage_path = os.path.join(storage_path, path)
    for folder_path, _, _ in os.walk(storage_path):
        if folder_path != storage_path:
            namespace = \
            folder_path[len(storage_path):].split(os.path.sep)[1]
            if include_hidden or not (
                namespace.startswith('__') and namespace.endswith('__')
            ):
                if os.path.isfile(os.path.join(folder_path, 'data.mdb')) and \