mirror of
https://github.com/munki/munki.git
synced 2026-04-29 17:00:13 -05:00
Ammending last commit: https://github.com/munki/munki/pull/689/commits/77b7c95206daa9b28424e7124e7c690b7059d525
NEW CHANGES ************************************************************************************************************************************************************************************ https://github.com/munki/munki/pull/689#pullrequestreview-17297080 Commit based on comments by Greg Neagle on what to fix: munki#689 (master...ryanyu91:master) FileRepo: Changed FileRepo class definition to not be old-style class iconutils: Deleted pkg_path join since passing in file anyways munkiimport: for --configure option, changed for relative paths support from same directory Repo: Changed for relative paths support from same directory ************************************************************************************************************************************************************************************ https://github.com/munki/munki/pull/689#pullrequestreview-16492427 Commit based on comments by Greg Neagle on what to fix: munki#689 (master...ryanyu91:master) makecatalogs: removed debugging print statements manifestutil: check if repo is initialized before checking if it is mounted munkiimport: check if repo is initialized before checking if it is mounted for def add_icon_hash_to_pkginfo(pkginfo):, not opening file (icon_path) anymore WE_MOUNTED_THE_REPO is a repo attribute now, instead of a global variable FileRepo: removed duplicate/unused imports changed class to not be old-style updated glob method since pkgs was uninitialized made WE_MOUNTED_THE_REPO from global variable to FileRepo attribute variable initialized to False iconimporter: updated Repo call to include 3 parameters now.. changed old find_items_to_check calls to new call: findItemsToCheck Repo.py Added support for relative paths for importing plugins ************************************************************************************************************************************************************************************ Commit based on comments by Greg Neagle on what to fix: munki#685 (master...ryanyu91:master) IconImporter: Not opening DMG and then mounting it anymore, directly mounting like how it was before ManifestUtil: Checking if the repo is mounted as well as if we (munki) mounted it. Only this will display prompt whether we want to unmount or not FileRepo.py, Repo.py: not hardcoding import path anymore FileRepo - added 10.12 mounting fileshares code ************************************************************************************************************************************************************************************ Changed Files: code/client/munkiimport code/client/iconimporter code/client/makecatalogs code/client/manifestutil code/client/munkilib/iconutils.py Added Files: code/client/munkilib/FileRepo.py code/client/munkilib/Repo.py Reason For Changes: The purpose for this change is to enable plugins to munki that will allow writes to the munki repo to be customized. Changes: The methods used to write to the munki repo are the target of this modification. A plugin can create new methods for overwriting the default behavior of writing to the munki repo. The default behavior is retained in the absence of a plugin. This is accomplished via the introduction of FileRepo.py which continues to simply write changes to the munki repo. A plugin can be introduced to change this default behavior and allow munki repo writes to be redirected as desired by the plugin author. In order to accomplish this we have refactored all of the os.path.* methods, as well as the mount, unmount and available methods from the following tools: (iconimporter, makecatalogs, munkiimport, manifestutil, iconutils), and put them into a different python script to be used as a library or common code module. By default, these are now in the FileRepo.py module. The plugin can be used to overwrite this common code module. In addition to the above described changes, we also made the following changes to support this plugin concept: • Added the ability to add a plugin either via the command line or via munkiimport –configure • The code will look for custom plugins in the /usr/local/munki/munkilib/plugins/ directory • If plugin is found in the plugins directory, munkiimport --configure will give the option to type in the plugin name. For example, if you plugin is Foo.py, you could specify a plugin name of Foo in munkiimport --configure • If no plugin is found the FileRepo.py module will be used as the default common code module for writing to the munki repo • Add the ability to set the plugin via the --plugin option for the following tools (makecatalogs, munkiimport, manifestutil) Testing Tested with munkiimport on local filesystem/network shares/our own custom plugins Tested manifestutil on local filesystem/network Verified through regression testing, all features of munkiimport, makecatalogs, iconimporter, manifestutil from before all still work (local filesystem/network shares)
This commit is contained in:
@@ -808,9 +808,15 @@ def configure():
|
||||
('plugin', 'Use a plugin to write to a custom munki repository')
|
||||
]:
|
||||
if key == 'plugin':
|
||||
if not os.path.isdir("/usr/local/munki/munkilib/plugins"):
|
||||
# first look for a plugins folder in the same dir as us
|
||||
plugin_path = os.path.dirname(os.path.abspath(__file__))
|
||||
plugin_path = os.path.join(plugin_path, 'munkilib')
|
||||
if not os.path.exists(plugin_path):
|
||||
# didn't find it; assume the default install path
|
||||
plugin_path = '/usr/local/munki/munkilib'
|
||||
if not os.path.isdir(plugin_path + '/plugins'):
|
||||
continue
|
||||
if not os.listdir("/usr/local/munki/munkilib/plugins"):
|
||||
if not os.listdir(plugin_path + '/plugins'):
|
||||
continue
|
||||
_prefs[key] = raw_input_with_default('%15s: ' % prompt, pref(key))
|
||||
|
||||
|
||||
@@ -207,7 +207,7 @@ class FileRepo(object):
|
||||
#
|
||||
def open(self, path, mode='r'):
|
||||
'''Opens a file in the repo.'''
|
||||
class RepoFile:
|
||||
class RepoFile(object):
|
||||
def __init__(self, repo, repo_path, mode):
|
||||
self.repo = repo
|
||||
self.repo_path = repo_path
|
||||
|
||||
@@ -28,19 +28,27 @@ import os
|
||||
|
||||
def Open(path, url, plugin):
|
||||
#looks for installtion path for munki
|
||||
command = "munkiimport"
|
||||
commandPath = os.popen("/usr/bin/which %s" % command).read().strip()
|
||||
commandPath = os.path.split(commandPath)
|
||||
commandPath = commandPath[0]
|
||||
|
||||
# first look for a plugin in the same dir as us in munkilib/plugins
|
||||
munkilib_path = os.path.dirname(os.path.abspath(__file__))
|
||||
if not os.path.exists(munkilib_path):
|
||||
# didn't find it; assume the default install path
|
||||
command = "munkiimport"
|
||||
commandPath = os.popen("/usr/bin/which %s" % command).read().strip()
|
||||
commandPath = os.path.split(commandPath)
|
||||
munkilib_path = commandPath[0]
|
||||
#use default munki location if munki installation path is not found
|
||||
if munkilib_path == None or munkilib_path == "":
|
||||
munkilib_path = '/usr/local/munki/munkilib'
|
||||
else:
|
||||
munkilib_path = munkilib_path + '/munkilib'
|
||||
#looks for plugin in /usr/local/munki/munkilib/plugins (installation of munki)
|
||||
if plugin == None or plugin == "":
|
||||
#default is FileRepo if no plugin is specified in configuration or options.
|
||||
module = imp.load_source('FileRepo', commandPath+'/munkilib/FileRepo.py')
|
||||
module = imp.load_source('FileRepo', munkilib_path+'/FileRepo.py')
|
||||
import_class = getattr(module, "FileRepo")
|
||||
parent = import_class
|
||||
else:
|
||||
module = imp.load_source(plugin, commandPath + '/munkilib/plugins/' + plugin + ".py")
|
||||
module = imp.load_source(plugin, munkilib_path + '/plugins/' + plugin + ".py")
|
||||
import_class = getattr(module, plugin)
|
||||
parent = import_class
|
||||
|
||||
|
||||
@@ -232,7 +232,6 @@ def extractAppIconsFromBundlePkg(pkg_path, repo=None):
|
||||
|
||||
def getAppInfoPathsFromBOM(bomfile):
|
||||
'''Returns a list of paths to application Info.plists'''
|
||||
bomfile = os.path.join(pkg_path, u'Contents/Archive.bom')
|
||||
if os.path.exists(bomfile):
|
||||
cmd = ['/usr/bin/lsbom', '-s', bomfile]
|
||||
proc = subprocess.Popen(cmd, shell=False, bufsize=-1,
|
||||
|
||||
Reference in New Issue
Block a user