예제 #1
0
	def forceDirectoryUnmount(self, mount_point):
		ret = environment.runSilent(["fusermount", "-u", mount_point])
		i = 0
		while (ret != 0 and i < 10):
			time.sleep(1)
			ret = environment.runSilent(["fusermount", "-u", mount_point])
			i += 1
		if (ret != 0):
			log.showErrorW("Unable to unmount " + mount_point + ".  Please unmount manually.")
			return False
		return True
예제 #2
0
	def create(self, size_bytes):
		# Check to make sure the file doesn't already exist.
		if (self.exists()):
			raise PackageAlreadyExistsException()

		# Create a temporary folder for working in.
		tempfolder = tempfile.mkdtemp("", self.appname_prefix + "_build_area.", "/tmp/")
		log.showInfoW("Total size for Ext2 partition will be: " + str(float(size_bytes) / (1024 * 1024)) + " MB")

		# Create a zero'd file so that we can partition it.
		log.showInfoW("Creating zero'd file at " + os.path.join(tempfolder, "app.ext2") + "...")
		with open(os.path.join(tempfolder, "app.ext2"), "w") as f:
			f.write("".ljust(int(size_bytes), "\0"))

		# Now format the zero'd file.
		log.showInfoW("Formatting Ext2 partition at " + os.path.join(tempfolder, "app.ext2") + "...")
		if (environment.runSilent(["mkfs.ext2", "-F", "-t", "ext2", os.path.join(tempfolder, "app.ext2")]) != 0):
			log.showErrorW("An error occurred while formatting the Ext2 partition.")
			raise PackageCreationFailureException()

		# Attach the blank partition to the AppFS bootstrapping binary.
		log.showInfoW("Attaching Ext2 partition to AppFS file at " + os.path.join(tempfolder, "app.afs") + "...")
		if (subprocess.call(["appattach", os.path.join(tempfolder, "app.ext2"), os.path.join(tempfolder, "app.afs")]) != 0):
			log.showErrorW("An error occurred while attaching the Ext2 partition to")
			log.showErrorO("the AppFS binary.  Check above for error messages.")
			raise PackageCreationFailureException()

		# Move the newly created package to the new location.
		log.showInfoW("Moving package to " + self.filename + "...")
		try:
			os.rename(os.path.join(tempfolder, "app.afs"), self.filename)
		except:
			log.showErrorW("Failed to move AppFS package to target.")
			raise PackageCreationFailureException()
		log.showSuccessW("Package successfully created.")
		
		# Remove our temporary files
		try:
			self.forceFileRemoval(os.path.join(tempfolder, "app.afs"))
			self.forceFileRemoval(os.path.join(tempfolder, "app.ext2"))
			os.rmdir(tempfolder)
			log.showSuccessW("Cleaned up temporary working directory.")
		except:
			log.showErrorW("Unable to clean up working directory at: " + tempfolder)
			log.showErrorO("Please remove directory manually.")
		
		return True