Commit ca3b9c69 authored by matograine's avatar matograine

* include graphics files in gdon directory

* deal with non-existing config file

* wrong tests on dir/files during retrieving
parent 466bc33f
include objects/recto.png
include objects/Roboto-Medium.ttf
include objects/verso.png
include objects/wordlist.txt
include gdon/objects/recto.png
include gdon/objects/Roboto-Medium.ttf
include gdon/objects/verso.png
include gdon/objects/wordlist.txt
......@@ -54,7 +54,7 @@ if __name__ == "__main__":
print ("Erreur : information mal formatées.")
help()
else:
CheckConfig().write_node_conf(argv[2], int(argv[3]))
CheckConfig().check_node_conf(argv[2], int(argv[3]))
else:
help()
......
......@@ -8,7 +8,7 @@ import os
# set the wordlist path
wordlist = "objects/wordlist.txt"
parent_dir = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
parent_dir = os.path.abspath(os.path.dirname(__file__))
wordlist_path = os.path.join(parent_dir, wordlist)
def diceware(N, wordlist=wordlist_path, separator="", camelcase=True):
......
......@@ -26,7 +26,7 @@ class Generator:
self.c = None
# set objects dir
par_dir = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
par_dir = os.path.abspath(os.path.dirname(__file__))
#wordlist_path = os.path.join(parent_dir, wordlist)
self.recto = os.path.join(par_dir, recto_file)
self.verso = os.path.join(par_dir, verso_file)
......
......@@ -27,20 +27,20 @@ class Retrieve():
"""
check given values and set self values.
"""
if folder == None and _file == None:
self.folder = os.path.expanduser(DEFAULT_FOLDER + WALLETS_FOLDER)
self.folder = os.path.expanduser(DEFAULT_FOLDER + WALLETS_FOLDER)
elif folder != None and _file != None:
message_exit("Erreur : Retrieve() ne peut recevoir folder ET _file")
elif folder != None:
self.folder = os.path.expanduser(folder)
if not os.path.exists(self.folder):
if not os.path.isdir(self.folder):
message_exit("Erreur : le dossier n'existe pas : {0}".format(self.folder))
elif _file != None:
self.file = os.path.expanduser(_file)
if not os.path.exists(self.file):
if not os.path.isfile(self.file):
message_exit("Erreur : le fichier n'existe pas : {0}".format(self.file))
def open_file(self, file):
......
......@@ -44,14 +44,17 @@ class CheckConfig():
def __call__(self):
return self
def check(self):
def check(self, node=G1_DEFAULT_ENDPOINT):
if not os.path.exists(self.folder):
os.makedirs(self.folder)
if not os.path.exists(self.wallets_folder):
os.makedirs(self.wallets_folder)
if not os.path.exists(self.backup_folder):
os.makedirs(self.backup_folder)
self.write_node_conf(str(G1_DEFAULT_ENDPOINT[0]), int(G1_DEFAULT_ENDPOINT[1]))
if not os.path.exists(self.config_file):
f = open(self.config_file, "x")
f.close()
self.write_node_conf(node[0], node[1])
def get_conf(self):
if not os.path.exists(self.config_file):
......@@ -59,13 +62,16 @@ class CheckConfig():
with open(self.config_file, "r") as f:
return json.loads(f.read())
def check_node_conf(self, given_node: str, port: int):
if not os.path.exists(self.config_file):
self.check([given_node, port])
else:
self.write_node_conf(given_node, port)
def write_node_conf(self, given_node, port):
node = dict()
node["domain"] = str(given_node)
node["port"] = str(port)
if not os.path.exists(self.config_file):
f = open(self.config_file, "x")
f.close()
node["port"] = str(int(port))
with open(self.config_file, "w") as f:
f.write(json.dumps(node, indent=4))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment