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:
Move FileRepo to munkilib/plugins/

Repo:
Change plugins location for FileRepo

munkiimport:
Change plugins location for FileRepo in configure.

************************************************************************************************************************************************************************************
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:
Ryan Yu
2017-01-24 14:48:17 -08:00
parent 483f82c6e3
commit 37cdff7f68
3 changed files with 15 additions and 6 deletions

View File

@@ -31,6 +31,7 @@ import subprocess
import sys
import time
import thread
import re
from ctypes.util import find_library
from optparse import OptionParser, BadOptionError, AmbiguousOptionError
@@ -810,13 +811,20 @@ def configure():
if key == 'plugin':
# 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')
plugin_path = os.path.join(plugin_path, 'munkilib/plugins')
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'):
plugin_path = '/usr/local/munki/munkilib/plugins'
hasPlugin = False
included_extensions = ['py']
plugins = [fn for fn in os.listdir(plugin_path)
if any(fn.endswith(ext) for ext in included_extensions)]
for plugin in plugins:
if 'FileRepo' not in plugin:
hasPlugin = True
if not os.path.isdir(plugin_path):
continue
if not os.listdir(plugin_path + '/plugins'):
if not hasPlugin:
continue
_prefs[key] = raw_input_with_default('%15s: ' % prompt, pref(key))

View File

@@ -30,6 +30,7 @@ def Open(path, url, plugin):
#looks for installtion path for munki
# first look for a plugin in the same dir as us in munkilib/plugins
munkilib_path = os.path.dirname(os.path.abspath(__file__))
munkilib_path = os.path.join(munkilib_path, 'plugins')
if not os.path.exists(munkilib_path):
# didn't find it; assume the default install path
command = "munkiimport"
@@ -38,9 +39,9 @@ def Open(path, url, plugin):
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'
munkilib_path = '/usr/local/munki/munkilib/plugins'
else:
munkilib_path = munkilib_path + '/munkilib'
munkilib_path = munkilib_path + '/munkilib/plugins'
#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.