summaryrefslogtreecommitdiff
path: root/backend/resilient/bsv_metanet.py
diff options
context:
space:
mode:
Diffstat (limited to 'backend/resilient/bsv_metanet.py')
-rw-r--r--backend/resilient/bsv_metanet.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/backend/resilient/bsv_metanet.py b/backend/resilient/bsv_metanet.py
new file mode 100644
index 0000000..3d21b3e
--- /dev/null
+++ b/backend/resilient/bsv_metanet.py
@@ -0,0 +1,44 @@
+from resilient import html_path, auth_path, dep_path, git, ikiwiki
+import os
+import subprocess
+import time
+
+# TODO: need to connect to a local node, not a web service
+
+class bsvup():
+ binary = "bsvup"
+ found = (os.system("%s" % binary) == 0)
+ # TODO: check dep_path for alternate location for binary
+ if not found:
+ print("WARNING: bsvup not found. bsv metanet won't be updated")
+
+ def __init__(self, keyfile):
+ self.keyfile = os.path.join(auth_path, keyfile)
+ with open(self.keyfile) as f: self.privkey = f.read()
+ self.configdir = self.keyfile + '.bsv'
+ if bsvup.found:
+ if not os.path.isdir(self.configdir):
+ os.mkdir(self.configdir)
+ os.symlink(".", os.path.join(self.configdir, ".bsv"))
+ proc = subprocess.Popen([bsvup.binary, 'init'], stdin=subprocess.PIPE, cwd=self.configdir)
+ proc.stdin.write(self.privkey + "\n")
+ time.sleep(1)
+ proc.communicate("\n")
+ open(os.path.join(self.configdir, "info", ".keepme"), "a").close()
+ open(os.path.join(self.configdir, "objects", ".keepme"), "a").close()
+ open(os.path.join(self.configdir, "tx", ".keepme"), "a").close()
+ else: # resume tx if needed
+ proc = subprocess.Popen([bsvup.binary], stdin=subprocess.PIPE, cwd=self.configdir)
+ proc.communicate("Y\n")
+
+ def push(self):
+ if not ikiwiki.synced or not bsvup.found:
+ return False
+
+ # add files to bsv metanet
+ orig_dir = os.path.abspath(".")
+ proc = subprocess.Popen([bsvup.binary, '-f', html_path, 'upload'], stdin=subprocess.PIPE, cwd=self.configdir)
+ proc.stdin.write("\n")
+ time.sleep(1)
+ proc.stdin.write("Y\n")
+ return proc.wait() == 0