def update_repository(url, path): """Update repository at given path. If no checkout exists, do a new checkout from given url.""" revision = -1 if os.path.exists(path): SystemLogger.info("Updating repository") SystemLogger.info("Path: " + path) remote_url = info_remote_url(path) if url == remote_url: revision = info_local_revision_number(path) remote_revision = info_remote_revision_number(url) SystemLogger.debug("Local revision: " + str(revision)) SystemLogger.debug("Remote revision: " + str(remote_revision)) if revision == remote_revision: SystemLogger.success("Repository '" + path + "' is up-to-date at revision " + str(revision)) else: revision = update(path) SystemLogger.success("Repository '" + path + "' is updated to revision " + str(revision)) else: SystemLogger.error("Repository URL of existing directory '" + path + "' does not match expected remote url") SystemLogger.error("Existing URL: " + remote_url) SystemLogger.error("Expected URL: " + url) else: SystemLogger.info("Checking out repository") SystemLogger.info("URL: " + url) SystemLogger.info("Location: " + path) revision = checkout(url, path) SystemLogger.success("Checkout of revision " + str(revision) + " complete") return revision
def copy_files(src_glob_raw, destination_folder_raw): SystemLogger.info("copying files from " + src_glob_raw + " to " + destination_folder_raw) expanded_folder = os.path.expandvars (destination_folder_raw) for fname in glob.iglob(os.path.expandvars (src_glob_raw)): dst_file = os.path.join(expanded_folder, os.path.basename(fname)) SystemLogger.debug ("copying file from " + fname + " to " + dst_file) shutil.copy(fname, dst_file)
def clean (self): l_path = os.path.join (self._project_path, "EIFGENs", self._target) SystemLogger.info ("Cleaning Eiffel program at " + l_path) elocation.delete (l_path) l_path = os.path.dirname (l_path) if os.listdir (l_path) == []: elocation.delete (l_path)
def catalog(catalog, keep_all): if catalog == None: catalog = "autogen" l_command = _set_eweasel_env() l_catalog = _prepare_catalog(catalog) assert os.path.exists(l_catalog), "Catalog does not exist." SystemLogger.info("Running Eweasel on catalog: " + l_catalog) _invoke_eweasel(l_command, l_catalog, keep_all)
def execute_with_output (program, execution_directory = None): SystemLogger.debug ("Executing " + ' '.join (program)) if execution_directory is None: proc = subprocess.Popen(program, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) for line in proc.stdout: SystemLogger.info (line.decode (v_encoding).rstrip()) proc.wait() SystemLogger.info("Finished with code " + str(proc.returncode)) return proc.returncode
def fix_makefiles (src_glob_raw, link_command): for orig in glob.iglob(os.path.expandvars (src_glob_raw)): SystemLogger.info ("Fixing makefile: " + orig) fixed = orig + ".tmp" with open (fixed, 'w') as fixed_file: with open (orig) as orig_file: for line in orig_file: fixed_file.write (line.replace ('LINKCMD = $(CC)', 'LINKCMD = ' + link_command)) elocation.delete (orig) elocation.move (fixed, orig)
def generate(a_filter, name="autogen"): l_parser = boolean.Parser(a_filter) l_filter = l_parser.parse() l_target_path = os.path.join(elocation.build(), name + ".eweasel_catalog") SystemLogger.info("Creating catalog " + l_target_path + " with filter: " + l_filter.to_string()) with open(_prepare_catalog(None), "r") as source: with open(l_target_path, "w") as target: target.write("source_path $BUGS\n") for line in source: if l_filter.evaluate(line): print(line.rstrip()) target.write(line)
def execute(program, output_file = None, execution_directory = None): """ Execute 'program'. """ SystemLogger.info("Executing " + ' '.join(program)) if isinstance(output_file, str): pipe = open(output_file, 'a') else: pipe = output_file if execution_directory is None: proc = subprocess.Popen(program, stdin=pipe, stdout=pipe, stderr=pipe) else: proc = subprocess.Popen(program, cwd=execution_directory, stdin=pipe, stdout=pipe, stderr=pipe) proc.communicate() if isinstance(output_file, str): pipe.close() SystemLogger.info("Finished with code " + str(proc.returncode)) return proc.returncode
def update_EiffelStudio(): SystemLogger.info("Updating EiffelStudio") if v_force_es_version != None: SystemLogger.warning("Forcing EiffelStudio version " + v_force_es_version) name, filename, version, url = get_nightly_build(d_ise_platform, d_archive_extension) current_version, current_path = get_installed_version() if version > current_version or (v_force_es_version != None and current_version != v_force_es_version): target_file = os.path.join(v_dir_eiffelstudio_base, filename) download_file(url, target_file) eutils.extract(target_file) elocation.move(os.path.join('.', name), os.path.join(v_dir_eiffelstudio_base, name + '_' + str(version))) elocation.delete(target_file) update_environment_variables() current_version = version SystemLogger.success("EiffelStudio version " + str(version) + " installed") else: update_environment_variables() SystemLogger.success("EiffelStudio is up-to-date at version " + str(current_version)) return current_version
def send_mail(to, subject, text, attach=None): """Send email""" SystemLogger.info("Sending email '" + subject + "' to " + str(to)) if to != None: email_user = "******" msg = MIMEMultipart() msg['From'] = "EVE <" + email_user + ">" msg['To'] = to msg['Subject'] = subject msg.attach(MIMEText(text)) if attach != None: part = MIMEBase('application', 'octet-stream') part.set_payload(open(attach, 'rb').read()) Encoders.encode_base64(part) part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(attach)) msg.attach(part) mailServer = smtplib.SMTP("smtp0.ethz.ch", 25, "localhost") mailServer.sendmail(email_user, to, msg.as_string()) mailServer.quit()
def run_all(keep_all=False): SystemLogger.info("Running the full eweasel test suite.") _invoke_eweasel(_set_eweasel_env(), _prepare_catalog(None), keep_all)
def make_delivery(): SystemLogger.info("Generating new delivery") eve_version = esvn.info_local_revision_number(v_dir_eve_source) #TODO delivery_name = 'eve_' + str(eve_version) delivery_path = os.path.realpath(os.path.join(v_dir_delivery, delivery_name)) # generate finalized version check_environment_variables() compile_runtime() update_version_number() finalize_eve('bench') revert_version_number() # copy EiffelStudio to delivery destination (this copies the runtime) elocation.copy(os.getenv("ISE_EIFFEL"), delivery_path) # copy finalized eve to delivery destination eve_exe_source = os.path.join(v_dir_eve_source, 'Eiffel', 'Ace', 'EIFGENs', 'bench', 'F_code', d_eve_exe_name) eve_exe_target = os.path.join(delivery_path, 'studio', 'spec', os.getenv("ISE_PLATFORM"), 'bin', d_eve_exe_name) elocation.copy(eve_exe_source, eve_exe_target) # AutoProof: copy update to base library source = os.path.join(v_dir_eve_source, 'library', 'base', 'eve') target = os.path.join(delivery_path, 'library', 'base', 'eve') elocation.copy(source, target) source = os.path.join(v_dir_eve_source, 'library', 'base', 'base2') target = os.path.join(delivery_path, 'library', 'base', 'base2') elocation.copy(source, target) source = os.path.join(v_dir_eve_source, 'library', 'base', 'mml') target = os.path.join(delivery_path, 'library', 'base', 'mml') elocation.copy(source, target) source = os.path.join(v_dir_eve_source, 'library', 'base', 'base-eve.ecf') target = os.path.join(delivery_path, 'library', 'base', 'base-eve.ecf') elocation.copy(source, target) # AutoProof: copy ecf for precompile source = os.path.join(v_dir_eve_source, 'Delivery', 'precomp', 'spec', 'platform', 'base-eve.ecf') target = os.path.join(delivery_path, 'precomp', 'spec', os.getenv("ISE_PLATFORM"), 'base-eve.ecf') elocation.copy(source, target) # AutoProof: copy Boogie files source = os.path.join(v_dir_eve_source, 'Delivery', 'studio', 'tools', 'autoproof') target = os.path.join(delivery_path, 'studio', 'tools', 'autoproof') elocation.copy(source, target) # copy Boogie to delivery destination boogie_target = os.path.join(delivery_path, 'studio', 'tools', 'boogie') elocation.copy(v_dir_boogie, boogie_target) # copy libraries to delivery destination source = os.path.join(v_dir_eve_source, 'library', 'fixing') target = os.path.join(delivery_path, 'library', 'fixing') elocation.copy(source, target) # TODO # copy install/run scripts to destination source = os.path.join(v_dir_eve_source, 'Delivery', 'run_eve.bat') target = os.path.join(delivery_path, 'run_eve.bat') elocation.copy(source, target) source = os.path.join(v_dir_eve_source, 'Delivery', 'run_eve.py') target = os.path.join(delivery_path, 'run_eve.py') elocation.copy(source, target) # generate zip archive archive_path = eutils.compress(delivery_path, delivery_name + "-" + d_ise_platform) delivery_file = os.path.join(v_dir_delivery, os.path.basename(archive_path)) elocation.move(archive_path, delivery_file) # clean up elocation.delete(delivery_path) SystemLogger.success("Delivery " + delivery_name + " finished") # upload zip to server result = None if os.path.exists(v_dir_delivery_remote): remote_file = os.path.join(v_dir_delivery_remote, os.path.basename(delivery_file)) elocation.copy(delivery_file, remote_file) SystemLogger.success("Delivery copied to remote location") result = v_remote_base_url + '/' + os.path.basename(delivery_file) else: if v_dir_delivery_remote != None: SystemLogger.error("Remote location (" + v_dir_delivery_remote + ") does not exist") return result
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")
def precompile (self): SystemLogger.info ("Precompiling Eiffel library.") assert self._ecf == (self._target + ".ecf"), "Target not equal to ECF file." assert self._binary == _append_exe ("driver"), "Wrong binary file name." self._internal_compile ('W_code', ['-clean', '-precompile', '-c_compile']) return self._last_result != None
def finalize (self): SystemLogger.info ("Finalizing Eiffel program.") self._internal_compile ('F_code', ['-target', self._target, '-finalize', '-c_compile']) return self._last_result != None