-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateudf.py
53 lines (53 loc) · 1.35 KB
/
generateudf.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
import json
import os
import sys
gfl = {}
e = {'data':{}}
def walk(ls,lst={}):
global gfl
for i in ls:
if os.path.isdir(i):
lst[i] = {'action':'+d'}
print("Entering Directory:",i)
os.chdir(i)
gfl[os.getcwd()] = 'd'
lst.update(walk(os.listdir()),)
print("Exiting Directory:",i)
os.chdir('../')
else:
print("Adding File:",i)
try:
gfl[os.getcwd()+'/'+i] = 'f'
lst['examples/'+os.path.basename(os.getcwd())+'/'+i] = {'action':'+','data':open(i,'r').read()}
print("File Added:",i)
except:
print("Adding File",i,"Failed")
return lst
print("Starting")
try:
print("Checking changelog")
file = open('changelog.clog','r')
c = json.loads(file.read())
for i in c:
if c[i] == 'f':
if os.path.isfile(i) == False:
print("File:'",i,"'does not exist")
e['data'][i.strip('/home/runner/Tinybook')] = {'action':'-'}
if c[i] == 'd':
if os.path.isdir(i) == False:
print("Folder:'",i,"'does not exist")
e['data'][i.strip('/home/runner/Tinybook')] = {'action':'-d'}
print("Changelog read!")
except Exception as e:
print("Error Reading Changelog",e)
os.chdir('examples')
t = walk(os.listdir())
e['data'].update(t)
os.chdir('../')
print("Generating udf")
json.dump(e,open('examples.udf','w+'))
print("Generating Changelog")
with open('changelog.clog','w+') as file:
file.write(json.dumps(gfl))
file.close()
print("Done")