Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
fix version checking using packaging module
Browse files Browse the repository at this point in the history
  • Loading branch information
Graham R Pugh committed Feb 13, 2020
1 parent 1fb935b commit 955dc81
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
*.pkg
*.DS_Store
local_tests/*
pkg/jss_helper/payload/*
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).


## [2.2.0b2] - 2020-02-13 - 2.2.0b2

### Changed

- Changed from distutils to packaging as `distutils.version.LooseVersion` was not working properly in python3.
- `packaging` module is not included in the AutoPkg python distribution so it is now bundled into the
jss_helper package.
- Fixed output if running `jss_helper` without any arguments.


## [2.2.0b1] - 2020-02-13 - 2.2.0b1

### Changed
Expand All @@ -10,7 +21,7 @@ All notable changes to this project will be documented in this file. This projec
* AutoPkg 2.0.2
* JSSImporter 1.1.0
* python-jss 2.1.0


## [2.1.0b2] - 2019-09-16 - 2.1.0b2

Expand Down
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ PKG_ROOT := $(CURDIR)/pkg/jss_helper/payload
PKG_BUILD := $(CURDIR)/pkg/jss_helper/build
PKG_VERSION := $(shell defaults read $(CURDIR)/pkg/jss_helper/build-info.plist version)

objects = $(PKG_ROOT)/usr/local/bin/jss_helper \
objects = $(PKG_ROOT)/Library/AutoPkg/JSSImporter/packaging \
$(PKG_ROOT)/usr/local/bin/jss_helper \
$(PKG_ROOT)/usr/local/bin/jss_helper_lib


Expand All @@ -16,6 +17,12 @@ $(PKG_BUILD)/jss_helper-$(PKG_VERSION).pkg: $(objects)
cd $(CURDIR)/pkg && $(MUNKIPKG) jss_helper


$(PKG_ROOT)/Library/AutoPkg/JSSImporter/packaging:
@echo "Installing packaging into JSSImporter support directory"
#pip install --install-option="--prefix=$(PKG_ROOT)/Library/AutoPkg/JSSImporter/packaging" --ignore-installed packaging
pip3 install --target "$(PKG_ROOT)/Library/AutoPkg/JSSImporter" --ignore-installed packaging


$(PKG_ROOT)/usr/local/bin/jss_helper:
@echo "Copying jss_helper into /usr/local/bin"
mkdir -p "$(PKG_ROOT)/usr/local/bin"
Expand Down
9 changes: 7 additions & 2 deletions jss_helper
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ sys.path.insert(0, '/Library/AutoPkg/JSSImporter')
import jss


__version__ = "2.2.0b1"
__version__ = "2.2.0b2"


def main():
Expand All @@ -103,7 +103,12 @@ def main():
args = parser.parse_args()

try:
args.func(args)
func = args.func
except AttributeError:
parser.error("too few arguments")

try:
func(args)
except KeyboardInterrupt:
# User wishes to bail.
sys.exit(1)
Expand Down
2 changes: 1 addition & 1 deletion jss_helper_lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
from . import tools


__version__ = "2.2.0b1"
__version__ = "2.2.0b2"
12 changes: 8 additions & 4 deletions jss_helper_lib/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@

from __future__ import absolute_import
from __future__ import print_function
from distutils.version import StrictVersion, LooseVersion
from distutils.version import StrictVersion
from packaging.version import parse as LooseVersion
import fnmatch
from operator import itemgetter
import re
Expand Down Expand Up @@ -405,9 +406,12 @@ def get_updatable_policies(policies, packages):
for package in packages_installed:
pkg_name, pkg_version = get_package_info(package)
if pkg_name in multiples:
if LooseVersion(pkg_version) < max(multiples[pkg_name]):
updates_available.append(policy)
break
try:
if LooseVersion(pkg_version) < max(multiples[pkg_name]):
updates_available.append(policy)
break
except TypeError:
pass

# Make a new list of just names (rather than the full XML)
updates_available_names = [policy.findtext("general/name") for policy in
Expand Down
2 changes: 1 addition & 1 deletion pkg/jss_helper/build-info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
<key>suppress_bundle_relocation</key>
<true/>
<key>version</key>
<string>2.2.0b1</string>
<string>2.2.0b2</string>
</dict>
</plist>

0 comments on commit 955dc81

Please sign in to comment.