-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrebuild_filelist.py
50 lines (40 loc) · 1.73 KB
/
rebuild_filelist.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
import sys
import os.path
import subprocess
from app.models import Mod, ModRelease, ModFile, UploadedFile
for mid in sys.argv[1:]:
print(mid)
mod = Mod.objects(mid=mid).first()
#for mod in Mod.objects:
for rel in ModRelease.objects(mod=mod):
if rel.rebuilt_filelist or rel.version != "4.5.1":
continue
print('Processing %s %s...' % (mod.title, rel.version))
try:
pkgs = len(rel.packages)
for i, pkg in enumerate(rel.packages):
print('[%3d/%3d]: %s' % (i, pkgs, pkg.name))
ar = pkg.files[0]
arfile = UploadedFile.objects(checksum=ar.checksum).first()
os.mkdir('tmp22')
subprocess.check_call(['7z', 'x', '-otmp22', os.path.join('../uploads', arfile.filename)])
print('Hashing...')
cks = subprocess.check_output(['find', '-type', 'f', '-exec', 'sha256sum', '{}', ';'], cwd='tmp22').decode('utf8')
print('Cleanup...')
subprocess.check_call(['rm', '-rf', 'tmp22'])
pkg.filelist = []
for item in cks.splitlines():
ck, name = item.split(' ', 1)
name = name.strip()
pkg.filelist.append(ModFile(
filename=name,
archive=ar.filename,
orig_name=name,
checksum=('sha256', ck)
))
rel.rebuilt_filelist = True
rel.save()
except Exception as ex:
print(ex)
if os.path.isdir('tmp22'):
subprocess.check_call(['rm', '-rf', 'tmp22'])