Skip to content

Commit

Permalink
1.1.1 redux
Browse files Browse the repository at this point in the history
  • Loading branch information
Graham R Pugh committed Jul 1, 2020
1 parent 353a20e commit b341356
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 31 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -14,7 +14,7 @@ Changes since last release.

## [1.1.1] - 2020-07-01

This is a bugfix release which addresses #176, #182 and #183, improving the language of the output when there is either no `JSS_REPO` set, no `pkg_path`, or `STOP_IF_NO_JSS_UPLOAD` is not set to `False`. There are also a million minor python format changes due to the use of `black` when saving the file.
This is a bugfix release which addresses #176, #182 and #183, improving the language of the output when there is either no `JSS_REPO` set, no `pkg_path`, or `STOP_IF_NO_JSS_UPLOAD` is not set to `False`. I have also removed some verbosity when running in `-v` or zero verbosity mode. Run with at least `-vv` to retain all previous output. There are also a million minor python format changes due to the use of `black` when saving the file.

The package installer incorporates a [fix in python-jss](https://github.com/jssimporter/python-jss/pull/98).

Expand Down
95 changes: 65 additions & 30 deletions JSSImporter.py
Expand Up @@ -371,22 +371,25 @@ def wait_for_id(self, obj_cls, obj_name):
self.output(
"{} ID '{}' verified on server".format(
obj_cls.__name__, object.id
)
),
verbose_level=2,
)
self.upload_needed = True
return object
else:
self.output(
"Waiting to get {} ID from server (reported: {})...".format(
obj_cls.__name__, object.id
)
),
verbose_level=2,
)
time.sleep(10)
except jss.GetError:
self.output(
"Waiting to get {} ID from server (none reported)...".format(
obj_cls.__name__
)
),
verbose_level=2,
)
time.sleep(10)

Expand All @@ -401,7 +404,8 @@ def handle_category(self, category_type, category_name=None):
category_name = category.name
self.output(
"Category, type '{}', name '{}', already exists on the Jamf Pro server, "
"moving on...".format(category_type, category_name)
"moving on...".format(category_type, category_name),
verbose_level=2,
)
except jss.GetError:
# Category doesn't exist
Expand Down Expand Up @@ -444,13 +448,15 @@ def handle_package(self):
if self.repo_type() is None:
self.output(
"No repos are setup so JSSImporter cannot upload packages. "
"If this is a mistake, check your JSS_REPOS array."
"If this is a mistake, check your JSS_REPOS array.",
verbose_level=2,
)
return
if pkg_path == "":
self.output(
"No 'pkg_path' key has been passed to the JSSImporter processor. "
"Therefore, no package will be uploaded. "
"Therefore, no package will be uploaded. ",
verbose_level=2,
)
return

Expand All @@ -473,9 +479,9 @@ def handle_package(self):
# now check if the package object already exists
try:
package = self.jss.Package(self.pkg_name)
self.output("Package object already exists on the Jamf Pro server.")
self.output(
"Package object already exists on the Jamf Pro server. "
"(ID: {})".format(package.id)
"Package ID: {}".format(package.id), verbose_level=2,
)
pkg_update = self.env["jss_changed_objects"]["jss_package_updated"]
# for cloud DPs we must assume that the package object means there is an associated package
Expand Down Expand Up @@ -538,17 +544,18 @@ def handle_package(self):
self.upload_needed = True

# only update the package object if an uploand ad was carried out
if self.env["STOP_IF_NO_JSS_UPLOAD"] is True and not self.upload_needed:
self.stop_if_no_upload = "{}".format(self.env.get("STOP_IF_NO_JSS_UPLOAD"))
if self.stop_if_no_upload != "False" and not self.upload_needed:
self.output(
"Not overwriting policy as upload requirement is determined as False, "
"and STOP_IF_NO_JSS_UPLOAD is set to True."
"and STOP_IF_NO_JSS_UPLOAD is not set to False."
)
self.env["stop_processing_recipe"] = True
return
elif not self.upload_needed:
self.output(
"Overwriting policy although upload requirement is determined as False, "
"because STOP_IF_NO_JSS_UPLOAD is not set to True."
"because STOP_IF_NO_JSS_UPLOAD is set to False."
)

