Exemple #1
0
def main():
	import optparse
	
	startTime = time.time()
	
	compressionChoices = ['zlib', 'bzip2']
	
	optionParser = optparse.OptionParser()
	optionParser.add_option("-a", "--automatic", default=False, action="store_true", dest="automaticRun", help="Run automaically, will fail if there are any questions")
	
	# ToDo: convert these to actions vaildating the input
	optionParser.add_option("-c", "--compression-type", default="zlib", choices=compressionChoices, action="store", dest="compressionType", help="Choose the compression type from: %s" % ", ".join(compressionChoices))
	optionParser.add_option("-f", "--output-folder", default=None, action="store", dest="outputFolder", help="Override the output folder")
	optionParser.add_option("-l", "--legacy", default=False, action="store_true", dest="legacyMode", help="Use legacy name and location")
	optionParser.add_option("-n", "--output-name", default=None, action="store", dest="outputFileName", help="Override the output name")
	optionParser.add_option("-o", "--overwrite-existing-file", default=False, action="store_true", dest="overwriteExisting", help="Overwite existing output file without asking")	
	(options, args) = optionParser.parse_args()
	
	chosenMount			= None
	
	if len(args) == 0:
		
		possibleVolumes = []
		
		# get a list of avalible installer disks
		for thisMountPoint in volumeTools.getMountedVolumes():
						
			try:
				thisVolume = container(thisMountPoint)
			except Exception, error:
				continue
			
			if not thisVolume.isContainerType('volume'):
				continue
			
			macOSInformation = thisVolume.getMacOSInformation()
			if macOSInformation is None or macOSInformation['macOSInstallerDisc'] is not True:
				continue
			
			possibleVolumes.append(thisVolume)
		
		if len(possibleVolumes) == 0:
			optionParser.error('Error: There were no possible disks to image')
		
		elif len(possibleVolumes) == 1 and options.automaticRun == True:
			chosenMount = possibleVolumes[0]
		
		elif len(possibleVolumes) == 1:
			chosenMount = possibleVolumes[0]
			
			choice = raw_input('Only one mount point found: "%s" (%s) - %s %s (%s). Create image? (Y/N):' % (chosenMount.getMountPoint(), chosenMount.volumeType, chosenMount.getMacOSInformation()['macOSType'], chosenMount.getMacOSInformation()['macOSVersion'], chosenMount.getMacOSInformation()['macOSBuild']))
			if choice.lower() not in ['y', 'yes']:
				print("Canceling")
				sys.exit()
			
		elif options.automaticRun == True:
			optionParser.error('There was more than one avalible disk in an automatic run. Can only run in automatic mode when there is only one option.')
		
		else:
			print('The following mounts are avalible: ')
			i = 1
			for thisVolume in possibleVolumes:
				print('	%-4.4s"%s" (%s) - %s %s (%s)' % (str(i) + ")", thisVolume.getWorkingPath(), thisVolume.volumeType, thisVolume.getMacOSInformation()['macOSType'], thisVolume.getMacOSInformation()['macOSVersion'], thisVolume.getMacOSInformation()['macOSBuild']))
				i += 1
			choice = raw_input('Please select a volume by typeing in the number that precedes it: ')
			try:
				choice = int(choice)
			except:
				sys.stderr.write('Error: Input "%s" is not an integer\n' % choice)
				sys.exit(13)
			if choice > len(possibleDiscsInfo) or choice <= 0:
				sys.stderr.write('Error: Input "%s" was not a valid option\n' % choice)
				sys.exit(14)
			
			chosenMount = possibleVolumes[choice - 1]
Exemple #2
0
			choice = raw_input('Please select a volume by typeing in the number that precedes it: ')
			try:
				choice = int(choice)
			except:
				sys.stderr.write('Error: Input "%s" is not an integer\n' % choice)
				sys.exit(13)
			if choice > len(possibleDiscsInfo) or choice <= 0:
				sys.stderr.write('Error: Input "%s" was not a valid option\n' % choice)
				sys.exit(14)
			
			chosenMount = possibleVolumes[choice - 1]
	
	elif len(args) == 1:
		# user has supplied the mount point to use
		try:
			chosenMount = container(args[0])
		except:
			optionParser.error('The path "%s" is not valid' % args[0])
		
		if not chosenMount.isContainerType('volume') or chosenMount.getMacOSInformation()['macOSType'] is None:
			optionParser.error('The path "%s" is not an installer disk' % args[0])
	
	else:
		optionParser.error('Can only process a single disk at a time')
	
	chosenFileName = options.outputFileName
	if chosenFileName is None and options.legacyMode is False:
		chosenFileName = "%s %s %s.dmg" % (chosenMount.getMacOSInformation()['macOSType'], chosenMount.getMacOSInformation()['macOSVersion'], chosenMount.getMacOSInformation()['macOSBuild'])
	elif options.legacyMode is True:
		chosenFileName = "Mac OS X Install DVD.dmg"
	
