Exemplo n.º 1
0
class NotBitProtocol(LineReaderProcessProtocol):
    def __init__(self, *args, **kw):
        super().__init__(*args, **kw)

        self.sPowCalculated = AsyncSignal()
        self.sMessageAccepted = AsyncSignal(str)

    def lineReceived(self, fd, line):
        log.debug(f'NotBit daemon message: {line}')

        match = re.search(r'\[\d*\-\d*\-\d.*?\]\s(.*)$', line)

        if match:
            # Handle specific events

            msg = match.group(1)

            # POW
            if msg.startswith('Finished calculating proof-of-work'):
                ensure(self.sPowCalculated.emit())

            # Message accepted
            ma = re.search(r'Accepted message from (BM-\w*)$', msg)
            if ma:
                ensure(self.sMessageAccepted.emit(ma.group(1)))

        if line.startswith('Failed to bind socket'):
            log.debug('Notbit failed to start')
Exemplo n.º 2
0
class StoredSeedObjectActionsWidget(ObjectActionsWidget):
    def __init__(self, treeItem, obj, parent=None):
        super().__init__(treeItem, obj, parent=parent)

        self.sCancel = AsyncSignal()
        self.sRestart = AsyncSignal()

        self.btnCancel = QPushButton(self)
        self.btnCancel.setText('Cancel')
        self.btnCancel.setIcon(getIcon('cancel.png'))
        self.btnCancel.clicked.connect(
            lambda: ensure(self.sCancel.emit()))
        self.btnCancel.hide()

        self.btnRestart = QPushButton(self)
        self.btnRestart.setText('Restart')
        self.btnRestart.clicked.connect(
            lambda: ensure(self.sRestart.emit()))
        self.btnRestart.hide()

        self.hlayout.addWidget(self.btnCancel)
        self.hlayout.addWidget(self.btnRestart)

    def showControls(self, download=False, cancel=False, restart=False):
        self.btnDownload.setVisible(download)
        self.btnCancel.setVisible(cancel)
        self.btnRestart.setVisible(restart)
Exemplo n.º 3
0
class ObjectActionsWidget(QWidget):
    def __init__(self, treeItem, obj, parent=None):
        super().__init__(parent)

        self.sDownload = AsyncSignal()

        self.treeItem = treeItem
        self.obj = obj
        self.ipfsPath = IPFSPath(self.obj.get('path'))

        self.hlayout = QHBoxLayout(self)
        self.setLayout(self.hlayout)

        self.btnOpen = QPushButton(iOpen())
        self.btnOpen.setText(iOpen())
        self.btnOpen.setIcon(getIcon('open.png'))
        self.btnOpen.clicked.connect(partialEnsure(self.onOpen))

        self.btnHashmark = HashmarkThisButton(self.ipfsPath)
        self.btnClipboard = IPFSPathClipboardButton(self.ipfsPath)

        self.btnDownload = QToolButton(self)
        self.btnDownload.setText('Download')
        self.btnDownload.clicked.connect(self.onDl)
        self.btnDownload.hide()

        self.hlayout.addWidget(self.btnClipboard)
        self.hlayout.addWidget(self.btnHashmark)
        self.hlayout.addWidget(self.btnOpen)
        self.hlayout.addWidget(self.btnDownload)

    def fLayout(self):
        self.hlayout.addItem(
            QSpacerItem(10, 10, QSizePolicy.Expanding, QSizePolicy.Minimum))

    def onDl(self):
        ensure(self.sDownload.emit())

    def showControls(self, download=False):
        self.btnDownload.setVisible(download)

    async def onOpen(self, *a):
        app = QApplication.instance()
        ensure(app.resourceOpener.open(self.obj['path']))
Exemplo n.º 4
0
class TorProtocol(asyncio.SubprocessProtocol):
    def __init__(self, loop, exitFuture, startedFuture, debug=False):
        self._loop = loop
        self.debug = debug
        self.eventStarted = asyncio.Event()
        self.exitFuture = exitFuture
        self.startedFuture = startedFuture
        self.errAlreadyRunning = False

        self.bstrapRe = re.compile(
            r'\s*\d+:\d+:\d+\.\d*\s\[\w*\] Bootstrapped (\d+)\%')

        self.sTorBootstrapStatus = AsyncSignal(int, str)

    @property
    def loop(self):
        return self._loop

    def pipe_data_received(self, fd, data):
        try:
            msg = data.decode().strip()
        except BaseException:
            return

        for line in msg.split('\n'):
            if self.debug:
                log.debug(f'TOR: {line}')

            ma = self.bstrapRe.search(line)
            if ma:
                try:
                    pc = ma.group(1)
                    ensure(
                        self.sTorBootstrapStatus.emit(int(pc), 'bootstrapped'))
                except Exception:
                    continue

    def process_exited(self):
        if not self.exitFuture.done():
            self.exitFuture.set_result(True)
