summaryrefslogtreecommitdiff
path: root/backend/resilient
diff options
context:
space:
mode:
Diffstat (limited to 'backend/resilient')
-rw-r--r--backend/resilient/__init__.py63
-rw-r--r--backend/resilient/freenet.py6
2 files changed, 53 insertions, 16 deletions
diff --git a/backend/resilient/__init__.py b/backend/resilient/__init__.py
index 490ff3f..135c47d 100644
--- a/backend/resilient/__init__.py
+++ b/backend/resilient/__init__.py
@@ -1,7 +1,13 @@
-import os, urllib
+import fileinput
+import os
+import shutil
+import subprocess
+import tempfile
+import urllib
__all__ = ["freenet"]
+## Set to change default title
name = 'A Wiki for Targeted Individuals'
backend_path = os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))
@@ -26,9 +32,9 @@ class git:
print("ERROR: git not found")
exit(1)
- def __init__(self, remote, push_remote = None):
+ def __init__(self, remote, push_remote = ""):
self.remote = remote
- if push_remote == None:
+ if push_remote == "":
push_remote = remote
self.push_remote = push_remote
@@ -63,22 +69,23 @@ class ikiwiki:
if ikiwiki.synced:
return True
- html_git_path = os.path.join(html_path, '.git')
- os.system("rm -rf '%s'" % html_path)
- os.system("mkdir -p '%s'" % html_git_path)
+ shutil.rmtree(html_path)
+ os.mkdir(html_path)
status = os.system("ikiwiki --wikiname '%s' --rebuild '%s' '%s'" % (name.replace("'","'\"'\"'"), wiki_src_path, html_path))
- ikiwiki.synced = status == 0
+ ikiwiki.synced = (status == 0)
if ikiwiki.synced:
os.system('git gc')
os.system('git update-server-info')
+ html_git_path = os.path.join(html_path, '.git')
+ os.mkdir(html_git_path)
for path in ['objects', 'refs', 'HEAD', 'info', 'packed-refs']:
- os.system("cp -r '%s' '%s'" % (os.path.join(git_path, path), html_git_path))
+ shutil.copytree(os.path.join(git_path, path), os.path.join(html_git_path, path))
return ikiwiki.synced
-class zeronet():
+class zeronet:
running = url200('http://127.0.0.1:43110/1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D')
if not running:
print("WARNING: ZeroNet not running, won't be used")
@@ -96,12 +103,46 @@ class zeronet():
self.key = key
def push(self):
- if not ikiwiki.synced:
+ if not ikiwiki.synced or not zeronet.found:
return False
zitedir = os.path.join(zeronet.zn_datadir, self.addr)
- status = os.system('cp -r %s %s' % (os.path.join(html_path, '.'), os.path.join(zitedir, '.')))
+ shutil.rmtree(zitedir, True)
+ shutil.copytree(html_path, zitedir)
if status != 0:
return False
status = os.system('%s siteSign %s %s' % (zeronet.zn_script, self.addr, self.key))
return status == 0
+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 push(self):
+ if not ikiwiki.synced or not ipfs.found:
+ return False
+
+ # add files to ipfs
+ if not ipfs.synced:
+ proc = subprocess.Popen(['ipfs', '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])
+ 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
diff --git a/backend/resilient/freenet.py b/backend/resilient/freenet.py
index ea72760..0f5e741 100644
--- a/backend/resilient/freenet.py
+++ b/backend/resilient/freenet.py
@@ -10,10 +10,6 @@ class gitocalypse(git):
if not found:
print("WARNING: gitocalypse not found, changes won't be synced with freenet")
- def __init__(self, pull_remote, push_remote = None):
- self.remote = pull_remote
- self.push_remote = push_remote
-
class freesitemgr():
found = (os.system("freesitemgr --version") == 0)
if not found:
@@ -23,7 +19,7 @@ class freesitemgr():
pass
def push(self):
- if not ikiwiki.synced:
+ if not ikiwiki.synced or not found or not running:
return False
config_path = os.path.join(auth_path, 'freesitemgr')
status = os.system("freesitemgr -c '%s' -v -r 1 update" % config_path)