Пример #1
0
def compress (path, basename=None):
	""" 
		Compress the file or directory at path 
		Argument path: Unicode string. 
		Argument basename: Name of the archive to be generated. Unicode string, can be None.
		Result: Path to the compressed file. Unicode string.
	"""
	SystemLogger.debug("Compressing path")
	SystemLogger.debug("Path: " + path)
	result = None
	if basename == None:
		basename = os.path.basename(path)
	if platform.system() == 'Windows':
		output_file = os.path.join('.', basename + '.' + config.d_archive_extension)
		SystemLogger.debug("Destination: " + output_file)
		# TODO: get path from registry
		executable = os.path.join('C:\\', 'Program Files', '7-zip', '7z.exe')
		if os.path.isfile(executable):
			if execute([executable, 'a', output_file, path], SystemLogger.get_file()) == 0:
				SystemLogger.debug("Compression complete")
				result = output_file
			else:
				SystemLogger.error("Compression of '" + path + "' failed")
		else:
			SystemLogger.error("Comperssion of '" + path + "' failed. 7zip executable not found at " + executable)
	else:
		output_file = os.path.realpath(os.path.join('.', basename + '.' + config.d_archive_extension))
		workingdir, compressdir = os.path.split(path)
		if execute(['tar', '-C', workingdir, '-cjf', output_file, compressdir], SystemLogger.get_file()) == 0:
			SystemLogger.debug("Compression complete")
			result = output_file
		else:
			SystemLogger.error("Compression of '" + path + "' failed")
	return result
Пример #2
0
	def _internal_compile (self, X_code, additional_commands):
		ec_path = os.path.expandvars (os.path.join ("$ISE_EIFFEL", "studio", "spec", "$ISE_PLATFORM", "bin", _append_exe('ec')))
		ecf_path = os.path.join (self._project_path, self._ecf)
		
			# Print some information about the compilation step in the console.
		SystemLogger.info("EiffelStudio: " + ec_path)
		SystemLogger.info("ECF: " + ecf_path)
		SystemLogger.info("Target: " + self._target)
		SystemLogger.info("ISE_EIFFEL: " + os.environ['ISE_EIFFEL'])
		SystemLogger.info("ISE_LIBRARY: " + os.environ['ISE_LIBRARY'])
		SystemLogger.info("EIFFEL_SRC: " + os.environ['EIFFEL_SRC'])
		
		if os.path.isfile (ecf_path):
			
				# Invoke the Eiffel compiler with the right arguments.
			command = [ec_path, '-config', ecf_path, '-batch'] + additional_commands
			code = eutils.execute (command, SystemLogger.get_file(), self._project_path)
			
				# Check if the compilation was successful and store last_result.
			generated_binary = os.path.join (self._project_path, 'EIFGENs', self._target, X_code, self._binary)
			
			if code == 0 and generated_binary != None and os.path.isfile (generated_binary):
				self._last_result = generated_binary
				SystemLogger.success ("Compilation of Eiffel project " + ecf_path + " (" + self._target + ") successful.")
			else:
				self._last_result = None
				SystemLogger.error ("Compilation of Eiffel project " + ecf_path + " (" + self._target + ") failed.")
		else:
			SystemLogger.error("ECF file '" + ecf_path + "' does not exist")
Пример #3
0
def extract (a_file):
	""" 
		Extract a_file to the current directory.
		Argument a_file: Unicode string.
	"""
	SystemLogger.debug("Extracting file")
	SystemLogger.debug("Path: " + a_file)
	if platform.system() == 'Windows':
		# TODO: get path from registry
		executable = os.path.join('C:\\', 'Program Files', '7-zip', '7z.exe')
		if os.path.isfile(executable):
			if execute([executable, 'x', a_file], SystemLogger.get_file()) == 0:
				SystemLogger.debug("Extraction complete")
			else:
				SystemLogger.error("Extraction of '" + a_file + "' failed")
		else:
			SystemLogger.error("Extraction of '" + a_file + "' failed. 7zip executable not found at " + executable)
	else:
		if execute(['tar', '-xjf', a_file], SystemLogger.get_file()) == 0:
			SystemLogger.debug("Extraction complete")
		else:
			SystemLogger.error("Extraction of '" + a_file + "' failed")
Пример #4
0
def set_persistent_environment_variable(varname, value):
	SystemLogger.debug("setting environment variable " + varname + " to " + value)
	os.environ[varname] = value
	if platform.system() == 'Windows':
		execute(['setx', varname, value], SystemLogger.get_file())
	return
Пример #5
0
def run_command (command, directory):
	eutils.execute (command, SystemLogger.get_file(), os.path.expandvars (directory))