diff --git a/planetmint/backend/tarantool/database.py b/planetmint/backend/tarantool/database.py new file mode 100644 index 0000000..0cf9c9d --- /dev/null +++ b/planetmint/backend/tarantool/database.py @@ -0,0 +1,23 @@ +import tarantool +import os +from planetmint.backend.tarantool.utils import run + + +class TarantoolDB: + def __init__(self , host , port , username , password): + self.conn = tarantool.connect(host=host , port=port , user = username , password=password) + + + def connect_to_sapce(self,spacename): + self.conn.space(spacename) + + +def init_tarantool(): + path = os.getcwd() + run(["mkdir" , "tarantool"]) + run(["ln","-s",path +"/init.lua","init.lua"] , path+"/tarantool") + run (["tarantool" , "init.lua"] ,path+ "/tarantool") + +def drop_tarantool(): + #TODO drop tarantool + pass \ No newline at end of file diff --git a/planetmint/backend/tarantool/utils.py b/planetmint/backend/tarantool/utils.py new file mode 100644 index 0000000..1c10063 --- /dev/null +++ b/planetmint/backend/tarantool/utils.py @@ -0,0 +1,26 @@ +import os +import subprocess + + +def run(command , path=None): + if path is not None: + os.chdir(path) + p=subprocess.Popen( + command, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + + output , error = p.communicate() + if p.returncode != 0: + print(p.returncode + "\n" + output + "\n" +error) + else: + p=subprocess.run( + command, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + + output , error = p.communicate() + if p.returncode != 0: + print(p.returncode + "\n" + output + "\n" +error) + + diff --git a/planetmint/commands/planetmint.py b/planetmint/commands/planetmint.py index 5e534a7..e134adb 100644 --- a/planetmint/commands/planetmint.py +++ b/planetmint/commands/planetmint.py @@ -13,6 +13,7 @@ import argparse import copy import json import sys +from planetmint.backend.tarantool.database import TarantoolDB, init_tarantool from planetmint.core import rollback from planetmint.migrations.chain_migration_election import ChainMigrationElection @@ -25,6 +26,7 @@ import planetmint from planetmint import (backend, ValidatorElection, Planetmint) from planetmint.backend import schema +from planetmint.backend.tarantool import tarantool from planetmint.commands import utils from planetmint.commands.utils import (configure_planetmint, input_on_stderr) @@ -241,9 +243,11 @@ def run_election_show(args, planet): def _run_init(): - bdb = planetmint.Planetmint() + #bdb = planetmint.Planetmint() - schema.init_database(connection=bdb.connection) + #schema.init_database(connection=bdb.connection) + + init_tarantool() @configure_planetmint