-
Notifications
You must be signed in to change notification settings - Fork 0
/
controllers.py
80 lines (61 loc) · 2.5 KB
/
controllers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from operator import inv
import os
import json
import pandas
import yaml
df = pandas.read_excel('C:/Users/hadis/source/repos/peppolgenerator/files/inv 1/variables.xlsx', index_col=0,
keep_default_na=False)
dfHead = list(df.columns)
def getdir():
FILES_DIR = getroot()
invoiceFolder = {}
for root, dirs, files in os.walk(FILES_DIR):
if root == FILES_DIR:
for invDir in dirs:
key = os.path.join(root, invDir)
invoiceFolder[key] = {}
elif root in invoiceFolder:
invoiceFolder[root]['files'] = files
invoiceFolder[root]['dirs'] = dirs
# Check if settings exist
if 'settings.yaml' in invoiceFolder[root]['files']:
with open(os.path.join(root, 'settings.yaml'), 'r', encoding='utf-8') as file:
settings = yaml.safe_load(file)
invoiceFolder[root]['settings'] = settings
if settings['XML_VARIABLES_FILE'] != None:
df = pandas.read_excel(os.path.join(root, settings['XML_VARIABLES_FILE']), index_col=0,
keep_default_na=False)
invoiceFolder[root]['localizations'] = list(df.columns)
else:
invoiceFolder[root]['localizations'] = []
else:
invoiceFolder[root]['settings'] = {}
return invoiceFolder
def setroot(path):
with open('data.json', 'r', encoding='utf-8') as jsonFile:
data = json.load(jsonFile)
data['rootdir'] = path
with open('data.json', 'w', encoding='utf-8') as jsonFile:
json.dump(data, jsonFile)
def getroot():
with open('data.json', 'r', encoding='utf-8') as jsonFile:
data = json.load(jsonFile)
if data != None:
return(data['rootdir'])
def setsettings(subdir, xmlTemplate, xmlVariables, wordTemplate, wordVariables, localizations):
settings = {
'XML_TEMPLATE_FILE': xmlTemplate,
'XML_VARIABLES_FILE': xmlVariables,
'WORD_TEMPLATE_FILE': wordTemplate,
'WORD_VARIABLES_FILE': wordVariables,
'INCLUDED_LOCALIZATONS': localizations
}
with open(os.path.join(subdir, 'settings.yaml'), 'w', encoding='utf-8') as yamlfile:
yaml.dump(settings, yamlfile)
return
##
# Test
##
def loadsettings(subdir):
with open(os.path.join(subdir, 'settings.yaml'), 'r', encoding='utf-8') as f:
subdirSettings = yaml.safe_load(f)