예제 #1
0
	def getCatalogFullPath(myClass, catalogFileInput, catalogFolders):
		'''Classmethod to translate input to a abs-path from one of the accepted formats (checked in this order):
			- ToDo: http or https reference (will be downloaded and temporary filepath returned)
			- absolute path to a file
			- catalog file name within the CatalogFiles folder, with or without the .catalog extension
			- relative path from CatalogFiles folder, with or without the .catalog extension
			- relative path from the pwd, with or without the .catalog extension
		'''
		
		if catalogFolders is None:
			raise Exception('getCatalogFullPath was passed an emtpy catalogFolders')
			
		elif isinstance(catalogFolders, str) and os.path.isdir(str(catalogFolders)):
			catalogFolders = [catalogFolders]
		
		elif hasattr(catalogFolders, '__iter__'):
			for thisFolder in catalogFolders:
				if not os.path.isdir(str(thisFolder)):
					raise Exception('getCatalogFullPath was passed a bad catalog folder: ' + str(thisFolder))
			
		else:
			raise Exception('getCatalogFullPath unable to understand the catalogFolders given: ' + str(catalogFolders))
		
		
		# http/https url
		if urlparse.urlparse(catalogFileInput).scheme in ["http", "https"]:
			raise Exception("URL catalog files are not done yet")
			# ToDo: download the files, then return the path
		
		# try it as an absolute or relative file path
		if os.path.isfile(catalogFileInput):
			return pathHelpers.normalizePath(catalogFileInput, followSymlink=True)
		
		# cycle through the folders we have been given to see if it is there
		if not os.path.isabs(catalogFileInput):
			for thisFolder in catalogFolders:
				
				# try the simple path:
				if os.path.isfile( os.path.join(thisFolder, catalogFileInput) ):
					return pathHelpers.normalizePath(os.path.join(thisFolder, catalogFileInput), followSymlink=True)
				
				# try appending file extension(s)
				for thisExtension in myClass.fileExtensions:
					if os.path.isfile( os.path.join(thisFolder, catalogFileInput + thisExtension) ):
						return pathHelpers.normalizePath(os.path.join(thisFolder, catalogFileInput + thisExtension), followSymlink=True)
		
		raise commonExceptions.CatalogNotFoundException("The file input is not one that getCatalogFullPath understands, or can find: %s" % catalogFileInput)
예제 #2
0
    def arrangeFolders(self):
        "Create the folder structure for InstaDMG, and pop in soft-links to the items in the cache folder"

        assert isinstance(
            self.sectionFolders,
            list), "sectionfolders is required, and must be a list of dicts"

        import math

        for thisSectionFolder in self.sectionFolders:

            sectionTypes = thisSectionFolder["sections"]
            updateFolder = thisSectionFolder["folderPath"]

            itemsToProcess = []
            for thisSection in sectionTypes:
                itemsToProcess += self.packageGroups[thisSection]

            # Get the number of leading 0s we need
            leadingZeroes = 0
            if len(itemsToProcess) > 0:
                leadingZeroes = int(math.log10(len(itemsToProcess)))
            fileNameFormat = '%0' + str(leadingZeroes + 1) + "d %s"

            # Create symlinks for all of the items
            itemCounter = 1
            for thisItem in itemsToProcess:

                targetFileName = fileNameFormat % (itemCounter,
                                                   thisItem.displayName)
                targetFilePath = pathHelpers.normalizePath(os.path.join(
                    updateFolder, targetFileName),
                                                           followSymlink=True)

                if thisItem.installerChoicesPath is None:
                    # a straight link to the file
                    os.symlink(thisItem.filePath, targetFilePath)

                else:
                    # build a folder linking the item ant the choices path into it
                    os.mkdir(targetFilePath)
                    os.symlink(
                        thisItem.filePath,
                        os.path.join(targetFilePath,
                                     os.path.basename(thisItem.filePath)))
                    os.symlink(
                        thisItem.installerChoicesPath,
                        os.path.join(targetFilePath, 'installerChoices.xml'))

                assert os.path.exists(
                    targetFilePath
                ), "Something went wrong linking from %s to %s" % (
                    targetFilePath, pathFromTargetToSource
                )  # this should catch bad links

                itemCounter += 1

        return True
