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)
Example #2
0
 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
Example #3
0
    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)
Example #4
0
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)
Example #5
0
 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"))
Example #7
0
 def create(self, current_timestamp: int) -> None:
     self._create()
     checkout_info = {ProjectCheckout.__KEY_TIMESTAMP: current_timestamp}
     write_yaml(checkout_info, self._checkout_info_file)
Example #8
0
 def setup_releases(self, releases):
     releases_index = join(self.temp_dir, self.detector_id,
                           Detector.RELEASES_FILE)
     write_yaml(releases, releases_index)
Example #9
0
 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)
Example #10
0
 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)
Example #11
0
 def test_writes_multiline_in_list(self):
     data = write_yaml({"foo": ["a\n"]})
     assert_equals("foo:\n- |\n  a\n", data)
Example #12
0
 def test_writes_multiline_in_dict(self):
     data = write_yaml({"foo": {"bar": "a\n"}})
     assert_equals("foo:\n  bar: |\n    a\n", data)
Example #13
0
 def test_writes_multiline(self):
     data = write_yaml({"foo": "a\nb\n"})
     assert_equals("foo: |\n  a\n  b\n", data)
Example #14
0
 def test_writes_single_line(self):
     data = write_yaml({"foo": "oneliner"})
     assert_equals("foo: oneliner\n", data)
Example #15
0
 def save(self, timestamp: int):
     misuse_compile_info = {self.__TIMESTAMP_KEY: timestamp}
     write_yaml(misuse_compile_info, self._misuse_compile_file)
Example #16
0
 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))