def findInstallerDisc(allowedBuilds=None, searchItems=None, systemType='MacOS X Client'): # -- validate input if systemType != 'MacOS X Client': raise NotImplementedError( 'At this time only MacOS X Client is supported') # allowedBuilds parsedAllowedBuilds = [] if hasattr(allowedBuilds, 'capitalize'): for thisItem in allowedBuilds.split(','): try: parsedAllowedBuilds.append( macOSXVersionParser.macOSXVersion(thisItem.strip())) except: raise ValueError( 'The allowedBuild item is not in the correct form: ' + thisItem) elif hasattr(allowedBuilds, '__iter__'): if len(allowedBuilds) == 0: raise ValueError('There were no allowBuilds provided') for thisValue in allowedBuilds: try: parsedAllowedBuilds.append( macOSXVersionParser.macOSXVersion(thisValue)) except: raise ValueError( 'The allowedBuild item is not in the correct form: ' + thisValue) elif allowedBuilds is not None: raise ValueError('Unable to understand the allowedBuild provided: ' + str(allowedBuilds)) # -- confirm or setup search folders if hasattr(searchItems, 'capitalize'): # the path to a single item searchItems = [searchItems] elif hasattr(searchItems, '__iter__'): # array of paths to search items, so nothing to do pass elif searchItems is None: searchItems = [] if allowedBuilds is not None: # non-legacy mode if not os.path.isdir( commonConfiguration.standardOSDiscFolder): # worry-warting raise ValueError( 'The legacy OS installer disc folder does not exist or was not a directory: ' + str(commonConfiguration.standardOSDiscFolder)) searchItems.append(commonConfiguration.standardOSDiscFolder) if not os.path.isdir( commonConfiguration.legacyOSDiscFolder): # worry-warting raise ValueError( 'The legacy OS installer disc folder does not exist or was not a directory: ' + str(commonConfiguration.legacyOSDiscFolder)) searchItems.append(commonConfiguration.legacyOSDiscFolder) else: raise ValueError('Did not understand the searchItems input: ' + str(searchItems)) # confirm that the item in the list are valid searchContainers = [] for thisItem in searchItems: thisContainer = None try: thisContainer = container(thisItem) except: raise ValueError('Unable to understand the search item: ' + str(thisItem)) if not thisContainer.isContainerType( 'folder'): # note: dmg's are "folders" raise ValueError( 'The search item "%s" was a %s, which is not useable .Must be dmg, volume, or folder' % (thisItem, thisContainer.getType())) searchContainers.append(thisContainer) # -- search through the folders # legacy search mode if allowedBuilds is None: for thisContainer in searchContainers: results = {'InstallerDisc': None, 'SupportingDiscs': []} innerSearchItems = None if thisContainer.isContainerType('dmg'): innerSearchItems = [thisContainer] else: innerSearchItems = [ os.path.join(thisContainer.getWorkingPath(), internalItem) for internalItem in os.listdir( thisContainer.getWorkingPath()) ] for thisItem in innerSearchItems: if hasattr(thisItem, 'isContainerType'): results['InstallerDisc'] = thisItem else: candidateConainter = None try: candidateConainter = container(thisItem) except Exception, e: #print e pass # we are in legacy mode, so fail if the name matches one of our preset names if os.path.basename(candidateConainter.getStoragePath( )) in legacyOSDiscNames or os.path.basename( thisItem) in legacyOSDiscNames: if candidateConainter is None or not candidateConainter.isContainerType( 'dmg' ): # note: volume would work here as well but needs InstaDMG support raise ValueError( 'In legacy mode the item "%s" was named like an installer disc, but was not a dmg' % thisItem) results['InstallerDisc'] = candidateConainter elif candidateConainter is not None and candidateConainter.isContainerType( 'dmg' ): # note: volume would work here as well but needs InstaDMG support results['SupportingDiscs'].append(candidateConainter) if results['InstallerDisc'] is not None: macOSInformation = results[ 'InstallerDisc'].getMacOSInformation() if macOSInformation is not None and macOSInformation[ 'macOSInstallerDisc'] is True: return results else: raise ValueError( 'In legacy mode the item "%s" was named like an installer disc, but was not' % results['InstallerDisc'].getWorkingPath())
continue macOSInformation = baseImageCandidate.getMacOSInformation() if macOSInformation['macOSInstallerDisc'] is not True: continue if macOSInformation['macOSType'] != 'MacOS X Client': continue # see if one of the patterns in allowedBuilds matches for thisAllowedBuild in parsedAllowedBuilds: if thisAllowedBuild == baseImageCandidate: if bestCandidateVersion is None: bestCandidate = baseImageCandidate bestCandidateVersion = macOSXVersionParser.macOSXVersion( macOSInformation['macOSBuild']) elif bestCandidateVersion > baseImageCandidate: bestCandidate = baseImageCandidate bestCandidateVersion = macOSXVersionParser.macOSXVersion( macOSInformation['macOSBuild']) if bestCandidate is not None: return {'InstallerDisc': bestCandidate, 'SupportingDiscs': []} folderString = "" stringItems = [] for thisItem in searchItems: if os.path.isdir(thisItem): stringItems.append(str(os.listdir(thisItem))) else: stringItems.append(thisItem)
def test_lessThanComparisons(self): # -- direct object comparisons # 10.5 to 10.5.8 self.comparisonTest( macOSXVersionParser.macOSXVersion("9A581"), macOSXVersionParser.macOSXVersion("9L30"), "<", True ) self.comparisonTest( macOSXVersionParser.macOSXVersion("9A581"), macOSXVersionParser.macOSXVersion("9L30"), ">", False ) self.comparisonTest( macOSXVersionParser.macOSXVersion("9A581"), macOSXVersionParser.macOSXVersion("9L30"), "=", False ) self.comparisonTest( macOSXVersionParser.macOSXVersion("9A581"), macOSXVersionParser.macOSXVersion("9L30"), "!=", True ) # 10.5 to 10.6 self.comparisonTest( macOSXVersionParser.macOSXVersion("9A581"), macOSXVersionParser.macOSXVersion("10A432"), "<", True ) self.comparisonTest( macOSXVersionParser.macOSXVersion("9A581"), macOSXVersionParser.macOSXVersion("10A432"), ">", False ) self.comparisonTest( macOSXVersionParser.macOSXVersion("9A581"), macOSXVersionParser.macOSXVersion("10A432"), "=", False ) self.comparisonTest( macOSXVersionParser.macOSXVersion("9A581"), macOSXVersionParser.macOSXVersion("10A432"), "!=", True ) # 10.6 to 10.6.4 self.comparisonTest( macOSXVersionParser.macOSXVersion("10A432"), macOSXVersionParser.macOSXVersion("10F569"), "<", True ) self.comparisonTest( macOSXVersionParser.macOSXVersion("10A432"), macOSXVersionParser.macOSXVersion("10F569"), ">", False ) self.comparisonTest( macOSXVersionParser.macOSXVersion("10A432"), macOSXVersionParser.macOSXVersion("10F569"), "=", False ) self.comparisonTest( macOSXVersionParser.macOSXVersion("10A432"), macOSXVersionParser.macOSXVersion("10F569"), "!=", True ) # 10.6.4 to 10.6.4 self.comparisonTest( macOSXVersionParser.macOSXVersion("10F569"), macOSXVersionParser.macOSXVersion("10F569"), "<", False ) self.comparisonTest( macOSXVersionParser.macOSXVersion("10F569"), macOSXVersionParser.macOSXVersion("10F569"), ">", False ) self.comparisonTest( macOSXVersionParser.macOSXVersion("10F569"), macOSXVersionParser.macOSXVersion("10F569"), "=", True ) self.comparisonTest( macOSXVersionParser.macOSXVersion("10F569"), macOSXVersionParser.macOSXVersion("10F569"), "!=", False ) # 10.6.4 to 10.6.4 with an extra self.comparisonTest( macOSXVersionParser.macOSXVersion("10F569"), macOSXVersionParser.macOSXVersion("10F569a"), "<", True ) self.comparisonTest( macOSXVersionParser.macOSXVersion("10F569"), macOSXVersionParser.macOSXVersion("10F569a"), ">", False ) self.comparisonTest( macOSXVersionParser.macOSXVersion("10F569"), macOSXVersionParser.macOSXVersion("10F569a"), "=", False ) self.comparisonTest( macOSXVersionParser.macOSXVersion("10F569"), macOSXVersionParser.macOSXVersion("10F569a"), "!=", True ) # 10.6.4 with an extra to 10.6.4 self.comparisonTest( macOSXVersionParser.macOSXVersion("10F569a"), macOSXVersionParser.macOSXVersion("10F569"), "<", False ) self.comparisonTest( macOSXVersionParser.macOSXVersion("10F569a"), macOSXVersionParser.macOSXVersion("10F569"), ">", True ) self.comparisonTest( macOSXVersionParser.macOSXVersion("10F569a"), macOSXVersionParser.macOSXVersion("10F569"), "=", False ) self.comparisonTest( macOSXVersionParser.macOSXVersion("10F569a"), macOSXVersionParser.macOSXVersion("10F569"), "!=", True ) # 10.6.4 with an extra to 10.6.4 with the same extra self.comparisonTest( macOSXVersionParser.macOSXVersion("10F569a"), macOSXVersionParser.macOSXVersion("10F569a"), "<", False ) self.comparisonTest( macOSXVersionParser.macOSXVersion("10F569a"), macOSXVersionParser.macOSXVersion("10F569a"), ">", False ) self.comparisonTest( macOSXVersionParser.macOSXVersion("10F569a"), macOSXVersionParser.macOSXVersion("10F569a"), "=", True ) self.comparisonTest( macOSXVersionParser.macOSXVersion("10F569a"), macOSXVersionParser.macOSXVersion("10F569a"), "!=", False ) # 10.6.4 with an extra to 10.6.4 with a different extra self.comparisonTest( macOSXVersionParser.macOSXVersion("10F569a"), macOSXVersionParser.macOSXVersion("10F569b"), "<", True ) self.comparisonTest( macOSXVersionParser.macOSXVersion("10F569a"), macOSXVersionParser.macOSXVersion("10F569b"), ">", False ) self.comparisonTest( macOSXVersionParser.macOSXVersion("10F569a"), macOSXVersionParser.macOSXVersion("10F569b"), "=", False ) self.comparisonTest( macOSXVersionParser.macOSXVersion("10F569a"), macOSXVersionParser.macOSXVersion("10F569b"), "!=", True ) # -- object with string comparisons # 10.5 to 10.5.8 self.comparisonTest(macOSXVersionParser.macOSXVersion("9A581"), "9L30", "<", True) # 10.5 to 10.6 self.comparisonTest(macOSXVersionParser.macOSXVersion("9A581"), "10A432", "<", True) # 10.6 to 10.6.4 self.comparisonTest(macOSXVersionParser.macOSXVersion("10A432"), "10F569", "<", True) # 10.6.4 to 10.6.4 self.comparisonTest(macOSXVersionParser.macOSXVersion("10F569"), "10F569", "<", False) # 10.6.4 to 10.6.4 with an extra self.comparisonTest(macOSXVersionParser.macOSXVersion("10F569"), "10F569a", "<", True) self.comparisonTest(macOSXVersionParser.macOSXVersion("10F569a"), "10F569", "<", False)
def findInstallerDisc(allowedBuilds=None, searchItems=None, systemType='MacOS X Client'): # -- validate input if systemType != 'MacOS X Client': raise NotImplementedError('At this time only MacOS X Client is supported') # allowedBuilds parsedAllowedBuilds = [] if hasattr(allowedBuilds, 'capitalize'): for thisItem in allowedBuilds.split(','): try: parsedAllowedBuilds.append(macOSXVersionParser.macOSXVersion(thisItem.strip())) except: raise ValueError('The allowedBuild item is not in the correct form: ' + thisItem) elif hasattr(allowedBuilds, '__iter__'): if len(allowedBuilds) == 0: raise ValueError('There were no allowBuilds provided') for thisValue in allowedBuilds: try: parsedAllowedBuilds.append(macOSXVersionParser.macOSXVersion(thisValue)) except: raise ValueError('The allowedBuild item is not in the correct form: ' + thisValue) elif allowedBuilds is not None: raise ValueError('Unable to understand the allowedBuild provided: ' + str(allowedBuilds)) # -- confirm or setup search folders if hasattr(searchItems, 'capitalize'): # the path to a single item searchItems = [searchItems] elif hasattr(searchItems, '__iter__'): # array of paths to search items, so nothing to do pass elif searchItems is None: searchItems = [] if allowedBuilds is not None: # non-legacy mode if not os.path.isdir(commonConfiguration.standardOSDiscFolder): # worry-warting raise ValueError('The legacy OS installer disc folder does not exist or was not a directory: ' + str(commonConfiguration.standardOSDiscFolder)) searchItems.append(commonConfiguration.standardOSDiscFolder) if not os.path.isdir(commonConfiguration.legacyOSDiscFolder): # worry-warting raise ValueError('The legacy OS installer disc folder does not exist or was not a directory: ' + str(commonConfiguration.legacyOSDiscFolder)) searchItems.append(commonConfiguration.legacyOSDiscFolder) else: raise ValueError('Did not understand the searchItems input: ' + str(searchItems)) # confirm that the item in the list are valid searchContainers = [] for thisItem in searchItems: thisContainer = None try: thisContainer = container(thisItem) except: raise ValueError('Unable to understand the search item: ' + str(thisItem)) if not thisContainer.isContainerType('folder'): # note: dmg's are "folders" raise ValueError('The search item "%s" was a %s, which is not useable .Must be dmg, volume, or folder' % (thisItem, thisContainer.getType())) searchContainers.append(thisContainer) # -- search through the folders # legacy search mode if allowedBuilds is None: for thisContainer in searchContainers: results = { 'InstallerDisc':None, 'SupportingDiscs':[] } innerSearchItems = None if thisContainer.isContainerType('dmg'): innerSearchItems = [thisContainer] else: innerSearchItems = [os.path.join(thisContainer.getWorkingPath(), internalItem) for internalItem in os.listdir(thisContainer.getWorkingPath())] for thisItem in innerSearchItems: if hasattr(thisItem, 'isContainerType'): results['InstallerDisc'] = thisItem else: candidateConainter = None try: candidateConainter = container(thisItem) except Exception, e: #print e pass # we are in legacy mode, so fail if the name matches one of our preset names if os.path.basename(candidateConainter.getStoragePath()) in legacyOSDiscNames or os.path.basename(thisItem) in legacyOSDiscNames: if candidateConainter is None or not candidateConainter.isContainerType('dmg'): # note: volume would work here as well but needs InstaDMG support raise ValueError('In legacy mode the item "%s" was named like an installer disc, but was not a dmg' % thisItem) results['InstallerDisc'] = candidateConainter elif candidateConainter is not None and candidateConainter.isContainerType('dmg'): # note: volume would work here as well but needs InstaDMG support results['SupportingDiscs'].append(candidateConainter) if results['InstallerDisc'] is not None: macOSInformation = results['InstallerDisc'].getMacOSInformation() if macOSInformation is not None and macOSInformation['macOSInstallerDisc'] is True: return results else: raise ValueError('In legacy mode the item "%s" was named like an installer disc, but was not' % results['InstallerDisc'].getWorkingPath())
continue macOSInformation = baseImageCandidate.getMacOSInformation() if macOSInformation['macOSInstallerDisc'] is not True: continue if macOSInformation['macOSType'] != 'MacOS X Client': continue # see if one of the patterns in allowedBuilds matches for thisAllowedBuild in parsedAllowedBuilds: if thisAllowedBuild == baseImageCandidate: if bestCandidateVersion is None: bestCandidate = baseImageCandidate bestCandidateVersion = macOSXVersionParser.macOSXVersion(macOSInformation['macOSBuild']) elif bestCandidateVersion > baseImageCandidate: bestCandidate = baseImageCandidate bestCandidateVersion = macOSXVersionParser.macOSXVersion(macOSInformation['macOSBuild']) if bestCandidate is not None: return { 'InstallerDisc':bestCandidate, 'SupportingDiscs':[] } folderString = "" stringItems = [] for thisItem in searchItems: if os.path.isdir(thisItem): stringItems.append(str(os.listdir(thisItem)))
def test_lessThanComparisons(self): # -- direct object comparisons # 10.5 to 10.5.8 self.comparisonTest(macOSXVersionParser.macOSXVersion('9A581'), macOSXVersionParser.macOSXVersion('9L30'), "<", True) self.comparisonTest(macOSXVersionParser.macOSXVersion('9A581'), macOSXVersionParser.macOSXVersion('9L30'), ">", False) self.comparisonTest(macOSXVersionParser.macOSXVersion('9A581'), macOSXVersionParser.macOSXVersion('9L30'), "=", False) self.comparisonTest(macOSXVersionParser.macOSXVersion('9A581'), macOSXVersionParser.macOSXVersion('9L30'), "!=", True) # 10.5 to 10.6 self.comparisonTest(macOSXVersionParser.macOSXVersion('9A581'), macOSXVersionParser.macOSXVersion('10A432'), "<", True) self.comparisonTest(macOSXVersionParser.macOSXVersion('9A581'), macOSXVersionParser.macOSXVersion('10A432'), ">", False) self.comparisonTest(macOSXVersionParser.macOSXVersion('9A581'), macOSXVersionParser.macOSXVersion('10A432'), "=", False) self.comparisonTest(macOSXVersionParser.macOSXVersion('9A581'), macOSXVersionParser.macOSXVersion('10A432'), "!=", True) # 10.6 to 10.6.4 self.comparisonTest(macOSXVersionParser.macOSXVersion('10A432'), macOSXVersionParser.macOSXVersion('10F569'), "<", True) self.comparisonTest(macOSXVersionParser.macOSXVersion('10A432'), macOSXVersionParser.macOSXVersion('10F569'), ">", False) self.comparisonTest(macOSXVersionParser.macOSXVersion('10A432'), macOSXVersionParser.macOSXVersion('10F569'), "=", False) self.comparisonTest(macOSXVersionParser.macOSXVersion('10A432'), macOSXVersionParser.macOSXVersion('10F569'), "!=", True) # 10.6.4 to 10.6.4 self.comparisonTest(macOSXVersionParser.macOSXVersion('10F569'), macOSXVersionParser.macOSXVersion('10F569'), "<", False) self.comparisonTest(macOSXVersionParser.macOSXVersion('10F569'), macOSXVersionParser.macOSXVersion('10F569'), ">", False) self.comparisonTest(macOSXVersionParser.macOSXVersion('10F569'), macOSXVersionParser.macOSXVersion('10F569'), "=", True) self.comparisonTest(macOSXVersionParser.macOSXVersion('10F569'), macOSXVersionParser.macOSXVersion('10F569'), "!=", False) # 10.6.4 to 10.6.4 with an extra self.comparisonTest(macOSXVersionParser.macOSXVersion('10F569'), macOSXVersionParser.macOSXVersion('10F569a'), "<", True) self.comparisonTest(macOSXVersionParser.macOSXVersion('10F569'), macOSXVersionParser.macOSXVersion('10F569a'), ">", False) self.comparisonTest(macOSXVersionParser.macOSXVersion('10F569'), macOSXVersionParser.macOSXVersion('10F569a'), "=", False) self.comparisonTest(macOSXVersionParser.macOSXVersion('10F569'), macOSXVersionParser.macOSXVersion('10F569a'), "!=", True) # 10.6.4 with an extra to 10.6.4 self.comparisonTest(macOSXVersionParser.macOSXVersion('10F569a'), macOSXVersionParser.macOSXVersion('10F569'), "<", False) self.comparisonTest(macOSXVersionParser.macOSXVersion('10F569a'), macOSXVersionParser.macOSXVersion('10F569'), ">", True) self.comparisonTest(macOSXVersionParser.macOSXVersion('10F569a'), macOSXVersionParser.macOSXVersion('10F569'), "=", False) self.comparisonTest(macOSXVersionParser.macOSXVersion('10F569a'), macOSXVersionParser.macOSXVersion('10F569'), "!=", True) # 10.6.4 with an extra to 10.6.4 with the same extra self.comparisonTest(macOSXVersionParser.macOSXVersion('10F569a'), macOSXVersionParser.macOSXVersion('10F569a'), "<", False) self.comparisonTest(macOSXVersionParser.macOSXVersion('10F569a'), macOSXVersionParser.macOSXVersion('10F569a'), ">", False) self.comparisonTest(macOSXVersionParser.macOSXVersion('10F569a'), macOSXVersionParser.macOSXVersion('10F569a'), "=", True) self.comparisonTest(macOSXVersionParser.macOSXVersion('10F569a'), macOSXVersionParser.macOSXVersion('10F569a'), "!=", False) # 10.6.4 with an extra to 10.6.4 with a different extra self.comparisonTest(macOSXVersionParser.macOSXVersion('10F569a'), macOSXVersionParser.macOSXVersion('10F569b'), "<", True) self.comparisonTest(macOSXVersionParser.macOSXVersion('10F569a'), macOSXVersionParser.macOSXVersion('10F569b'), ">", False) self.comparisonTest(macOSXVersionParser.macOSXVersion('10F569a'), macOSXVersionParser.macOSXVersion('10F569b'), "=", False) self.comparisonTest(macOSXVersionParser.macOSXVersion('10F569a'), macOSXVersionParser.macOSXVersion('10F569b'), "!=", True) # -- object with string comparisons # 10.5 to 10.5.8 self.comparisonTest(macOSXVersionParser.macOSXVersion('9A581'), '9L30', "<", True) # 10.5 to 10.6 self.comparisonTest(macOSXVersionParser.macOSXVersion('9A581'), '10A432', "<", True) # 10.6 to 10.6.4 self.comparisonTest(macOSXVersionParser.macOSXVersion('10A432'), '10F569', "<", True) # 10.6.4 to 10.6.4 self.comparisonTest(macOSXVersionParser.macOSXVersion('10F569'), '10F569', "<", False) # 10.6.4 to 10.6.4 with an extra self.comparisonTest(macOSXVersionParser.macOSXVersion('10F569'), '10F569a', "<", True) self.comparisonTest(macOSXVersionParser.macOSXVersion('10F569a'), '10F569', "<", False)