def save(self): # load and update, since an execution might have written additional fields to the file since initialization run_data = self.__load_data(self._run_file_path) run_data.update({ "result": self.result.name if self.result else None, "runtime": self.runtime, "message": self.message, "md5": self.detector.md5 }) write_yaml(run_data, file=self._run_file_path)
def __save_run_info(self, result, runtime, message, detector_md5): # load and update, since an execution might have written additional fields to the file since initialization run_info = self.__load_run_info() run_info.update({ "result": result.name, "runtime": runtime, "message": message, "md5": detector_md5 }) write_yaml(run_info, file=self._run_file_path) self.__run_info = run_info
def test_writes_object(self): class T: def __init__(self): self.f = 42 data = write_yaml({"foo": T().__dict__}) assert_equals("foo:\n f: 42\n", data)
def _prepare_example_projects(target_type: str, boa: BOA, metadata_path: str): data = [] for type in [target_type] + _get_subtypes(target_type): projects = boa.query_projects_with_type_usages(target_type, type) for project in projects: checkout = project.get_checkout(CHECKOUTS_PATH) if not checkout.exists(): try: logger.info(" Checking out %r...", str(project)) checkout.create() except CommandFailedError as error: logger.warning(" Checkout failed: %r", error) checkout.delete() continue else: logger.info(" Already checked out %r.", str(project)) try: project_entry = { "id": project.id, "url": project.repository_url, "path": os.path.relpath(checkout.checkout_dir, MUBENCH_ROOT_PATH), "source_paths": Project(checkout.checkout_dir).get_sources_paths() } write_yaml(project_entry) data.append(project_entry) except UnicodeEncodeError: logger.warning(" Illegal characters in project data.") if len(data) >= MAX_PROJECT_SAMPLE_SIZE: logger.warning(" Stopping after %r of %r example projects.", MAX_PROJECT_SAMPLE_SIZE, len(projects)) write_yamls(data, metadata_path) return write_yamls(data, metadata_path)
def save(self, current_timestamp: int): compile_info = {VersionCompile.__KEY_TIMESTAMP: current_timestamp} write_yaml(compile_info, self._compile_info_file)
logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) handler.setLevel(logging.DEBUG) logger.addHandler(handler) example_projects_by_API = {} with open(INDEX_PATH) as index: for row in csv.reader(index, delimiter="\t"): # skip blank lines, e.g., on trailing newline if not row: continue target_type = row[6] try: if target_type not in example_projects_by_API: logger.info("Preparing examples for type: %s...", target_type) target_example_file = os.path.join(CHECKOUTS_PATH, target_type + ".yml") example_projects = {} with open_yamls_if_exists(target_example_file) as projects: for project in projects: hash = Shell.exec( "cd \"{}\"; git rev-parse HEAD".format( join(MUBENCH_ROOT_PATH, project["path"]))) example_projects[project["url"]] = hash.strip() example_projects_by_API[target_type] = example_projects except Exception as error: logger.exception("failed", exc_info=error) write_yaml(example_projects_by_API, join(CHECKOUTS_PATH, "example_projects_by_API.yml"))
def create(self, current_timestamp: int) -> None: self._create() checkout_info = {ProjectCheckout.__KEY_TIMESTAMP: current_timestamp} write_yaml(checkout_info, self._checkout_info_file)
def setup_releases(self, releases): releases_index = join(self.temp_dir, self.detector_id, Detector.RELEASES_FILE) write_yaml(releases, releases_index)
def test_writes_dot_graph(self): data = write_yaml( {"graph": "digraph \"foo\" {\n 1 [label=\"A\"]\n}\n"}) assert_equals( "graph: |\n digraph \"foo\" {\n 1 [label=\"A\"]\n }\n", data)
def test_writes_multiline_in_dict_in_list(self): data = write_yaml({"foo": [{"a": "b\n"}]}) assert_equals("foo:\n- a: |\n b\n", data)
def test_writes_multiline_in_list(self): data = write_yaml({"foo": ["a\n"]}) assert_equals("foo:\n- |\n a\n", data)
def test_writes_multiline_in_dict(self): data = write_yaml({"foo": {"bar": "a\n"}}) assert_equals("foo:\n bar: |\n a\n", data)
def test_writes_multiline(self): data = write_yaml({"foo": "a\nb\n"}) assert_equals("foo: |\n a\n b\n", data)
def test_writes_single_line(self): data = write_yaml({"foo": "oneliner"}) assert_equals("foo: oneliner\n", data)
def save(self, timestamp: int): misuse_compile_info = {self.__TIMESTAMP_KEY: timestamp} write_yaml(misuse_compile_info, self._misuse_compile_file)
def write_run_file(self, run_data): write_yaml( run_data, join(self.findings_path, DetectorMode.mine_and_detect.name, self.detector.id, self.version.project_id, self.version.version_id, DetectorExecution.RUN_FILE))