Exemple #1
0
	def test_when_system_has_unzip_should_call_unzip(self, Popen):
		Popen.return_value.communicate.return_value = ('stdout', 'stderr')
		lib.unzip_with_permissions('dummy archive.zip')
		Popen.assert_called_with(
				["unzip", "-o", "dummy archive.zip", "-d", "."],
				stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
		eq_(Popen.call_count, 2)
Exemple #2
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)
Exemple #3
0
	def test_when_system_doesnt_have_unzip_should_use_zipfile(self, Popen, extract_zipfile, ZipFile):
		Popen.side_effect = OSError("cant find unzip")
		zip_object = mock.Mock()
		ZipFile.return_value = zip_object

		lib.unzip_with_permissions('dummy archive.zip')

		eq_(Popen.call_count, 1)
		ZipFile.assert_called_once_with('dummy archive.zip')
		extract_zipfile.assert_called_once_with(zip_object, '.')
		zip_object.close.assert_called_once_with()
Exemple #4
0
	def _handle_unpackaged(self, platform, filename):
		'''De-compress a built output tree.

		:param platform: e.g. "chrome", "ios" - we expect the contents of the ZIP file to
			contain a directory named after the relevant platform
		:param filename: the ZIP file to extract
		'''
		shutil.rmtree(platform, ignore_errors=True)
		LOG.debug('removed "%s" directory' % platform)

		lib.unzip_with_permissions(filename)
		LOG.debug('Extracted unpackaged build for %s' % platform)

		os.remove(filename)
		LOG.debug('removed downloaded file "%s"' % filename)
Exemple #5
0
	def fetch_initial(self, uuid, app_path="."):
		'''Retrieves the initial project template

		:param uuid: project uuid
		'''
		LOG.info('Fetching initial project template')
		self._authenticate()

		initial_zip_filename = path.join(app_path, 'initial.zip')

		self._get_file(
			urljoin(self.server, 'app/{uuid}/initial_files/'.format(uuid=uuid)),
			write_to_path=initial_zip_filename,
			progress_bar_title='Fetching initial files'
		)
		lib.unzip_with_permissions(initial_zip_filename, app_path)
		LOG.debug('Extracted initial project template')

		os.remove(initial_zip_filename)
		LOG.debug('Removed downloaded file "%s"' % initial_zip_filename)
Exemple #6
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