From 0cb4636cf3be82a0631c5dc3f1e933789f47f2b3 Mon Sep 17 00:00:00 2001 From: Greg Neagle Date: Wed, 14 Dec 2016 10:16:09 -0800 Subject: [PATCH] Add initial osutils module; update authrestart --- code/client/munkilib/munkicommon/__init__.py | 20 +------- .../munkilib/munkicommon/authrestart.py | 2 +- code/client/munkilib/munkicommon/osutils.py | 49 +++++++++++++++++++ 3 files changed, 51 insertions(+), 20 deletions(-) create mode 100755 code/client/munkilib/munkicommon/osutils.py diff --git a/code/client/munkilib/munkicommon/__init__.py b/code/client/munkilib/munkicommon/__init__.py index 1878320e..f3a93880 100755 --- a/code/client/munkilib/munkicommon/__init__.py +++ b/code/client/munkilib/munkicommon/__init__.py @@ -54,6 +54,7 @@ from .. import FoundationPlist from .authrestart import * from .dmgutils import * from .prefs import * +from .osutils import * from .output import * # pylint: enable=unused-wildcard-import @@ -126,22 +127,6 @@ class memoize(dict): return result -def getOsVersion(only_major_minor=True, as_tuple=False): - """Returns an OS version. - - Args: - only_major_minor: Boolean. If True, only include major/minor versions. - as_tuple: Boolean. If True, return a tuple of ints, otherwise a string. - """ - os_version_tuple = platform.mac_ver()[0].split('.') - if only_major_minor: - os_version_tuple = os_version_tuple[0:2] - if as_tuple: - return tuple(map(int, os_version_tuple)) - else: - return '.'.join(os_version_tuple) - - def set_file_nonblock(f, non_blocking=True): """Set non-blocking flag on a file object. @@ -302,9 +287,6 @@ def saveappdata(): 'Unable to save inventory report: %s' % err) - - - # misc functions diff --git a/code/client/munkilib/munkicommon/authrestart.py b/code/client/munkilib/munkicommon/authrestart.py index 6146c639..1a69a92f 100755 --- a/code/client/munkilib/munkicommon/authrestart.py +++ b/code/client/munkilib/munkicommon/authrestart.py @@ -25,7 +25,7 @@ Functions supporting FileVault authrestart. import subprocess -from . import getOsVersion +from .osutils import getOsVersion from .output import display_debug1, display_error, display_warning, log from .prefs import pref from .. import FoundationPlist diff --git a/code/client/munkilib/munkicommon/osutils.py b/code/client/munkilib/munkicommon/osutils.py new file mode 100755 index 00000000..d6fc1c52 --- /dev/null +++ b/code/client/munkilib/munkicommon/osutils.py @@ -0,0 +1,49 @@ +#!/usr/bin/python +# encoding: utf-8 +# +# Copyright 2009-2016 Greg Neagle. +# +# 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. +""" +osutils + +Created by Greg Neagle on 2016-12-13. + +Common functions and classes used by the munki tools. +""" + + +def getOsVersion(only_major_minor=True, as_tuple=False): + """Returns an OS version. + + Args: + only_major_minor: Boolean. If True, only include major/minor versions. + as_tuple: Boolean. If True, return a tuple of ints, otherwise a string. + """ + os_version_tuple = platform.mac_ver()[0].split('.') + if only_major_minor: + os_version_tuple = os_version_tuple[0:2] + if as_tuple: + return tuple(map(int, os_version_tuple)) + else: + return '.'.join(os_version_tuple) + + +def main(): + """Placeholder""" + print 'This is a library of support tools for the Munki Suite.' + + +if __name__ == '__main__': + main() +