summaryrefslogtreecommitdiff
path: root/backend/resilient
diff options
context:
space:
mode:
authorKarl Semich <0xloem@gmail.com>2016-08-12 01:14:52 -0400
committerKarl Semich <0xloem@gmail.com>2016-08-12 01:14:52 -0400
commita0b1a963501b27a8c8a9cd6c42d38acbc2b8522d (patch)
tree52952d27cae1fa40372d603b4ba50d0dc79958b5 /backend/resilient
parent96563c8022366a85196a91207ff7a25617c9a7b5 (diff)
downloadstandingwithresilience-a0b1a963501b27a8c8a9cd6c42d38acbc2b8522d.tar.gz
standingwithresilience-a0b1a963501b27a8c8a9cd6c42d38acbc2b8522d.zip
Backend: IPFS implementation that uses only the binary
Diffstat (limited to 'backend/resilient')
-rw-r--r--backend/resilient/__init__.py29
1 files changed, 18 insertions, 11 deletions
diff --git a/backend/resilient/__init__.py b/backend/resilient/__init__.py
index 21f2d85..07f3793 100644
--- a/backend/resilient/__init__.py
+++ b/backend/resilient/__init__.py
@@ -3,6 +3,7 @@ import os
import shutil
import subprocess
import tempfile
+import time
import urllib
__all__ = ["freenet"]
@@ -125,15 +126,21 @@ class ipfs:
found = (os.system('ipfs version') == 0)
if not found:
print("WARNING: ipfs not found, ipfs content won't be updated")
- else:
- found = (os.system('ipns-pub --version') == 0)
- if not found:
- print ("WARNING: ipns-pub not found, ipfs content won't be updated")
synced = False
- def __init__(self, keyfile):
- self.keyfile = keyfile
+ def __init__(self, configdir):
+ self.configdir = os.path.join(auth_path, configdir)
+ subprocess.Popen(['ipfs', '-c', self.configdir, 'daemon'])
+ while self._config('Identity.PeerID') == None:
+ time.sleep(0.5)
+ self.peerid = self._config('Identity.PeerID')
+ self.gateway = self._config('Addresses.Gateway').replace('/ip4','http:/').replace('/tcp/',':')
+
+ def _config(self, key):
+ proc = subprocess.Popen(['ipfs', '-c', self.configdir, 'config', key], stdout=subprocess.PIPE)
+ for line in proc.stdout:
+ return line[0:-1]
def push(self):
if not ikiwiki.synced or not ipfs.found:
@@ -141,16 +148,16 @@ class ipfs:
# add files to ipfs
if not ipfs.synced:
- proc = subprocess.Popen(['ipfs', 'add', '-rH', html_path], stdout=subprocess.PIPE)
+ proc = subprocess.Popen(['ipfs', '-c', self.configdir, 'add', '-rH', html_path], stdout=subprocess.PIPE)
for line in proc.stdout:
print line[0:-1]
ipfs.hash = line[6:52]
ipfs.synced = True
# publish hash to private key
- proc = subprocess.Popen(['ipns-pub', '-key=%s' % self.keyfile, ipfs.hash])
+ proc = subprocess.Popen(['ipfs', '-c', self.configdir, 'name', 'publish', ipfs.hash], stdout=subprocess.PIPE)
+ for line in proc.stdout:
+ print line[0:-1]
+ self.peerid = line[13:59]
status = proc.wait()
- if status != 0:
- print 'NOTE: ipns-pub failed to run under python as is common, try running by hand.'
- print 'CMDLINE: ipns-pub -key=%s %s' % (self.keyfile, ipfs.hash)
return status == 0