# now update the package object
Expand Down Expand Up @@ -629,7 +636,10 @@ def handle_groups(self, groups):
computer_groups = []
if groups:
for group in groups:
# self.output("Computer Group to process: {}".format(group["name"]))
self.output(
"Computer Group to process: {}".format(group["name"]),
verbose_level=3,
)
if self.validate_input_var(group):
is_smart = group.get("smart", False)
if is_smart:
Expand All @@ -647,7 +657,10 @@ def handle_scripts(self):
results = []
if scripts:
for script in scripts:
self.output("Looking for Script file {}...".format(script["name"]))
self.output(
"Looking for Script file {}...".format(script["name"]),
verbose_level=2,
)
script_file = self.find_file_in_search_path(script["name"])
try:
with open(script_file) as script_handle:
Expand Down Expand Up @@ -680,7 +693,9 @@ def handle_policy(self):
update_env="jss_policy_updated",
added_env="jss_policy_added",
)
# self.output("PolicyPackage object: {}".format(policy.id))
self.output(
"Policy object: {}".format(policy.id), verbose_level=3,
)
else:
self.output("Policy creation not desired, moving on...")
policy = None
Expand All @@ -705,7 +720,9 @@ def handle_icon(self):
if self.env.get("self_service_icon") and self.policy is not None:
# Search through search-paths for icon file.
self.output(
"Looking for Icon file {}...".format(self.env["self_service_icon"])
"Looking for Icon file {}...".format(
self.env["self_service_icon"], verbose_level=2,
)
)
icon_path = self.find_file_in_search_path(self.env["self_service_icon"])
icon_filename = os.path.basename(icon_path)
Expand All @@ -717,7 +734,10 @@ def handle_icon(self):
"self_service/self_service_icon/filename"
)
if not policy_filename == icon_filename:
self.output("Icon name in existing policy: {}".format(policy_filename))
self.output(
"Icon name in existing policy: {}".format(policy_filename),
verbose_level=2,
)
icon = jss.FileUpload(
self.jss, "policies", "id", self.policy.id, icon_path
)
Expand Down Expand Up @@ -968,7 +988,7 @@ def get_templated_object(self, obj_cls, template_path):
"""
self.output(
"Looking for {} template file {}...".format(
obj_cls.__name__, os.path.basename(template_path)
obj_cls.__name__, os.path.basename(template_path), verbose_level=2,
)
)
final_template_path = self.find_file_in_search_path(template_path)
Expand Down Expand Up @@ -1043,7 +1063,9 @@ def find_file_in_search_path(self, path):
tested.append(test_parent_folder_path)

if final_path:
self.output("Found file: {}".format(final_path))
self.output(
"Found file: {}".format(final_path), verbose_level=2,
)
break

if not final_path:
Expand Down Expand Up @@ -1113,13 +1135,13 @@ def add_or_update_smart_group(self, group):
try:
computer_group = self.jss.ComputerGroup(group["name"])
self.output(
"ComputerGroup '%s' already exists "
"Computer Group '%s' already exists "
"and set not to update." % computer_group.name
)
return computer_group
except jss.GetError:
self.output(
"ComputerGroup '%s' does not already exist. "
"Computer Group '%s' does not already exist. "
"Creating from template." % group["name"]
)

Expand All @@ -1137,12 +1159,14 @@ def add_or_update_static_group(self, group):
try:
computer_group = self.jss.ComputerGroup(group["name"])
self.output(
"Computer Group: {} already exists.".format(computer_group.name)
"Static Computer Group: {} already exists.".format(computer_group.name)
)
except jss.GetError:
computer_group = jss.ComputerGroup(self.jss, group["name"])
computer_group.save()
self.output("Computer Group '{}' created.".format(computer_group.name))
self.output(
"Static Computer Group '{}' created.".format(computer_group.name)
)
self.env["jss_changed_objects"]["jss_group_added"].append(
computer_group.name
)
Expand Down Expand Up @@ -1175,7 +1199,7 @@ def add_package_to_policy(self, policy_template):
if self.package is not None:
self.ensure_xml_structure(policy_template, "package_configuration/packages")
action_type = self.env["policy_action_type"]
self.output("Setting policy to '%s' package." % action_type)
self.output("Setting policy to '{}' package.".format(action_type))
policy_template.add_package(self.package, action_type=action_type)

def add_icon_to_policy(self, policy_template, icon_xml):
Expand Down Expand Up @@ -1280,7 +1304,9 @@ def main(self):
"""Main processor code."""
# Ensure we have the right version of python-jss
python_jss_version = StrictVersion(PYTHON_JSS_VERSION)
self.output("python-jss version: {}.".format(python_jss_version))
self.output(
"python-jss version: {}.".format(python_jss_version), verbose_level=2,
)
if python_jss_version < REQUIRED_PYTHON_JSS_VERSION:
self.output(
"python-jss version is too old. Please update to version: {}.".format(
Expand All @@ -1289,14 +1315,18 @@ def main(self):
)
raise ProcessorError

self.output("JSSImporter version: {}.".format(__version__))
self.output(
"JSSImporter version: {}.".format(__version__), verbose_level=2,
)

# clear any pre-existing summary result
if "jss_importer_summary_result" in self.env:
del self.env["jss_importer_summary_result"]

self.create_jss()
self.output("Jamf Pro version: '{}'".format(self.jss.version()))
self.output(
"Jamf Pro version: '{}'".format(self.jss.version()), verbose_level=2,
)

self.pkg_name = os.path.basename(self.env["pkg_path"])
self.prod_name = self.env["prod_name"]
Expand All @@ -1306,7 +1336,8 @@ def main(self):
"Warning: No `version` was added to the AutoPkg env up to "
"this point. JSSImporter is defaulting to version {}!".format(
self.version
)
),
verbose_level=2,
)

# Build and init jss_changed_objects
Expand All @@ -1319,7 +1350,9 @@ def main(self):
if len(self.jss.distribution_points) == 0:
self.output("Warning: No distribution points configured!")
for dp in self.jss.distribution_points:
self.output("Checking if DP already mounted...")
self.output(
"Checking if DP already mounted...", verbose_level=2,
)
dp.was_mounted = hasattr(dp, "is_mounted") and dp.is_mounted()
# Don't bother mounting the DPs if there's no package.
if self.env["pkg_path"]:
Expand All @@ -1328,11 +1361,13 @@ def main(self):
self.package = self.handle_package()

# stop if no package was uploaded and STOP_IF_NO_JSS_UPLOAD is True
if self.env["STOP_IF_NO_JSS_UPLOAD"] is True and not self.upload_needed:
if self.stop_if_no_upload and not self.upload_needed:
# Done with DPs, unmount them.
for dp in self.jss.distribution_points:
if not dp.was_mounted:
self.output("Unmounting DP...")
self.output(
"Unmounting DP...", verbose_level=2,
)
self.jss.distribution_points.umount()
self.summarize()
return
Expand Down

0 comments on commit b341356

Please sign in to comment.