Exemple #3
0
def main():
    import optparse

    # ------- defaults -------

    outputVolumeName = "MacintoshHD"
    outputFileName = str(datetime.date.today().month) + "-" + str(
        datetime.date.today().day) + "-" + str(datetime.date.today().year)

    # ---- parse options ----

    def print_version(option, opt, value, optionsParser):
        optionsParser.print_version()
        sys.exit(0)

    optionsParser = optparse.OptionParser(
        "%prog [options] catalogFile1 [catalogFile2 ...]",
        version="%%prog %s" % versionString)
    optionsParser.remove_option('--version')
    optionsParser.add_option("-v",
                             "--version",
                             action="callback",
                             callback=print_version,
                             help="Print the version number and quit")

    # catalog items

    optionsParser.add_option(
        "-a",
        "--add-catalog",
        action="append",
        type="string",
        dest="addOnCatalogFiles",
        help=
        "Add the items in this catalog file to all catalog files processed. Can be called multiple times",
        metavar="FILE_PATH")

    # instaDMG options

    optionsParser.add_option(
        "-p",
        "--process",
        action="store_true",
        default=False,
        dest="processWithInstaDMG",
        help="Run InstaDMG for each catalog file processed")
    optionsParser.add_option(
        "",
        "--instadmg-scratch-folder",
        action="store",
        dest="instadmgScratchFolder",
        default=None,
        type="string",
        metavar="FOLDER_PATH",
        help="Tell InstaDMG to use FOLDER_PATH as the scratch folder")
    optionsParser.add_option(
        "",
        "--instadmg-output-folder",
        action="store",
        dest="instadmgOutputFolder",
        default=None,
        type="string",
        metavar="FOLDER_PATH",
        help="Tell InstaDMG to place the output image in FOLDER_PATH")

    # source folder options

    optionsParser.add_option('',
                             '--add-catalog-folder',
                             action='append',
                             default=None,
                             type='string',
                             dest='catalogFolders',
                             help='Set the folders searched for catalog files',
                             metavar="FILE_PATH")
    optionsParser.add_option(
        '',
        '--set-cache-folder',
        action='store',
        default=None,
        type='string',
        dest='cacheFolder',
        help='Set the folder used to store downloaded files',
        metavar="FILE_PATH")
    optionsParser.add_option(
        '',
        '--add-source-folder',
        action='append',
        default=[],
        type='string',
        dest='searchFolders',
        help='Set the folders searched for items to install',
        metavar="FILE_PATH")

    # post-processing

    optionsParser.add_option(
        '',
        '--restore-onto-volume',
        default=None,
        type='string',
        dest='restoreTarget',
        help=
        'After creating the image, restore onto volume. WARNING: this will destroy all data on the volume',
        metavar="VOLUME")

    # run the parser

    options, catalogFiles = optionsParser.parse_args()

    # ---- police options

    # catalogFiles
    if len(catalogFiles) < 1:
        optionsParser.error("At least one catalog file is required")

    if options.processWithInstaDMG is True:

        # check that we are running as root
        if os.getuid() != 0:
            optionsParser.error(
                "When using the -p/--process flag this must be run as root (sudo is fine)"
            )

        # instadmgScratchFolder
        if options.instadmgScratchFolder is not None and not os.path.isdir(
                options.instadmgScratchFolder):
            optionsParser.error(
                "The --instadmg-scratch-folder option requires a valid folder path, but got: %s"
                % options.instadmgScratchFolder)

        # instadmgOutputFolder
        if options.instadmgOutputFolder is not None and not os.path.isdir(
                options.instadmgOutputFolder):
            optionsParser.error(
                "The instadmg-output-folder option requires a valid folder path, but got: %s"
                % options.instadmgOutputFolder)

        # restoreTarget
        if options.restoreTarget is not None:

            if len(catalogFiles) > 1:
                optionsParser.error(
                    'When using the --restore-onto-volume option option only a single catalog file can be processed'
                )

            try:
                options.restoreTarget = container(options.restoreTarget)
            except:
                optionsParser.error(
                    "Could not understand the value of the --restore-onto-volume option: "
                    + str(options.restoreTarget))

            if not options.restoreTarget.isContainerType(
                    'volume') or options.restoreTarget.isContainerType('dmg'):
                optionsParser.error(
                    "The --restore-onto-volume option can only accept volumes on a HD, not dmgs or folder-like objects: "
                    + str(options.restoreTarget))

    else:

        # instadmgScratchFolder, instadmgOutputFolder, and restoreTarget are meaningless without the --process option
        for optionName, optionVariable in {
                '--instadmg-scratch-folder': 'instadmgScratchFolder',
                '--instadmg-output-folder': 'instadmgOutputFolder',
                '--restore-onto-volume': 'restoreTarget'
        }.items():
            if getattr(options, optionVariable) is not None:
                optionsParser.error(
                    "The %s option requires the -p/--process option to also be enabled"
                    % optionName)

    # ---- process options

    if options.catalogFolders is None:
        options.catalogFolders = commonConfiguration.standardCatalogFolder

    baseCatalogFiles = []
    for thisCatalogFile in catalogFiles:
        try:
            baseCatalogFiles.append(
                instaUpToDate.getCatalogFullPath(thisCatalogFile,
                                                 options.catalogFolders))

        except commonExceptions.CatalogNotFoundException:
            optionsParser.error(
                "There does not seem to be a catalog file at: %s" %
                thisCatalogFile)

    addOnCatalogFiles = []
    if options.addOnCatalogFiles is not None:
        for thisCatalogFile in options.addOnCatalogFiles:
            try:
                addOnCatalogFiles.append(
                    instaUpToDate.getCatalogFullPath(thisCatalogFile,
                                                     options.catalogFolders))

            except commonExceptions.CatalogNotFoundException:
                optionsParser.error(
                    "There does not seem to be a catalog file at: %s" %
                    thisCatalogFile)

    if options.cacheFolder is None:
        options.cacheFolder = commonConfiguration.standardCacheFolder

    if commonConfiguration.standardUserItemsFolder not in options.searchFolders:
        options.searchFolders.append(
            commonConfiguration.standardUserItemsFolder)

    # ----- setup system ----

    # ToDo: evaluate removing these

    try:
        cacheController.setCacheFolder(options.cacheFolder)
    except ValueError, error:
        optionsParser.error(error)
