From 1e12e6a8bfc13b4ffb981f555990aa8ff0999da4 Mon Sep 17 00:00:00 2001 From: Allister Banks Date: Wed, 25 Mar 2015 15:38:47 -0400 Subject: [PATCH] Prepping v.2 tag satisfying contents of PR #4, integrating os.environ to allow runtime override of path to munki repo, mainly for easier docker integration. Thanks again @hfike! --- README.md | 4 ++-- moscargo.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1f9a6b5..482bbc4 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Moscargo is a [Munki(2)](https://www.munki.org/munki/) repo browser to aid in fi ![Screen Shot 2015-03-18 at 11.58.37 AM.png](https://raw.githubusercontent.com/arubdesu/Moscargo/master/static/readmeScreenshot.png) -It's written in flask, loosely wrapped in bootstrap, and inspired greatly by [Margarita](https://github.com/jessepeterson/margarita). It was thrown together by a novice ([me](http://resume.aru-b.com)) very quickly, so it may very well not work for you. However, feel free to file issues with the understanding that I may not be able to (or honestly be interested in) do(ing) much more work on this, since more full-fledged solutions like [Sal](http://salsoftware.com), [MunkiWebAdmin](https://github.com/munki/munkiwebadmin), [MunkiReport](https://github.com/munkireport/munkireport-php), and [MunkiServer](https://github.com/jnraine/munkiserver)(among others) are available and staffed by more capable devs. +It's written in flask, loosely wrapped in bootstrap, and inspired greatly by [Margarita](https://github.com/jessepeterson/margarita). It was thrown together by a novice ([me](http://resume.aru-b.com)) very quickly, so it may very well not work for you. Consider it alpha code at this point. However, feel free to file issues with the understanding that I may not be able to (or honestly be interested in) do(ing) much more work on this, since more full-fledged solutions like [Sal](http://salsoftware.com), [MunkiWebAdmin](https://github.com/munki/munkiwebadmin), [MunkiReport](https://github.com/munkireport/munkireport-php), and [MunkiServer](https://github.com/jnraine/munkiserver)(among others) are available and staffed by more capable devs. ###How it does what it does: A bootstrap html template gets filled in with info from a python script. That script checks the 'all' catalog(you can change it in the script if you'd like to limit it to a specific catalog), generates a list of dictionaries for each item it finds (except for nopkg or Apple Update Metadata pkginfos, since those wouldn't have download links). It caps each description to the length of a tweet, and performs a set of checks to be able to make smart choices about icons: @@ -15,7 +15,7 @@ A bootstrap html template gets filled in with info from a python script. That sc It then reverse-sorts this list of dict-per-catalog-entry by the version, creates a set to throw out duplicates (leaving the highest numerical version), and sorts again by name for ease of scrolling-lookup. (I could get fancier with bootstrap widgets and toolbars, but eff it, ship it. Maybe v.3) ## Installation -To install, first check out or otherwise grab this code. I'd recommend setting up a virtualenv (using ```easy_install pip``` and then use pip to install virtualenv) wherever you'd like on the same server running your munki repo, and install flask as per their instructions. (If you use git and or git fat to sync around your repo, setting up a new web serving instance anywhere just for this purpose may make sense, too.) In the moscargo.py file, fill in the variable for the full path to the munki repo, and override the 'all' catalog if you'd like. ```cd``` into the included static folder and make symlinks (real ones on the command line, e.g.: ```ln /Users/Shared/repo/icons ./icons```)pointing to your icons and packages folders. Optionally, modify the last line of moscargo.py as appropriate to meet your desired setup, if you want to limit to a specific IP for instance - see the flask docs for more info. +To install, first check out or otherwise grab this code. If running standalone, I'd recommend setting up a virtualenv (using ```easy_install pip``` and then use pip to install virtualenv) wherever you'd like on the same server running your munki repo, and install flask as per their instructions. (If you use git and or git fat to sync around your repo, setting up a new web serving instance anywhere just for this purpose may make sense, too.) In the moscargo.py file, fill in the variable for the full path to the munki repo, and override the 'all' catalog if you'd like. In the mos.wsgi file, change the path to wherever these tools are on your local filesystem. ```cd``` into the included static folder and make symlinks (real ones on the command line, e.g.: ```ln /Users/Shared/repo/icons ./icons```)pointing to your icons and packages folders. Optionally, modify the last line of moscargo.py as appropriate to meet your desired setup, e.g. if you want to limit to a specific IP - see the flask docs for more info. Test by first activating the virtualenv and running the moscargo.py file directly and navigate to http://localhost:5000. For better performance(you could be serving hundreds of megs on top of the regular munki repo load) and ease of 'prod' deployment, you may also want to use pip to install mod_wsgi, which is the simplest way I've found to get this running in Apache on a Mac with the included mos.wsgi script, it also leaves any pre-existing Apache config as-is. If all seems good, run the mod_wsgi-express script, preferably as a restricted service user and make sure that works as well, which would move it to port 8000 by default. (A launchd plist or other pleaserun method of init'ing the webservice is left as an exercise for you, see the Margarita and MunkiWebAdmin docs for some hints.) diff --git a/moscargo.py b/moscargo.py index 3e2e1b6..c3be8f4 100644 --- a/moscargo.py +++ b/moscargo.py @@ -1,5 +1,5 @@ from flask import Flask -from flask import render_template, redirect#jsonify +from flask import render_template, redirect app = Flask(__name__) from operator import itemgetter from distutils.version import LooseVersion @@ -7,8 +7,8 @@ import os #set this to the base of your munki repo: -repo_base = '/Users/Shared/repo/' -# ad override the catalog to parse below: +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 @@ -24,7 +24,7 @@ def key_not_seen(unfiltered_prod_dict): return key_not_seen try: - products = plistlib.readPlist(os.path.join(repo_base, 'catalogs/all')) + 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':