Beispiel #1
0
def test_resolve_path():
    """ Test that relative ~, ./ resolve correctly.  Paths are relative to os.getcwd()."""
    path1 = "~/test"
    path2 = "./test"
    target_path1 = os.path.join(HOST_HOME_FOLDER, "test")
    target_path2 = os.path.join(HOST_REPO_PATH, "test")
    assert parse_lib.resolve_path(path1) == target_path1
    assert parse_lib.resolve_path(path2) == target_path2
Beispiel #2
0
def test_resolve_path_relative():
    """Test that relative paths resolved correctly for [link](./relative_path.md)"""

    source_path = os.path.join(TEST_FIXTURES_FOLDER, "source_path1/source1_doc.md")
    test_path = "../source_path2/source2_doc.md"

    resolved_test_path = parse_lib.resolve_path(test_path, source_path=source_path)
    true_test_path = os.path.join(TEST_FIXTURES_FOLDER, "source_path2/source2_doc.md")
    assert resolved_test_path == true_test_path
Beispiel #3
0
 def write(self, path, force=True):
     """Write/save current state of the database to file."""
     path = resolve_path(path)
     path_exists = os.path.exists(path)
     if path_exists and not force:
         raise OSError("file already exists!")
     elif path_exists and force:
         self.df.to_pickle(path)
     elif not path_exists:
         db_folder = os.path.dirname(path)
         os.makedirs(db_folder, exist_ok=True)
         self.df.to_pickle(path)
Beispiel #4
0
 def gen_record(document_id, primary_doc, gen_links):
     """Generate a record from a markdown file."""
     document_id = MarkdownDoc.resolve_id(document_id)
     raw_doc = parse_lib.return_file_contents(document_id)
     raw_links = MarkdownDoc.gen_links(raw_doc) if gen_links else []
     links = []
     for link in raw_links:
         try:
             res_link = parse_lib.resolve_path(link, document_id)
         except AttributeError:
             logger.exception(f"unable to resolve link: {link}")
         if os.path.exists(res_link):
             links.append(res_link)
         else:
             links.append(link)
     record = {
         "document_id": document_id,
         "document_name": document_id,
         "primary_doc": primary_doc,
         "document_type": MarkdownDoc,
         "content": raw_doc,
         "links": links,
     }
     return record
Beispiel #5
0
 def resolve_source_id(source_id):
     return parse_lib.resolve_path(source_id)
Beispiel #6
0
 def resolve_id(document_id):
     return parse_lib.resolve_path(document_id)