forked from ngld/fsnebula
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_repo.py
36 lines (28 loc) · 966 Bytes
/
gen_repo.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
import os.path
import json
from app import app
from app.models import Mod
from app.controllers.mod import render_mod_list
update_required = os.path.join(app.config['FILE_STORAGE'], 'repo_needs_update')
repo_path = os.path.join(app.config['FILE_STORAGE'], 'public', 'repo.json')
lock_path = repo_path + '.lock'
if os.path.isfile(lock_path):
print('Update already in progress!')
exit(0)
# if we don't need an update then bail
if not os.path.isfile(update_required):
exit(0)
open(lock_path, 'w').close()
print('Updating repo...')
try:
exclude_fields = ('members', 'team', 'releases')
mods = Mod.objects.exclude(*exclude_fields).select_related(4)
repo = render_mod_list(mods)
with open(repo_path, 'w') as stream:
json.dump({'mods': repo}, stream) # , seperator=(',',':'))
except Exception:
print('Failed to update repository data!')
else:
print('Repo update complete.')
os.unlink(lock_path)
os.unlink(update_required)