Open homebysix opened 8 years ago
Well, that's super weird. It obviously is not supposed to work like that. I just ran it here and it is working fine.
I wonder if you either added some print statements in the get_updatable_policies
func or added a pdb.set_trace()
and looked at the values of some of the policies and packages involved if you could get an idea of what was going wrong. Based on what you provided, the Policy names do not meet the criteria for the automatic renaming, but that shouldn't matter. The package names look alright based on the one example you show, although Slack's version numbering leaves a bit to be desired.
Also, determining which packages are "the same" is a bit of a guess...
Specifically, if you look at the regex that splits the names into basename, version, and extension, it is assuming that a space, _, or - separate the version from the basename.
package_regex = (r"^(?P<basename>[\w\s\-]+)[\s\-_]"
r"(?P<version>[\d]+[\w.\-]*)"
r"(?P<extension>\.(pkg(\.zip)?|dmg))$")
This may need to be tweaked-for example, it treats a filename like Adobe_CC_2015_Lightroom_Install.pkg.zip like this:
>>> import re
>>> pkg = "Adobe_CC_2015_Lightroom_Install.pkg.zip"
>>> package_regex = (r"^(?P<basename>[\w\s\-]+)[\s\-_]"
... r"(?P<version>[\d]+[\w.\-]*)"
... r"(?P<extension>\.(pkg(\.zip)?|dmg))$")
>>> match = re.search(package_regex, pkg)
>>> match.groups()
('Adobe_CC', '2015_Lightroom_Install', '.pkg.zip', 'pkg.zip', '.zip')
So the "basename" is "Adobe_CC", the version is "2015_Lightroom_Install", and the extension is ".pkg.zip".
In this case it's because underscores are matched with the \w
character class for 1 or more times. So the first underscore matches the basename group, but that group looks for a whitespace, hyphen, or underscore followed by the next group which is a number. So the second hyphen falls into the non-group section, and the 2015 is what it think is the beginning of the version number.
LooseVersion then sorts these version numbers lexicographically, so the 2015 of one CC product matches any other. Lightroom ends up being less than Photoshop because L < P.
This is potentially something that could be solved with a more refined regex, better package naming, or both.
In YOUR case, I'm not sure based on the one example what is going on, but hopefully that will get you started.
Seems to be happening for packages which follow a stricter naming convention, too:
69: iTerm2
70: Malwarebytes Anti-Malware
71: Sequel Pro
72: SizeUp
73: Sketch
74: Slack
71
0: Sequel Pro-1.0.2.pkg (CURRENT) (DEFAULT)
I'll dig in with print
and pdb
to see what I can find.
I mean, the relevant part to my mind is that Sequel Pro-1.0.2.pkg
is not less than itself.
I've never seen this happen before with jss_helper, but I just set it up on a new Mac and it appears to think that ALL policies are eligible for promotion. Upon selecting a policy, the same package is offered as both (CURRENT) and (DEFAULT).