Exemple #4
0
def main ():
	import optparse
	
	# ------- defaults -------
	
	outputVolumeName	= "MacintoshHD"
	outputFileName		= str(datetime.date.today().month) + "-" + str(datetime.date.today().day) + "-" + str(datetime.date.today().year)
	
	# ---- parse options ----
	
	def print_version(option, opt, value, optionsParser):
		optionsParser.print_version()
		sys.exit(0)
	
	optionsParser = optparse.OptionParser("%prog [options] catalogFile1 [catalogFile2 ...]", version="%%prog %s" % versionString)
	optionsParser.remove_option('--version')
	optionsParser.add_option("-v", "--version", action="callback", callback=print_version, help="Print the version number and quit")
	
	# catalog items
	
	optionsParser.add_option("-a", "--add-catalog", action="append", type="string", dest="addOnCatalogFiles", help="Add the items in this catalog file to all catalog files processed. Can be called multiple times", metavar="FILE_PATH")
	
	# instaDMG options
	
	optionsParser.add_option("-p", "--process", action="store_true", default=False, dest="processWithInstaDMG", help="Run InstaDMG for each catalog file processed")
	optionsParser.add_option("", "--instadmg-scratch-folder", action="store", dest="instadmgScratchFolder", default=None, type="string", metavar="FOLDER_PATH", help="Tell InstaDMG to use FOLDER_PATH as the scratch folder")
	optionsParser.add_option("", "--instadmg-output-folder", action="store", dest="instadmgOutputFolder", default=None, type="string", metavar="FOLDER_PATH", help="Tell InstaDMG to place the output image in FOLDER_PATH")
	
	# source folder options
	
	optionsParser.add_option('', '--add-catalog-folder', action='append', default=None, type='string', dest='catalogFolders', help='Set the folders searched for catalog files', metavar="FILE_PATH")
	optionsParser.add_option('', '--set-cache-folder', action='store', default=None, type='string', dest='cacheFolder', help='Set the folder used to store downloaded files', metavar="FILE_PATH")
	optionsParser.add_option('', '--add-source-folder', action='append', default=[], type='string', dest='searchFolders', help='Set the folders searched for items to install', metavar="FILE_PATH")
	
	# post-processing
	
	optionsParser.add_option('', '--restore-onto-volume', default=None, type='string', dest='restoreTarget', help='After creating the image, restore onto volume. WARNING: this will destroy all data on the volume', metavar="VOLUME")
	
	# run the parser
	
	options, catalogFiles = optionsParser.parse_args()
	
	# ---- police options
	
	# catalogFiles
	if len(catalogFiles) < 1:
		optionsParser.error("At least one catalog file is required")
	
	if options.processWithInstaDMG is True:
		
		# check that we are running as root
		if os.getuid() != 0:
			optionsParser.error("When using the -p/--process flag this must be run as root (sudo is fine)")
		
		# instadmgScratchFolder
		if options.instadmgScratchFolder is not None and not os.path.isdir(options.instadmgScratchFolder):
			optionsParser.error("The --instadmg-scratch-folder option requires a valid folder path, but got: %s" % options.instadmgScratchFolder)
		
		# instadmgOutputFolder
		if options.instadmgOutputFolder is not None and not os.path.isdir(options.instadmgOutputFolder):
			optionsParser.error("The instadmg-output-folder option requires a valid folder path, but got: %s" % options.instadmgOutputFolder)
		
		# restoreTarget
		if options.restoreTarget is not None:
			
			if len(catalogFiles) > 1:
				optionsParser.error('When using the --restore-onto-volume option option only a single catalog file can be processed')
			
			try:
				options.restoreTarget = container(options.restoreTarget)
			except:
				optionsParser.error("Could not understand the value of the --restore-onto-volume option: " + str(options.restoreTarget))
			
			if not options.restoreTarget.isContainerType('volume') or options.restoreTarget.isContainerType('dmg'):
				optionsParser.error("The --restore-onto-volume option can only accept volumes on a HD, not dmgs or folder-like objects: " + str(options.restoreTarget))
		
	else:
		
		# instadmgScratchFolder, instadmgOutputFolder, and restoreTarget are meaningless without the --process option
		for optionName, optionVariable in {
			'--instadmg-scratch-folder':'instadmgScratchFolder',
			'--instadmg-output-folder':'instadmgOutputFolder',
			'--restore-onto-volume':'restoreTarget'
		}.items():
			if getattr(options, optionVariable) is not None:
				optionsParser.error("The %s option requires the -p/--process option to also be enabled" % optionName)
	
	# ---- process options

	if options.catalogFolders is None:
		options.catalogFolders = commonConfiguration.standardCatalogFolder
		
	baseCatalogFiles = []
	for thisCatalogFile in catalogFiles:
		try:
			baseCatalogFiles.append(instaUpToDate.getCatalogFullPath(thisCatalogFile, options.catalogFolders))
			
		except commonExceptions.CatalogNotFoundException:
			optionsParser.error("There does not seem to be a catalog file at: %s" % thisCatalogFile)
	
	addOnCatalogFiles = []
	if options.addOnCatalogFiles is not None:
		for thisCatalogFile in options.addOnCatalogFiles:
			try:
				addOnCatalogFiles.append(instaUpToDate.getCatalogFullPath(thisCatalogFile, options.catalogFolders))
			
			except commonExceptions.CatalogNotFoundException:
				optionsParser.error("There does not seem to be a catalog file at: %s" % thisCatalogFile)
	
	if options.cacheFolder is None:
		options.cacheFolder = commonConfiguration.standardCacheFolder
	
	if commonConfiguration.standardUserItemsFolder not in options.searchFolders:
		options.searchFolders.append(commonConfiguration.standardUserItemsFolder)
	
	# ----- setup system ----
	
	# ToDo: evaluate removing these
	
	try:
		cacheController.setCacheFolder(options.cacheFolder)
	except ValueError, error:
		optionsParser.error(error)
