mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-11-18 12:27:16 +01:00
update
This commit is contained in:
@@ -1,18 +1,16 @@
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
from subprocess import run
|
||||
import sys
|
||||
from threading import Thread
|
||||
|
||||
from venv import create
|
||||
from nostr_sdk import Keys
|
||||
|
||||
from nostr_dvm.dvm import DVM
|
||||
from nostr_dvm.utils.admin_utils import AdminConfig
|
||||
from nostr_dvm.utils.dvmconfig import DVMConfig
|
||||
from nostr_dvm.utils.nip89_utils import NIP89Config
|
||||
from nostr_dvm.utils.nostr_utils import check_and_set_private_key
|
||||
from nostr_dvm.utils.output_utils import post_process_result
|
||||
from nostr_dvm.utils.zap_utils import check_and_set_ln_bits_keys
|
||||
|
||||
|
||||
class DVMTaskInterface:
|
||||
@@ -30,11 +28,13 @@ class DVMTaskInterface:
|
||||
admin_config: AdminConfig
|
||||
dependencies = []
|
||||
|
||||
|
||||
def __init__(self, name, dvm_config: DVMConfig, nip89config: NIP89Config, admin_config: AdminConfig = None,
|
||||
options=None, task=None):
|
||||
self.init(name, dvm_config, admin_config, nip89config, task)
|
||||
self.options = options
|
||||
self.install_dependencies(self.dependencies)
|
||||
self.make_venv(dvm_config)
|
||||
|
||||
|
||||
def init(self, name, dvm_config, admin_config=None, nip89config=None, task=None):
|
||||
self.NAME = name
|
||||
@@ -58,6 +58,16 @@ class DVMTaskInterface:
|
||||
self.dvm_config = dvm_config
|
||||
self.admin_config = admin_config
|
||||
|
||||
def make_venv(self, dvm_config):
|
||||
if dvm_config.SCRIPT != "":
|
||||
dir = r'cache/venvs/' + os.path.basename(dvm_config.SCRIPT).split(".py")[0]
|
||||
if not os.path.isdir(dir):
|
||||
print(dir)
|
||||
create(dir, with_pip=True, upgrade_deps=True)
|
||||
for (module, package) in self.dependencies:
|
||||
print("Installing Module: " + module)
|
||||
run(["bin/pip", "install", package], cwd=dir)
|
||||
|
||||
def run(self):
|
||||
nostr_dvm_thread = Thread(target=self.DVM, args=[self.dvm_config, self.admin_config])
|
||||
nostr_dvm_thread.start()
|
||||
@@ -87,16 +97,6 @@ class DVMTaskInterface:
|
||||
"""Post-process the data and return the result Use default function, if not overwritten"""
|
||||
return post_process_result(result, event)
|
||||
|
||||
def install_dependencies(self, packages):
|
||||
import pip
|
||||
for module, package in packages:
|
||||
try:
|
||||
__import__(module)
|
||||
except ImportError:
|
||||
subprocess.check_call([sys.executable, "-m", "pip", "install", package])
|
||||
|
||||
|
||||
|
||||
@staticmethod
|
||||
def set_options(request_form):
|
||||
print("Setting options...")
|
||||
@@ -105,3 +105,25 @@ class DVMTaskInterface:
|
||||
opts = json.loads(request_form["options"])
|
||||
print(opts)
|
||||
return dict(opts)
|
||||
|
||||
@staticmethod
|
||||
def process_args():
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--request', dest='request')
|
||||
parser.add_argument('--identifier', dest='identifier')
|
||||
parser.add_argument('--output', dest='output')
|
||||
args = parser.parse_args()
|
||||
return args
|
||||
|
||||
@staticmethod
|
||||
def write_output(result, output):
|
||||
with open(os.path.abspath(output), 'w') as f:
|
||||
f.write(result)
|
||||
#f.close()
|
||||
|
||||
def process_venv(self):
|
||||
pass
|
||||
|
||||
if __name__ == '__main__':
|
||||
process_venv()
|
||||
|
||||
Reference in New Issue
Block a user