예제 #3
0
	def arrangeFolders(self):
		"Create the folder structure for InstaDMG, and pop in soft-links to the items in the cache folder"
		
		assert isinstance(self.sectionFolders, list), "sectionfolders is required, and must be a list of dicts"
		
		import math
		
		for thisSectionFolder in self.sectionFolders:
			
			sectionTypes = thisSectionFolder["sections"]
			updateFolder = thisSectionFolder["folderPath"]
			
			itemsToProcess = []
			for thisSection in sectionTypes:
				itemsToProcess += self.packageGroups[thisSection]
			
			# Get the number of leading 0s we need
			leadingZeroes = 0
			if len(itemsToProcess) > 0:
				leadingZeroes = int(math.log10(len(itemsToProcess)))
			fileNameFormat = '%0' + str(leadingZeroes + 1) + "d %s"
			
			# Create symlinks for all of the items
			itemCounter = 1
			for thisItem in itemsToProcess:
				
				targetFileName = fileNameFormat % (itemCounter, thisItem.displayName)
				targetFilePath = pathHelpers.normalizePath(os.path.join(updateFolder, targetFileName), followSymlink=True)
				
				if thisItem.installerChoicesPath is None:
					# a straight link to the file
					os.symlink(thisItem.filePath, targetFilePath)
				
				else:
					# build a folder linking the item ant the choices path into it
					os.mkdir(targetFilePath)
					os.symlink(thisItem.filePath, os.path.join(targetFilePath, os.path.basename(thisItem.filePath)))
					os.symlink(thisItem.installerChoicesPath, os.path.join(targetFilePath, 'installerChoices.xml'))
				
				assert os.path.exists(targetFilePath), "Something went wrong linking from %s to %s" % (targetFilePath, pathFromTargetToSource) # this should catch bad links
				
				itemCounter += 1
				
		return True
