Commit b3a6def8 authored by matograine's avatar matograine

* create a config file for node

  * "write_node_conf" in utils/utils.py
* modify main.py
  * add "noeud"
  * add "help" minimal function
  * add a default behavior
parent e8daa47d
......@@ -10,23 +10,50 @@
from utils.common import Creating # Generator
from utils.retrieve import Retrieve
from utils.utils import CheckConfig
from sys import argv
import asyncio
import aiohttp
import async_timeout
def help():
print ("Utiliser Ğ1Dons\n===============")
print ("Générer des dons : \"generer <montant> <nombre_pages> <peremption_date_JJ/MM/AAAA>\"")
print ("Récupérer des dons : \"recuperer\"")
print ("Récupérer des dons depuis un dossier : \"recuperer <dossier>\"")
print ("Récupérer des dons depuis un fichier : \"recuperer fichier <fichier>\"")
print ("Configurer le noeud Duniter : \"noeud <noeud> <port>\"")
# main
if len(argv) > 1:
if argv[1] == "generate":
amount = float(argv[2])
pages = int(argv[3])
date = str(argv[4])
Creating (amount, date, pages).create()
if argv[1] == "generer":
if len(argv) > 5 or len(argv) < 4:
print ("Erreur : information mal formatées.")
help()
else:
amount = float(argv[2])
pages = int(argv[3])
date = str(argv[4])
Creating (amount, date, pages).create()
elif argv[1] == "recuperer":
if len(argv) == 2:
Retrieve().retrieve()
elif len(argv) == 3:
Retrieve(folder=argv[2]).retrieve()
elif len(argv) == 4 and argv[3] == "fichier":
Retrieve(file=argv[3]).retrieve()
else:
print ("Erreur : information mal formatées.")
help()
elif argv[1] == "retrieve":
file = argv[2]
# pubkey = argv [3]
Retrieve().retrieve(file) #, pubkey)
elif argv[1] == "noeud":
if len(argv) != 4:
print ("Erreur : information mal formatées.")
help()
else:
CheckConfig().write_node_conf(argv[2], int(argv[3]))
else:
help()
else :
print ("Use \"generate <amount> <pages number> <peremption_date_DD/MM/YYYY>\" to generate Ğ1Dons.")
print ("Use \"retrieve <file>\" to retrieve Ğ1Dons from a file")
help()
......@@ -31,14 +31,36 @@ class CheckConfig():
if not os.path.exists(self.backup_folder):
os.makedirs(self.backup_folder)
if not os.path.exists(self.config_file):
node = dict()
node["domain"] = str(G1_DEFAULT_ENDPOINT[0])
node["port"] = int(G1_DEFAULT_ENDPOINT[1])
with open(self.config_file) as f:
f.write(json.dumps(node, 4))
self.write_node_conf(str(G1_DEFAULT_ENDPOINT[0]), int(G1_DEFAULT_ENDPOINT[1]))
# node = dict()
# node["domain"] = str(G1_DEFAULT_ENDPOINT[0])
# node["port"] = int(G1_DEFAULT_ENDPOINT[1])
# with open(self.config_file) as f:
# f.write(json.dumps(node, 4))
def get_conf(self):
if not os.path.exists(self.config_file):
self.check()
with open(self.config_file, "r") as f:
return json.loads(f.read())
def write_node_conf(self, given_node, port):
node = dict()
node["domain"] = str(given_node)
node["port"] = str(port)
with open(self.config_file, "w") as f:
f.write(json.dumps(node, indent=4))
def backup_data(data):
# check that the backup folder exists
year = datetime.datetime.now().year
backup_folder = os.path.expanduser(DEFAULT_FOLDER + BACKUP_FOLDER + year)
if not os.path.exists(backup_folder):
os.makedirs(backup_folder)
# create the backup path as a number
files = os.listdir(backup_folder)
backup = os.path.join(backup_folder, str(len(files)))
os.rename(data, backup)
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