diff options
Diffstat (limited to 'backend/resilient/__init__.py')
-rw-r--r-- | backend/resilient/__init__.py | 29 |
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 |