From 770bd2390bacd1a9445ea3aaa63a1fe6542cc90a Mon Sep 17 00:00:00 2001 From: Allister Banks Date: Wed, 25 Mar 2015 12:53:58 -0400 Subject: [PATCH] integrate bruienne, hfike fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 😅 --- moscargo.py | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/moscargo.py b/moscargo.py index 9282adb..3e2e1b6 100644 --- a/moscargo.py +++ b/moscargo.py @@ -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 @@ -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)