Exemplo n.º 5
0
class PinActions(QObject):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.sPinPageLinksRequested = AsyncSignal(str)

    def pinPath(self, path, recursive=True, notify=True):
        if isinstance(path, str):
            ensure(self.pinQueuePath(path, recursive, notify))
        elif isinstance(path, IPFSPath):
            ensure(self.pinQueuePath(path.objPath, recursive, notify))

    @ipfsOp
    async def pinQueuePath(self, ipfsop, path, recursive, notify):
        log.debug(f'Pinning object {path} (recursive: {recursive})')
        onSuccess = None

        await ipfsop.ctx.pinner.queue(path,
                                      recursive,
                                      onSuccess,
                                      qname=self.pinQueueName)

    @ipfsOp
    async def unpinPath(self, ipfsop, path):
        log.debug(f'UnPinning object {path}')

        result = await ipfsop.unpin(str(path))
        if result:
            await messageBoxAsync(iUnpinHereOk())

    def onPinSingle(self):
        if not self.ipfsPath:
            return messageBox(iNotAnIpfsResource())

        self.pinPath(self.ipfsPath.objPath, recursive=False)

    def onPinRecursive(self):
        if not self.ipfsPath:
            return messageBox(iNotAnIpfsResource())

        self.pinPath(self.ipfsPath.objPath, recursive=True)

    def onPinRecursiveParent(self):
        if not self.ipfsPath:
            return messageBox(iNotAnIpfsResource())

        parent = self.ipfsPath.parent()

        if parent and parent.valid:
            self.pinPath(parent.objPath, recursive=True)
        else:
            self.pinPath(self.ipfsPath.objPath, recursive=True)

    def onUnpin(self):
        if not self.ipfsPath:
            return messageBox(iNotAnIpfsResource())

        ensure(self.unpinPath(self.ipfsPath))

    def onPinPageLinks(self):
        if not self.ipfsPath:
            return messageBox(iNotAnIpfsResource())

        ensure(self.sPinPageLinksRequested.emit(self.ipfsPath))

    async def onUnpinFromRps(self, service, *args):
        if not self.ipfsPath or not self.ipfsPath.valid:
            return

        result = await self.rpsUnpin(service, self.ipfsPath)

        if result:
            await messageBoxAsync(iUnpinFromRpsOk())
        else:
            await messageBoxAsync(iUnpinError())

    @ipfsOp
    async def rpsUnpin(self, ipfsop, service, ipfsPath: IPFSPath):
        resolved = await ipfsop.resolve(ipfsPath.objPath, recursive=True)

        if not resolved:
            return False

        cid = stripIpfs(resolved)

        return await ipfsop.pinRemoteRemove(service.serviceName, cid=[cid])

    @ipfsOp
    async def onPinToRpsWithName(self, ipfsop, service, *args):
        pass

    async def onPinToRps(self, service, *args):
        if not self.ipfsPath or not self.ipfsPath.valid:
            return

        name = None
        if self.ipfsPath.basename:
            name = self.ipfsPath.basename

        if await self.rpsPin(service, name=name):
            await messageBoxAsync(
                iPinToRpsSuccess(service.serviceName, str(self.ipfsPath)))
        else:
            await messageBoxAsync(
                iPinToRpsError(service.serviceName, str(self.ipfsPath)))

    @ipfsOp
    async def rpsPin(self, ipfsop, service, name=None, background=True):
        path = self.ipfsPath.objPath

        if self.ipfsPath.isIpns:
            """
            It's an IPNS path, no worries but resolve it first
            """

            resolved = await ipfsop.nameResolveStreamFirst(
                self.ipfsPath.objPath)
            if resolved:
                path = resolved['Path']

        log.debug(f'RPS pinning object: {path}')

        return await ipfsop.pinRemoteAdd(service.serviceName,
                                         path,
                                         background=background,
                                         name=name)

    async def onPinToRpsAll(self, *args):
        for srv in cfgpinning.rpsList():
            await self.rpsPin(srv)

    def onPinResult(self, f):
        try:
            path, code, msg = f.result()
        except:
            pass
        else:
            path = IPFSPath(path)
            if not path.valid:
                log.debug('Invalid path in pin result: {}'.format(str(path)))
                return

            if code == 0:
                runningApp().systemTrayMessage('PIN',
                                               iPinSuccess(str(path)),
                                               timeout=2000)
            elif code == 1:
                runningApp().systemTrayMessage('PIN',
                                               iPinError(str(path), msg),
                                               timeout=3000)
            elif code == 2:
                # Cancelled, no need to notify here
                pass
            else:
                log.debug('Unknown status code for pinning result')

    def onHelp(self):
        runningApp().manuals.browseManualPage('pinning.html')