-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGMDCreator.py
More file actions
143 lines (110 loc) · 4.26 KB
/
Copy pathGMDCreator.py
File metadata and controls
143 lines (110 loc) · 4.26 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed May 3 19:25:34 2017
@author: christopher
"""
from importlib.util import find_spec
from os import makedirs as omakedirs
from os import getcwd
from os.path import join as pjoin
from os.path import exists as pexists
from os.path import basename as pbasename
from pip import main as pip_main
from gmdata_managment import getMetaDataPath
from gmdata_managment import createMetaDataFile, modifyMetaData
from gmdata_managment import getTutMetaInfo
from gmdata_managment import createTutoriumList
from gmdata_managment import createExternalStudentsList
from gmdata_managment import createImportFile
from gmdata_managment import createExportFile
from gmdata_managment import createStudentsList
def install (module):
spam_spec = find_spec(module)
found = spam_spec is not None
if not found:
pip_main(['install', module])
# create GlobalMetaData - Folder
#==============================================================================
def createGlobalMetaData(root = getcwd()):
globalMdataPath = pjoin(root, 'GlobalMetaData')
onChange = False
if not pexists(globalMdataPath):
print('GlobalMetaData', globalMdataPath)
omakedirs(globalMdataPath)
else:
print('[WARNING] GlobalMetaData folder already exists!')
if input('Wanna override and recreate files (step by step)? (Y|n)') != 'Y':
print('Execution terminated...')
return globalMdataPath
tutLinks = None
#MetaData.txt
#--------------------------------------------------------------------------
metaDataFile = getMetaDataPath(globalMdataPath)
if pexists(metaDataFile):
inp = input('MetaData are already existent: \n\
o|O Override \n\
m|M Modify \n\
.* Skip\n\nChoose option: ')
if inp.lower() == 'o':
tutLinks = createMetaDataFile(globalMdataPath)
onChange = True
elif inp.lower() == 'm':
tutLinks = modifyMetaData(globalMdataPath)
onChange = True
else:
print('MetaData.txt will not be changed.')
else:
print('Create %s' % pbasename(metaDataFile))
tutLinks = createMetaDataFile(globalMdataPath)
if tutLinks == None:
tutLinks = getTutMetaInfo(globalMdataPath)
#<ID>_MuesliData.txt
#--------------------------------------------------------------------------
for tut in tutLinks:
tutpath = pjoin(globalMdataPath, tut['ID'] + '_MuesliData.txt')
if not pexists(tutpath):
createTutoriumList(tutpath, tut)
else:
if input('Do u want to sync and override data for (%s %s)? (Y|n)' % (tut['Day'], tut['Time'])) == 'Y':
print('Synced')
print(tutpath, tut)
createTutoriumList(tutpath, tut)
onChange = True
else:
print('Skipped')
studentsListPath = pjoin(globalMdataPath, 'StudentList.txt')
#External
createExternalStudentsList(globalMdataPath)
# Pre-Init
if not pexists(studentsListPath):
createStudentsList(globalMdataPath, ignore = True)
#Imported/Exported
print('=' * 30)
importPath = pjoin(globalMdataPath, 'Imported.txt')
print('=' * 30)
exportPath = pjoin(globalMdataPath, 'Exported.txt')
cif = createImportFile(importPath)
cef = createExportFile(exportPath)
onChange = cif or cef or onChange
if onChange:
print('Some files have been updated - Updating StudentsList')
if not pexists(studentsListPath) or onChange:
createStudentsList(globalMdataPath)
else:
print('There were no changes on student data.')
if input('Do u want to update \'%s\' anyways? (Y|n)' % pbasename(studentsListPath)) == 'Y':
createStudentsList(globalMdataPath)
else:
print('Skipped')
print('GlobalMetaData created and ready to be used')
return globalMdataPath
#==============================================================================
if __name__ == '__main__':
install('bs4')
install('requests')
install('zipfile')
install('rarfile')
install('tarfile')
install('smtplib')
createGlobalMetaData()