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