This repository has been archived by the owner on Feb 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
moscargo.py
74 lines (67 loc) · 3.16 KB
/
moscargo.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from flask import Flask
from flask import render_template, redirect
app = Flask(__name__)
from operator import itemgetter
from distutils.version import LooseVersion
import plistlib
import os
#set this to the base of your munki repo:
repo_base = os.environ.get('MOSCARGO_REPO') or '/Users/Shared/repo/'
# override the catalog to parse below:
catalog_to_parse = 'all'
# yup, stolen whole-heartedly from http://stackoverflow.com/a/22878816/743638
def get_key_watcher():
keys_seen = set()
def key_not_seen(unfiltered_prod_dict):
key = unfiltered_prod_dict['distinct_name']
if key in keys_seen:
return False # key is not new
else:
keys_seen.add(key)
return True # key seen for the first time
return key_not_seen
try:
products = plistlib.readPlist(os.path.join(repo_base, 'catalogs', catalog_to_parse))
prodlist = []
for prod_dict in products:
if not prod_dict.get('installer_type') == 'apple_update_metadata':
if not prod_dict.get('installer_type') == 'nopkg':
joined_path = os.path.join(repo_base,'icons', prod_dict.get('name')) + '.png'
this_prod_dict = {}
try_keys = [('Name', 'display_name'), ('distinct_name', 'name')]
for item in try_keys:
try:
this_prod_dict[item[0]] = prod_dict.get(item[1])
except Exception:
this_prod_dict[item[0]] = 'No %s found' % item[0]
try:
this_prod_dict['version'] = LooseVersion(prod_dict.get('version'))
except Exception:
this_prod_dict['description'] = 'No description found'
try:
this_prod_dict['description'] = (prod_dict.get('description'))[:130] + '...'
except Exception:
this_prod_dict['description'] = 'No description found'
try:
this_prod_dict['link'] = (os.path.join('static/pkgs', prod_dict.get('installer_item_location'))).replace(' ', '%20')
except Exception:
this_prod_dict['link'] = 'No link!'
if prod_dict.get('installer_type') == 'profile':
this_prod_dict['icon_url'] = 'static/mobileconfig.png'
elif prod_dict.get('icon_name'):
this_prod_dict['icon_url'] = (os.path.join('static/icons/', prod_dict.get('icon_name'))).replace(' ', '%20')
elif os.path.exists(joined_path):
this_prod_dict['icon_url'] = (os.path.join('static/icons', prod_dict.get('name') + '.png')).replace(' ', '%20')
else:
this_prod_dict['icon_url'] = 'static/package.png'
prodlist.append(this_prod_dict)
listbyvers = sorted(prodlist, key=itemgetter('version'), reverse=True)
filtered = filter(get_key_watcher(), listbyvers)
sprodlist = sorted(filtered, key=itemgetter('Name'))
except Exception, e:
print e
@app.route('/')
def index():
return render_template('moscargo.html', example_prods=sprodlist)
if __name__ == '__main__':
app.run(host='0.0.0.0')