Exemplo n.º 1
0
def iterate_assets(
		cache, 
		settings, 
		asset_folders,
		tools, 
		platform
	):
	# loop through each asset path and glob
	# run the tool associated with each file
	logging.info("Running tools on assets...")
	total_files = 0
	modified_files = 0
	for asset in asset_folders:
		try:
			search_path = os.path.join(
				asset.abs_src_folder, 
				asset.glob
			)
			#logging.info("Processing: \"%s\"" % search_path)
			
			if tools.has_key(asset.tool):
				tool = tools[asset.tool]
			else:
				raise UnknownToolException(
					"Unknown tool \"%s\"" % asset.tool
				)

			path_created = False

			for root, subs, files in os.walk(asset.abs_src_folder, topdown=True):
				# filter files based on glob
				files[:] = fnmatch.filter(files, asset.glob)

				if not path_created:
					# make all asset destination folders
					make_dirs(asset.abs_dst_folder)
					path_created = True

				# filter subdirectories based on the glob
				matched_subs = fnmatch.filter(subs, asset.glob)

				# do not recurse into subdirectories
				subs[:] = []

				if matched_subs:
					# One or more subdirectories matched the glob.
					# For now, copy each match over to the destination folder.
					# This is to specifically handle the case where directories are entire
					# folders (.dSYM, .app). These specific dirs should be
					# exceptions where the entire folder is simply copied.
					for folder in matched_subs:
						copy_tree(source_file_root, dst_file_root)

				for file in files:
					src_file_path = os.path.join(root, file)

					total_files += 1

					if not cache.update(src_file_path):
						continue

					modified_files += 1

					execute_commands(
						tools, 
						tool, 
						settings.paths,
						asset,
						src_file_path,
						platform
					)

		except UnknownToolException as e:
			logging.warn(e.message)
			continue	


	logging.info("Complete.")
	logging.info("Modified / Total - %i/%i" % (modified_files, total_files))
Exemplo n.º 2
0
		def process_events(self):
			queued_items = self.queue[:]
			self.queue = []

			for target_path in queued_items:
				for asset in asset_folders:
					match = re.search(asset.get_abs_regex(), target_path)
					if match:

						# determine if this is a directory path
						# a file in a subdirectory
						source_to_target_path = os.path.relpath(target_path, self.settings.paths.source_root)
						asset_target_relative = os.path.relpath(source_to_target_path, asset.src_folder)
						subdir = os.path.sep in asset_target_relative
						is_directory = os.path.isdir(target_path) or subdir

						if is_directory:
							# We don't want to perform tree copies for modified files
							# inside of a subfolder; only do that on the root subfolder.
							if not subdir:
								source_path = target_path
								destination_path = os.path.join(settings.paths.destination_root, asset.dst_folder, asset_target_relative)
								copy_tree(source_path, destination_path)
							break
						
						try:
							# try to update the cache
							if not self.cache.update(target_path):
								break

							if self.tools.has_key(asset.tool):
								tool = tools[asset.tool]
							else:
								raise UnknownToolException(
									"Unknown tool \"%s\"" % asset.tool
								)

							outputs = execute_commands(
								self.tools, 
								tool, 
								self.settings.paths,
								asset,
								target_path,
								self.platform
							)

							# get the relative asset path from the source_root
							# to the asset being modified.
							relative_path = os.path.relpath(outputs[0], settings.paths.destination_root)

							if self.send_reload_requests:
								request_packet = {
									"type": "file_modified",
									"resource": relative_path
								}
								
								post = 80
								host, uri = self.server_url.split("/")
								if ":" in host:
									host, port = host.split(":")
									port = int(port)

								try:
									connection = httplib.HTTPConnection(host, port)
									connection.request("PUT", ("/" + uri), json.dumps(request_packet))
									response = connection.getresponse()
									if response.status != 204 and response.status != 200:
										logging.warn("Request failed: (%i) %s" % (response.status, response.reason))				
								except socket.error as exception:
									pass
								except:
									raise
							break
						except:
							raise