Exemple #1
0
    async def loadIpfsObj(self, op):
        """
        Load the JSON from the MFS if it already exists or initialize a new
        object otherwise
        """
        self.debug('Loading mutable object from {}'.format(self.mfsFilePath))

        obj = await op.filesReadJsonObject(self.mfsFilePath)

        if obj:
            self._root = obj
            self.curEntry = await op.filesStat(self.mfsFilePath)
            self.loaded.set_result(True)
            self.evLoaded.set()
        else:
            self.debug('JSON empty or invalid, initializing')
            self._root = self.initObj()
            await self.ipfsSave()
            self.loaded.set_result(True)
            self.evLoaded.set()

        self.parser = traverseParser(self.root)
        if self.upgrade() is True:
            await self.ipfsSave()

        if isinstance(self.root, dict):
            self.available.emit(self.root)
Exemple #2
0
    async def loadDag(self, op):
        self.debug('Loading DAG metadata file')
        meta = await op.filesReadJsonObject(self.dagMetaMfsPath)

        self.debug('Metadata is {}'.format(meta))
        if meta is not None:
            self._dagMeta = meta
            latest = self.dagMeta.get(self.keyCidLatest, None)
            if latest:
                self.dagCid = latest
                self.debug('Getting DAG: {cid}'.format(cid=self.dagCid))
                self._dagRoot = await op.dagGet(self.dagCid)

                if self.dagRoot:
                    if self.updateDagSchema(self.dagRoot) is True:
                        # save right away
                        await self.ipfsSave()
            else:
                self.debug('No CID history, reinitializing')
                # How inconvenient ..
                # TODO: the history could be used here to recreate a DAG
                # from previous CIDs but we really shouldn't have to enter here
                self._dagRoot = {}

            self.loaded.set_result(True)
        else:
            self._dagMeta = {self.keyCidLatest: None, 'history': []}
            self._dagRoot = self.initDag()
            self.updateDagSchema(self.dagRoot)
            await self.ipfsSave()
            self.loaded.set_result(True)

        self.parser = traverseParser(self.dagRoot)
        await self.available.emit(self.dagRoot)
Exemple #3
0
    async def logWatch(self, op):
        try:
            await op.client.log.level('all', 'info')

            async for event in op.client.log.tail():
                display = False
                parser = jtraverse.traverseParser(event)

                systems = [
                    parser.traverse('system'),
                    parser.traverse('Tags.system')
                ]

                if ('core' in systems or 'addrutil' in systems) and \
                        self.checkCore.isChecked():
                    display = True
                elif ('swarm' in systems or 'swarm2' in systems) and \
                        self.checkSwarm.isChecked():
                    display = True
                elif 'dht' in systems and self.checkDht.isChecked():
                    display = True
                elif 'bitswap' in systems and self.checkBitswap.isChecked():
                    display = True
                elif 'pubsub' in systems and self.checkPubsub.isChecked():
                    display = True

                if self.checkAll.isChecked():
                    display = True

                if display is True:
                    self.displayEvent(event)

                await op.sleep(0.05)

        except asyncio.CancelledError:
            return
        except Exception:
            log.debug('Unknown error ocurred while reading ipfs log')
Exemple #4
0
    async def loadIpfsObj(self, op):
        obj = await self.rsaHelper.decryptMfsFile(self.mfsFilePath)

        if obj:
            self._root = json.loads(obj.decode())
            self.debug('Successfully loaded ciphered JSON: {}'.format(
                self.mfsFilePath))
            self.curEntry = await op.filesStat(self.mfsFilePath)
            self.loaded.set_result(True)
            self.evLoaded.set()
        else:
            self.debug('JSON object empty or invalid, initializing')
            self._root = self.initObj()
            await self.ipfsSave()
            self.loaded.set_result(True)
            self.evLoaded.set()

        self.parser = traverseParser(self.root)
        if self.upgrade() is True:
            await self.ipfsSave()

        if isinstance(self.root, dict):
            self.available.emit(self.root)
Exemple #5
0
 def parser(self):
     return traverseParser(self.data)