コード例 #1
0
ファイル: ipfssearch.py プロジェクト: atavacron/galacteek
    def findByHash(self, mHash):
        for result in self._cResults:
            hit = result['hit']
            hitHash = hit.get('hash')

            if not hitHash:
                continue

            if cidConvertBase32(hitHash) == cidConvertBase32(mHash):
                return hit
コード例 #2
0
    def getFullPath(self):
        """
        Returns the full IPFS path of the entry associated with this item
        (preserving file names) if we have the parent's hash, or the IPFS path
        with the entry's hash otherwise
        """

        if self._parentCid:
            return joinIpfs(
                posixIpfsPath.join(cidConvertBase32(self._parentCid),
                                   self.filename))
        else:
            return joinIpfs(cidConvertBase32(self.entry['Hash']))
コード例 #3
0
ファイル: unixfs.py プロジェクト: pinnaculum/galacteek
    async def gitClone(self, ipfsop, entry, dest):
        """
        Clone the git repository contained within entry, to directory dest
        """
        from git.repo import base
        from git.exc import InvalidGitRepositoryError

        self.gitButton.setEnabled(False)

        mHash = cidConvertBase32(entry['Hash'])
        getRet = await ipfsop.client.get(mHash, dstdir=self.app.tempDir.path())
        if not getRet:
            self.gitButton.setEnabled(True)
            return messageBox('Could not fetch the git repository')

        repoPath = os.path.join(self.app.tempDir.path(), mHash)
        try:
            repo = base.Repo(repoPath)
        except InvalidGitRepositoryError:
            return messageBox(iGitInvalid())

        dstPath = '{}.git'.format(os.path.join(dest, self.rootHash))

        # Clone it now. No need to run it in a threadpool since the git module
        # will run a git subprocess for the cloning
        try:
            repo.clone(dstPath)
        except Exception as e:
            self.gitButton.setEnabled(True)
            return messageBox(iGitErrorCloning(str(e)))

        messageBox(iGitClonedRepo(dstPath))
        self.gitButton.setEnabled(True)
コード例 #4
0
ファイル: ipfsview.py プロジェクト: atavacron/galacteek
 def getFullPath(self):
     """
     Returns the full IPFS path of the entry associated with this item
     (preserving file names) if we have the parent's hash, or the IPFS path
     with the entry's hash otherwise
     """
     parentHash = self.getParentHash()
     name = self.entry['Name']
     if parentHash:
         return joinIpfs(os.path.join(parentHash, name))
     else:
         return joinIpfs(cidConvertBase32(self.entry['Hash']))
コード例 #5
0
ファイル: ipfsview.py プロジェクト: atavacron/galacteek
    async def list(self,
                   op,
                   path,
                   parentItem=None,
                   autoexpand=False,
                   resolve_type=True):

        parentItemSibling = self.model.sibling(parentItem.row(),
                                               self.model.COL_HASH,
                                               parentItem.index())
        parentItemHash = self.model.data(parentItemSibling)
        if parentItemHash is None:
            parentItemHash = self.rootHash

        async for obj in op.list(path, resolve_type):
            for entry in obj['Links']:
                await op.sleep()

                cid = cidConvertBase32(entry['Hash'])
                if cid in self.model.entryCache:
                    continue

                if len(entry['Name']) > 32:
                    entryName = entry['Name'][0:32]
                else:
                    entryName = entry['Name']

                nItemName = IPFSNameItem(entry, entryName, None)

                if self.mimeDetectionMethod == 'db':
                    nItemName.mimeFromDb(self.app.mimeDb)
                elif self.mimeDetectionMethod == 'magic':
                    mType = await detectMimeType(cid)
                    if mType:
                        nItemName.mimeType = str(mType)

                nItemName.setParentHash(parentItemHash)
                nItemSize = IPFSItem(sizeFormat(entry['Size']))
                nItemSize.setToolTip(str(entry['Size']))
                nItemMime = IPFSItem(nItemName.mimeType or iUnknown())
                nItemHash = IPFSItem(cid)
                nItemHash.setToolTip(cidInfosMarkup(cid))
                nItemName.setToolTip(entry['Name'])

                if nItemName.isDir():
                    nItemName.setIcon(self.iconFolder)
                elif nItemName.isFile():
                    if nItemName.mimeType:
                        mIcon = getMimeIcon(nItemName.mimeType)
                        if mIcon:
                            nItemName.setIcon(mIcon)
                        else:
                            nItemName.setIcon(self.iconFile)
                    else:
                        nItemName.setIcon(self.iconFile)
                elif nItemName.isUnknown():
                    nItemName.setIcon(self.iconUnknown)

                nItem = [nItemName, nItemSize, nItemMime, nItemHash]
                parentItem.appendRow(nItem)

                if nItemName.isDir() and self.autoOpenFolders:
                    # Automatically open sub folders. Used by unit tests
                    self.directoryOpenRequest.emit(dataHash)

                if nItemName.isDir() and entry['Name'] == '.git' and \
                        self.gitEnabled is True:
                    # If there's a git repo here, add a control button
                    self.addGitControl(entry)
コード例 #6
0
ファイル: ipfsview.py プロジェクト: atavacron/galacteek
 def cid(self):
     return cidhelpers.getCID(cidConvertBase32(self.entry['Hash']))