예제 #4
0
파일: checksum.py 프로젝트: zdw/instadmg
            if parsedURL.scheme in ['http', 'https']:
                progressReporter = statusHandler(
                    taskMessage=os.path.basename(parsedURL.path) + " ")

            else:
                progressReporter = statusHandler(
                    taskMessage=os.path.basename(location) + " ")

        data = checksum(location,
                        checksumType=options.checksumAlgorithm,
                        progressReporter=progressReporter,
                        outputFolder=thisOutputLocation,
                        checksumInFileName=options.checksumInFileName)

        dataLine = ""
        normalizedPath = pathHelpers.normalizePath(location)

        # in the standardCacheFolder
        if parsedURL.scheme is '' and pathHelpers.pathInsideFolder(
                location, commonConfiguration.standardCacheFolder) and hasattr(
                    os.path, 'relpath'):  # relpath is python 2.6
            dataLine = "\t".join([
                "",
                os.path.splitext(data['name'])[0],
                os.path.relpath(normalizedPath,
                                commonConfiguration.standardCacheFolder),
                data['checksumType'] + ":" + data['checksum']
            ])

        # in the standardUserItemsFolder
        if parsedURL.scheme is '' and pathHelpers.pathInsideFolder(
예제 #5
0
    def getCatalogFullPath(myClass, catalogFileInput, catalogFolders):
        '''Classmethod to translate input to a abs-path from one of the accepted formats (checked in this order):
			- ToDo: http or https reference (will be downloaded and temporary filepath returned)
			- absolute path to a file
			- catalog file name within the CatalogFiles folder, with or without the .catalog extension
			- relative path from CatalogFiles folder, with or without the .catalog extension
			- relative path from the pwd, with or without the .catalog extension
		'''

        if catalogFolders is None:
            raise Exception(
                'getCatalogFullPath was passed an emtpy catalogFolders')

        elif isinstance(catalogFolders, str) and os.path.isdir(
                str(catalogFolders)):
            catalogFolders = [catalogFolders]

        elif hasattr(catalogFolders, '__iter__'):
            for thisFolder in catalogFolders:
                if not os.path.isdir(str(thisFolder)):
                    raise Exception(
                        'getCatalogFullPath was passed a bad catalog folder: '
                        + str(thisFolder))

        else:
            raise Exception(
                'getCatalogFullPath unable to understand the catalogFolders given: '
                + str(catalogFolders))

        # http/https url
        if urlparse.urlparse(catalogFileInput).scheme in ["http", "https"]:
            raise Exception("URL catalog files are not done yet")
            # ToDo: download the files, then return the path

        # try it as an absolute or relative file path
        if os.path.isfile(catalogFileInput):
            return pathHelpers.normalizePath(catalogFileInput,
                                             followSymlink=True)

        # cycle through the folders we have been given to see if it is there
        if not os.path.isabs(catalogFileInput):
            for thisFolder in catalogFolders:

                # try the simple path:
                if os.path.isfile(os.path.join(thisFolder, catalogFileInput)):
                    return pathHelpers.normalizePath(os.path.join(
                        thisFolder, catalogFileInput),
                                                     followSymlink=True)

                # try appending file extension(s)
                for thisExtension in myClass.fileExtensions:
                    if os.path.isfile(
                            os.path.join(thisFolder,
                                         catalogFileInput + thisExtension)):
                        return pathHelpers.normalizePath(os.path.join(
                            thisFolder, catalogFileInput + thisExtension),
                                                         followSymlink=True)

        raise commonExceptions.CatalogNotFoundException(
            "The file input is not one that getCatalogFullPath understands, or can find: %s"
            % catalogFileInput)
예제 #6
0
		if options.outputFolder is not None and parsedURL.scheme in ['http', 'https']:
			thisOutputLocation = options.outputFolder
			
		progressReporter = None
		if options.reportProgress is True:
			
			if parsedURL.scheme in ['http', 'https']:
				progressReporter = statusHandler(taskMessage=os.path.basename(parsedURL.path) + " ")
					
			else:
				progressReporter = statusHandler(taskMessage=os.path.basename(location) + " ")
			
		data = checksum(location, checksumType=options.checksumAlgorithm, progressReporter=progressReporter, outputFolder=thisOutputLocation, checksumInFileName=options.checksumInFileName)
		
		dataLine = ""
		normalizedPath = pathHelpers.normalizePath(location)
		
		# in the standardCacheFolder
		if parsedURL.scheme is '' and pathHelpers.pathInsideFolder(location, commonConfiguration.standardCacheFolder) and hasattr(os.path, 'relpath'): # relpath is python 2.6
			dataLine = "\t".join(["", os.path.splitext(data['name'])[0], os.path.relpath(normalizedPath, commonConfiguration.standardCacheFolder), data['checksumType'] + ":" + data['checksum']])
		
		# in the standardUserItemsFolder
		if parsedURL.scheme is '' and pathHelpers.pathInsideFolder(location, commonConfiguration.standardUserItemsFolder) and hasattr(os.path, 'relpath'): # relpath is python 2.6
			dataLine = "\t".join(["", os.path.splitext(data['name'])[0], os.path.relpath(normalizedPath, commonConfiguration.standardUserItemsFolder), data['checksumType'] + ":" + data['checksum']])
			
		else:
			dataLine = "\t".join(["", os.path.splitext(data['name'])[0], location, data['checksumType'] + ":" + data['checksum']])
		
		if progressReporter is not None:
			progressReporter.update(taskMessage=dataLine)
			progressReporter.finishLine()