Ejemplo n.º 1
0
	def fetch_unpackaged(self, build, to_dir, target):
		'''Retrieves the unpackaged artefacts for a particular build.
		
		:param build: the build to fetch
		:param to_dir: directory that will hold all the unpackged build trees
		'''
		LOG.info('Fetching Forge templates for %s into "%s"' % (build["id"], to_dir))
		self._authenticate()
		
		filenames = []
		if not path.isdir(to_dir):
			LOG.debug('Creating output directory "%s"' % to_dir)
			os.mkdir(to_dir)
			
		with lib.cd(to_dir):
			location = build['file_output']

			filename = urlsplit(location).path.split('/')[-1]
			
			LOG.debug('writing %s to %s' % (location, path.abspath(filename)))
			self._get_file(
				location,
				write_to_path=filename,
				progress_bar_title=target,
			)
			
			self._handle_unpackaged(target, filename)
			
			filenames.append(path.abspath(target))
		
		LOG.debug('Fetched build into "%s"' % '", "'.join(filenames))
		return filenames
def command_build(target=None):
	if target is None:
		LOG.error("Target required for 'forge-extension build', e.g. 'forge-extension build chrome'")
		return
	(config, config_tmp) = app_config()
	args = [
		'forge-generate', 'build',
		'--platforms', target,
		'-c', config_tmp,
		'-u', path.abspath('src'),
		'--remove_attribution', '1',
		'-r' # replace existing output directory if it already exists
	]
	if not forge.settings['development']:
		args.append('-p') # minify library files for customer distribution

	# safari output name differs from target
	if target == "safari":
		target = "forge.safariextension"	

	with cd(platform_dir):
		if path.exists(config['uuid']): # clean up any broken builds
			shutil.rmtree(config['uuid'])
		sys.argv = args
		forge_generate.main()
		if not path.exists(os.path.join(project_dir, 'development')):
			os.mkdir(os.path.join(project_dir, 'development'))
		if path.exists(os.path.join(project_dir, 'development', target)):
			shutil.rmtree(os.path.join(project_dir, 'development', target))
		shutil.move(path.join(config['uuid'], 'development', target),
					path.join(project_dir, 'development', target))
		shutil.rmtree(config['uuid'])
		os.remove(config_tmp)
Ejemplo n.º 3
0
	def update(self):
		if path.exists(path.join(defaults.FORGE_ROOT, 'no_update')):
			raise ForgeError("Tools tried to update themselves during development")

		write_to_path = path.join(defaults.FORGE_ROOT, 'latest.zip')
		self._get_file(urljoin(self.server, 'latest_tools'), write_to_path)

		above_forge_root = path.normpath(path.join(defaults.FORGE_ROOT, '..'))
		with lib.cd(above_forge_root):
			lib.unzip_with_permissions(write_to_path)
Ejemplo n.º 4
0
def push(cookies, path, stream_name):
	# Override cookies for any new remote objects
	from forge import remote
	remote.override_cookies = cookies

	build(cookies, path, 'reload')
	with cd(path):
		forge_main.handle_primary_options(['reload', 'push', stream_name])
		forge_main.handle_secondary_options('reload', ['push', stream_name])
		forge_main.reload(['push', stream_name])
Ejemplo n.º 5
0
def run(cookies, path, target):
	# Override cookies for any new remote objects
	from forge import remote
	remote.override_cookies = cookies

	build(cookies, path, target)
	with cd(path):
		# TODO: HAAACK, should extract an interface to the build tools
		# that both the CLI and web interfaces back onto instead of
		# simulating calls to the CLI
		forge_main.handle_primary_options(['run', '-v'])
		forge_main.handle_secondary_options('run', [target])
		forge_main.run(['--general.interactive', 'no'])
Ejemplo n.º 6
0
def build(cookies, path, target=None):
	# Override cookies for any new remote objects
	from forge import remote
	remote.override_cookies = cookies

	with cd(path):
		# TODO: HAAACK, should extract an interface to the build tools
		# that both the CLI and web interfaces back onto instead of
		# simulating calls to the CLI
		forge_main.handle_primary_options(['build', '-v'])
		forge_main.handle_secondary_options('build', [])
		if target is None:
			forge_main.development_build(['--general.interactive', 'no'], has_target=False)
		else:
			forge_main.development_build([target, '--general.interactive', 'no'])
		_remove_stream_handlers()
Ejemplo n.º 7
0
def migrate(cookies, path):
	"""Rewrites src/config.json appropriately for a new schema

	:param path: Path to migrate the config file for
	"""
	# Override cookies for any new remote objects
	from forge import remote
	remote.override_cookies = cookies

	with cd(path):
		# TODO: HAAACK, should extract an interface to the build tools
		# that both the CLI and web interfaces back onto instead of
		# simulating calls to the CLI
		forge_main.handle_primary_options(['migrate', '-v'])
		forge_main.handle_secondary_options('migrate', [])
		forge_main.migrate(['--general.interactive', 'no'])
Ejemplo n.º 8
0
	def fetch_generate_instructions(self, to_dir):
		'''Retreive the generation instructions for our current environment.

		Rather than hard-coding these instructions - how to inject customer
		code into the apps - they are loaded dynamically from the server to
		allow for different platforms versions to work with a larger number
		of build-tools versions.

		:param to_dir: where the instructions will be put
		'''
		self._authenticate()

		platform_version = build_config.load_app()['platform_version']
		temp_instructions_file = 'instructions.zip'

		LOG.info("Fetching generation instructions for {platform_version} "
				"into \"{to_dir}\"".format(**locals()))

		try:
			# ensure generate_dynamic dir is there before extracting instructions into it
			if not path.isdir(to_dir):
				os.makedirs(to_dir)

			with lib.cd(to_dir):
				self._get_file(
					urljoin(
						self.server,
						'platform/{platform_version}/generate_instructions/'
						.format(platform_version=platform_version)),
					temp_instructions_file
				)
				lib.unzip_with_permissions(temp_instructions_file)

		finally:
			if path.isfile(path.join(to_dir, temp_instructions_file)):
				os.remove(path.join(to_dir, temp_instructions_file))

		return to_dir