-
Notifications
You must be signed in to change notification settings - Fork 0
/
iccn-pack.py
46 lines (40 loc) · 1.46 KB
/
iccn-pack.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
import os
import json
import re
originurl = 'https://gitlab.com/zhekasmirnov/horizon-cloud-config/raw/master/'
afterurl = 'https://cdn.jsdelivr.net/gh/WvTStudio/horizon-cloud-config@master/'
packjsonfile = open(os.path.join('tmp', 'packs.json'))
origin = packjsonfile.read()
packjsonfile.close()
origin = re.sub(originurl, afterurl, origin)
# print(origin)
origin = json.loads(origin)
import sys,os
def split(fromfile,todir,chunksize):
partnum = 0
partmap = {}
inputfile = open(fromfile,'rb')#open the fromfile
while True:
chunk = inputfile.read(chunksize)
if not chunk: #check the chunk is empty
break
partnum += 1
filename = os.path.join(todir,('part%04d'%partnum))
partmap['part%04d'%partnum]=afterurl+todir+('/part%04d'%partnum)
fileobj = open(filename,'wb')#make partfile
fileobj.write(chunk) #write data into partfile
fileobj.close()
return partmap
packs = []
for i in origin['packs']:
print(i['uuid'])
filename = re.search('(?<=master/).+',i['package']).group()
filedir = re.search('(?<=master/).+?(?=/)',i['package']).group()
packjson = split(filename,filedir,1024*1024*10)
i['package'] = packjson
packs.append(i)
os.remove(filename)
origin['packs'] = packs
print(json.dumps(origin, sort_keys=True, indent=4))
packjsonfile = open(os.path.join('.', 'packs.json'),'w')
packjsonfile.write(json.dumps(origin, sort_keys=True, indent=4))