mirror of
https://github.com/munki/munki.git
synced 2026-05-06 12:29:27 -05:00
e165e92104
************************************************************************************************************************************************************************************ 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: Fixed crashing issue for unmounting. iconutils: removed unused import Repo: Simplified plugins selection based on plugins option. Couldn’t reproduce the case where pkginfo failed to open in the textEditor. For me, the pkginfo always opened up in sublime (my pref setting for textedit or) Could you check to see if it is still happening with your repo? Thanks. ************************************************************************************************************************************************************************************ 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)
75 lines
2.7 KiB
Python
75 lines
2.7 KiB
Python
#!/usr/bin/python
|
|
# encoding: utf-8
|
|
#
|
|
# Copyright 2016 Centrify Corporation.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the 'License');
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# https://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an 'AS IS' BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
"""
|
|
Repo
|
|
Created by Centrify Corporation 2016-06-02.
|
|
Interface for accessing a repo.
|
|
"""
|
|
|
|
import re
|
|
import sys
|
|
import imp
|
|
import os
|
|
|
|
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"
|
|
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/plugins'
|
|
else:
|
|
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
|
|
plugin = 'FileRepo'
|
|
module = imp.load_source(plugin, munkilib_path + "/" + plugin + ".py")
|
|
import_class = getattr(module, plugin)
|
|
parent = import_class
|
|
|
|
class Repo(parent):
|
|
mounted = False
|
|
|
|
def available(self):
|
|
#if path does not exist, mount to local filesystem
|
|
if not self.exists():
|
|
retcode = self.mount()
|
|
if retcode == 0:
|
|
self.mounted = True
|
|
#if path still doesn't exist, then cannot find munki_repo
|
|
if not self.exists():
|
|
print >> sys.stderr, "repo is missing"
|
|
return False
|
|
#checks if all subdirectories are there
|
|
for subdir in ['catalogs', 'manifests', 'pkgs', 'pkgsinfo']:
|
|
if not self.exists(subdir):
|
|
print >> sys.stderr, "repo is missing %s" % subdir
|
|
return False
|
|
# if we get this far, the repo path looks OK
|
|
return True
|
|
|
|
return Repo(path, url)
|