Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Commit

Permalink
integrate bruienne, hfike fixes
Browse files Browse the repository at this point in the history
More robust checking of lack of description, version - I had been
overlooking that a .get returning None from a dict would make building
the list of dicts fail. Should address current issues 😅
  • Loading branch information
arubdesu committed Mar 25, 2015
1 parent db397ad commit 770bd23
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions moscargo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from flask import render_template, redirect#jsonify
app = Flask(__name__)
from operator import itemgetter
from distutils.version import LooseVersion
import plistlib
import os

Expand All @@ -23,25 +24,38 @@ def key_not_seen(unfiltered_prod_dict):
return key_not_seen

try:
products = plistlib.readPlist(repo_base + 'catalogs/all')
products = plistlib.readPlist(os.path.join(repo_base, 'catalogs/all'))
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 = (repo_base + 'icons/' + prod_dict.get('name') + '.png')
this_prod_dict = {
'Name': prod_dict.get('display_name'),
'distinct_name': prod_dict.get('name'),
'description': (prod_dict.get('description'))[:130] + '...',
'link': ('static/pkgs/' + prod_dict.get('installer_item_location')).replace(' ', '%20'),
'version': prod_dict.get('version'),
}
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'] = 'static/icons/' + prod_dict.get('icon_name').replace(' ', '%20')
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'] = 'static/icons/' + (prod_dict.get('name') + '.png').replace(' ', '%20')
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)
Expand Down

0 comments on commit 770bd23

Please sign in to comment.