Commit 8046d324 authored by matograine's avatar matograine

* Allow batch retrieving

  * allow to retrieve a whole folder
  * allow to chose the folder
  * allow to retrieve a single file
  * move used files to .backup folder (we should add a function to retrieve the backup folder in case of mistake)
  * do not include empty wallets in transactions issuers.

* deal with filled tips
  * we can retrieve tips that contain a lot of sources
parent b3a6def8
......@@ -11,15 +11,20 @@
from utils.common import Creating # Generator
from utils.retrieve import Retrieve
from utils.utils import CheckConfig
from utils.constants import DEFAULT_FOLDER, WALLETS_FOLDER, BACKUP_FOLDER
from sys import argv
def help():
print ("Utiliser Ğ1Dons\n===============")
print ("\nUtiliser Ğ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>\"")
print ("\nLes Ğ1Dons sont enregistrés dans {0}.".format(DEFAULT_FOLDER))
print ("Les fichiers de récupération sont enregistrés dans {0}.".format(DEFAULT_FOLDER + WALLETS_FOLDER))
print ("Lors d'une récupération, les fichiers récupérés sont enregistrés dans {0}<année> en cas de transaction mal effectuée.\n".format(DEFAULT_FOLDER + BACKUP_FOLDER))
# main
if len(argv) > 1:
......@@ -38,8 +43,8 @@ if len(argv) > 1:
Retrieve().retrieve()
elif len(argv) == 3:
Retrieve(folder=argv[2]).retrieve()
elif len(argv) == 4 and argv[3] == "fichier":
Retrieve(file=argv[3]).retrieve()
elif len(argv) == 4 and argv[2] == "fichier":
Retrieve(_file=argv[3]).retrieve()
else:
print ("Erreur : information mal formatées.")
help()
......
......@@ -76,11 +76,6 @@ class Creating:
) as f:
f.write(signed_data)
with open(
self.backup_folder + self.output + ".json.signed", "a"
) as b:
b.write(signed_data)
# Ajouter la date au json
def tip_date(self):
"""
......
......@@ -8,4 +8,5 @@ WALLETS_FOLDER = "Recuperation_ne_pas_supprimer/"
BACKUP_FOLDER = ".backup/"
CONF_FILE = ".config"
MAX_PAGES = 10
MAX_ISSUERS = 18
COMMENT = "G1Don"
This diff is collapsed.
......@@ -24,4 +24,4 @@ G1_TEST_DEFAULT_ENDPOINT = "ts.gt.librelois.fr", "443"
CONNECTION_TIMEOUT = 10
ASYNC_SLEEP = 0.1
PUBKEY_PATTERN = "[1-9A-HJ-NP-Za-km-z]{43,44}"
SOURCES_PER_TX = 40
SOURCES_PER_TX = 30
......@@ -373,7 +373,7 @@ async def generate_and_send_transaction(
OutputbackChange,
)
transaction.sign(key_list)
# print ("DEBUG : ", transaction.raw())
#print ("DEBUG : ", transaction.raw())
response = await client(process, transaction.signed_raw())
if response.status == 200:
print("Transaction successfully sent.")
......
......@@ -32,11 +32,6 @@ class CheckConfig():
os.makedirs(self.backup_folder)
if not os.path.exists(self.config_file):
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):
......@@ -52,15 +47,14 @@ class CheckConfig():
f.write(json.dumps(node, indent=4))
def backup_data(data):
def backup_data(data, name):
# check that the backup folder exists
year = datetime.datetime.now().year
year = str(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)))
# create the backup path and move the file
backup = os.path.join(backup_folder, name)
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