Exemple #5
0
def main():
    import optparse

    startTime = time.time()

    compressionChoices = ['zlib', 'bzip2']

    optionParser = optparse.OptionParser()
    optionParser.add_option(
        "-a",
        "--automatic",
        default=False,
        action="store_true",
        dest="automaticRun",
        help="Run automaically, will fail if there are any questions")

    # ToDo: convert these to actions vaildating the input
    optionParser.add_option("-c",
                            "--compression-type",
                            default="zlib",
                            choices=compressionChoices,
                            action="store",
                            dest="compressionType",
                            help="Choose the compression type from: %s" %
                            ", ".join(compressionChoices))
    optionParser.add_option("-f",
                            "--output-folder",
                            default=None,
                            action="store",
                            dest="outputFolder",
                            help="Override the output folder")
    optionParser.add_option("-l",
                            "--legacy",
                            default=False,
                            action="store_true",
                            dest="legacyMode",
                            help="Use legacy name and location")
    optionParser.add_option("-n",
                            "--output-name",
                            default=None,
                            action="store",
                            dest="outputFileName",
                            help="Override the output name")
    optionParser.add_option(
        "-o",
        "--overwrite-existing-file",
        default=False,
        action="store_true",
        dest="overwriteExisting",
        help="Overwite existing output file without asking")
    (options, args) = optionParser.parse_args()

    chosenMount = None

    if len(args) == 0:

        possibleVolumes = []

        # get a list of avalible installer disks
        for thisMountPoint in volumeTools.getMountedVolumes():

            try:
                thisVolume = container(thisMountPoint)
            except Exception, error:
                continue

            if not thisVolume.isContainerType('volume'):
                continue

            macOSInformation = thisVolume.getMacOSInformation()
            if macOSInformation is None or macOSInformation[
                    'macOSInstallerDisc'] is not True:
                continue

            possibleVolumes.append(thisVolume)

        if len(possibleVolumes) == 0:
            optionParser.error('Error: There were no possible disks to image')

        elif len(possibleVolumes) == 1 and options.automaticRun == True:
            chosenMount = possibleVolumes[0]

        elif len(possibleVolumes) == 1:
            chosenMount = possibleVolumes[0]

            choice = raw_input(
                'Only one mount point found: "%s" (%s) - %s %s (%s). Create image? (Y/N):'
                % (chosenMount.getMountPoint(), chosenMount.volumeType,
                   chosenMount.getMacOSInformation()['macOSType'],
                   chosenMount.getMacOSInformation()['macOSVersion'],
                   chosenMount.getMacOSInformation()['macOSBuild']))
            if choice.lower() not in ['y', 'yes']:
                print("Canceling")
                sys.exit()

        elif options.automaticRun == True:
            optionParser.error(
                'There was more than one avalible disk in an automatic run. Can only run in automatic mode when there is only one option.'
            )

        else:
            print('The following mounts are avalible: ')
            i = 1
            for thisVolume in possibleVolumes:
                print('	%-4.4s"%s" (%s) - %s %s (%s)' %
                      (str(i) + ")",
                       thisVolume.getWorkingPath(), thisVolume.volumeType,
                       thisVolume.getMacOSInformation()['macOSType'],
                       thisVolume.getMacOSInformation()['macOSVersion'],
                       thisVolume.getMacOSInformation()['macOSBuild']))
                i += 1
            choice = raw_input(
                'Please select a volume by typeing in the number that precedes it: '
            )
            try:
                choice = int(choice)
            except:
                sys.stderr.write('Error: Input "%s" is not an integer\n' %
                                 choice)
                sys.exit(13)
            if choice > len(possibleDiscsInfo) or choice <= 0:
                sys.stderr.write('Error: Input "%s" was not a valid option\n' %
                                 choice)
                sys.exit(14)

            chosenMount = possibleVolumes[choice - 1]
Exemple #6
0
                choice = int(choice)
            except:
                sys.stderr.write('Error: Input "%s" is not an integer\n' %
                                 choice)
                sys.exit(13)
            if choice > len(possibleDiscsInfo) or choice <= 0:
                sys.stderr.write('Error: Input "%s" was not a valid option\n' %
                                 choice)
                sys.exit(14)

            chosenMount = possibleVolumes[choice - 1]

    elif len(args) == 1:
        # user has supplied the mount point to use
        try:
            chosenMount = container(args[0])
        except:
            optionParser.error('The path "%s" is not valid' % args[0])

        if not chosenMount.isContainerType(
                'volume'
        ) or chosenMount.getMacOSInformation()['macOSType'] is None:
            optionParser.error('The path "%s" is not an installer disk' %
                               args[0])

    else:
        optionParser.error('Can only process a single disk at a time')

    chosenFileName = options.outputFileName
    if chosenFileName is None and options.legacyMode is False:
        chosenFileName = "%s %s %s.dmg" % (