Commit 645df246 authored by matograine's avatar matograine

Check that the document does not already exist (1 minute delay).

parent a838f973
......@@ -5,7 +5,7 @@ import json
from utils.generator import Generator
from utils.transfer import Transfer
from utils.constants import DEFAULT_FOLDER, WALLETS_FOLDER, BACKUP_FOLDER, CONF_FILE, MAX_PAGES
from utils.constants import DEFAULT_FOLDER, WALLETS_FOLDER, BACKUP_FOLDER, PDF_EXTENSION, SIGNED_EXTENSION, CONF_FILE, MAX_PAGES
from utils.utils import CheckConfig, check_date
from utils.silkaj.tools import coroutine, message_exit
from utils.silkaj.auth import auth_by_scrypt
......@@ -27,6 +27,10 @@ class Creating:
self.output = datetime.datetime.now().strftime(
"Ğ1Don_%Y-%m-%dT%Hh%M"
)
self.pdf_output = self.folder + self.output + PDF_EXTENSION
self.signed_output = self.wallets_folder + self.output + SIGNED_EXTENSION
if os.path.isfile(self.pdf_output) or os.path.isfile(self.signed_output):
message_exit("ERREUR : {0}{1}/{2} existe déjà. Attendez une minute et recommencez.".format(self.output, PDF_EXTENSION, SIGNED_EXTENSION))
self.wallets = []
# Check date format
self.date = check_date(given_date)
......@@ -38,11 +42,11 @@ class Creating:
#@coroutine
def create(self):
""" Generating, filling wallets."""
#self.transfer = False
if self.key and self.pages <= MAX_PAGES:
Generator(self.folder + self.output, self.wallets, self.amount, self.date, self.pages).generate()
transfer = Transfer(self.amount, self.pages, self.wallets, self.output, self.date)
Generator(self.pdf_output, self.wallets, self.amount, self.date, self.pages).generate()
transfer = Transfer(self.amount, self.pages, self.wallets, self.date)
self.save_json()
if self.amount > 0:
transfer.transfer(self.key)
......@@ -50,7 +54,7 @@ class Creating:
def save_json(self): #, key):
"""
write wallets data in a json file.
write wallets data in an encrypted json file.
"""
# create and encrypt wallet list
wallet_data = [
......@@ -74,7 +78,7 @@ class Creating:
# sign the whole document
signed_data = ascii_armor.AsciiArmor.create(data, signing_keys=[self.key])
with open(
self.wallets_folder + self.output + ".json.signed", "a"
self.signed_output, "a"
) as f:
f.write(signed_data)
......
......@@ -6,6 +6,8 @@ PUBKEY_FORMAT = "[1-9A-HJ-NP-Za-km-z]{43,44}"
DEFAULT_FOLDER = "~/Documents/G1pourboire/"
WALLETS_FOLDER = "Recuperation_ne_pas_supprimer/"
BACKUP_FOLDER = ".backup/"
PDF_EXTENSION = ".pdf"
SIGNED_EXTENSION = ".json.signed"
CONF_FILE = ".config"
MAX_PAGES = 10
MAX_ISSUERS = 18
......
......@@ -112,7 +112,7 @@ class Generator:
def gen_page(self, wallets):
# Create a new canvas
if self.c == None:
self.c = canvas.Canvas(self.output + ".pdf")
self.c = canvas.Canvas(self.output)
# Size of wallets. You may not edit those values until you know what you do
width = 19 * cm
height = width * 302 / 1270
......
......@@ -13,8 +13,7 @@ from utils.constants import COMMENT
class Transfer:
"""Create a transfer wallet, send amount to tips"""
def __init__(self, amount, pages, wallets, outputs, peremption_date):
self.output = outputs
def __init__(self, amount, pages, wallets, peremption_date):
self.wallets = wallets
self.pages = pages
self.Tips_Amount = amount
......
......@@ -23,6 +23,7 @@ def check_date(given_date):
break
return datetime.date(int(infos_date[2]), int(infos_date[1]), int(infos_date[0]))
class CheckConfig():
def __init__(self):
......
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