diff --git a/mytoncore.py b/mytoncore.py index 2fa08ebb..43fd7bd2 100644 --- a/mytoncore.py +++ b/mytoncore.py @@ -138,6 +138,7 @@ def __init__(self): class MyTonCore(): def __init__(self): self.walletsDir = None + self.dbFile = None self.adnlAddr = None self.tempDir = None self.validatorWalletName = None @@ -146,7 +147,6 @@ def __init__(self): self.validatorConsole = ValidatorConsole() self.fift = Fift() - local.dbLoad() self.Refresh() self.Init() #end define @@ -157,7 +157,14 @@ def Init(self): #end define def Refresh(self): - self.walletsDir = dir(local.buffer.get("myWorkDir") + "wallets") + if self.dbFile: + local.dbLoad(self.dbFile) + else: + local.dbLoad() + + if not self.walletsDir: + self.walletsDir = dir(local.buffer.get("myWorkDir") + "wallets") + self.tempDir = local.buffer.get("myTempDir") self.adnlAddr = local.db.get("adnlAddr") diff --git a/mytonctrl.py b/mytonctrl.py index e3dd63ff..b5ae7f5b 100755 --- a/mytonctrl.py +++ b/mytonctrl.py @@ -5,13 +5,16 @@ from mypyconsole.mypyconsole import MyPyConsole from mytoncore import * import platform +import sys, getopt, os + + local = MyPyClass(__file__) console = MyPyConsole() ton = MyTonCore() # Must control: /var/ton-work/db/keyring/ -def Init(): +def Init(argv): # Create user console console.name = "MyTonCtrl" console.AddItem("upgrade", RunUpdater, "Check and install MyTonCtrl updates") @@ -54,6 +57,29 @@ def Init(): console.AddItem("test", Test, "") + # Process input parameters + opts, args = getopt.getopt(argv,"hc:w:",["config=","wallets="]) + for opt, arg in opts: + if opt == '-h': + print ('mytonctrl.py -c -w ') + sys.exit() + elif opt in ("-c", "--config"): + configfile = arg + if not os.access(configfile, os.R_OK): + print ("Configuration file " + configfile + " could not be opened") + sys.exit() + + ton.dbFile = configfile + ton.Refresh() + elif opt in ("-w", "--wallets"): + wallets = arg + if not os.access(wallets, os.R_OK): + print ("Wallets path " + wallets + " could not be opened") + sys.exit() + elif not os.path.isdir(wallets): + print ("Wallets path " + wallets + " is not a directory") + sys.exit() + ton.walletsDir = wallets local.db["config"]["logLevel"] = "debug" local.db["config"]["isLocaldbSaving"] = True @@ -702,6 +728,6 @@ def secondsToText(secs): ### if __name__ == "__main__": - Init() + Init(sys.argv[1:]) console.Run() #end if