Skip to content
Snippets Groups Projects
Commit b9818e07 authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

MAINT: removed parts that modify readmes; not needed in this context

parent bc3ccff1
No related branches found
No related tags found
No related merge requests found
......@@ -33,20 +33,6 @@ import yaml
from .cfood import AbstractCFood, get_entity
TEMPLATEHEADER = """
---
title: {title}
location:
author:
participants:
date: {date}
keywords:
tags:
category:
...
"""
def _clean_header(header):
# Fill empty fields with empty string
......@@ -74,7 +60,7 @@ class NoValidHeader(Exception):
super().__init__(msg, *args, **kwargs)
def get_header(filename, add_header=True):
def get_header(filename):
"""Open an md file identified by filename and read out the yaml
header.
......@@ -156,47 +142,7 @@ it is not at the beginning, it must be preceded by a blank line.
return (found_1, found_2, _clean_header(yaml_part))
if not add_header:
raise NoValidHeader(filename)
else:
print("Adding header in: {fn}".format(fn=filename))
_add_header(filename)
return get_header(filename)
def get_date_and_title_from_name(filename):
dir_re = re.compile('(?P<title>.+)\.(?P<date>[0-9\-]+)')
file_re = re.compile('(?P<title>.+)\.(?P<date>[0-9\-]+)\.md')
if os.path.basename(filename).lower() == "readme.md":
for part in os.path.abspath(filename).split(os.path.sep):
m = dir_re.match(part)
if m is not None:
break
else:
m = file_re.match(filename)
if m is not None:
return m.group("date"), m.group("title")
else:
return "", ""
def _add_header(filename):
"""
Add a header to an md file. Date and title are guessed from the filename.
"""
with open(filename) as f:
textlines = f.readlines()
date, title = get_date_and_title_from_name(filename)
localheader = TEMPLATEHEADER.format(date=str(date), title=title)
with open(filename, "w") as f:
f.write(localheader)
f.writelines(textlines)
raise NoValidHeader(filename)
def parse_responsibles(header):
"""
......@@ -207,10 +153,12 @@ def parse_responsibles(header):
If it is a simple string, it is added as the only person.
"""
people = []
if type(header["responsible"]) == list:
resplist = header["responsible"]
else:
resplist = [header["responsible"]]
for person in header["responsible"]:
firstname = person.split(" ")[0]
lastname = person.split(" ")[1]
......@@ -225,9 +173,11 @@ def parse_responsibles(header):
def reference_data_files(entity, header, prefix=""):
referenced_files = []
for glob in get_data_glob(header):
if not glob.startswith("/"):
glob = os.path.normpath(os.path.join(prefix, glob))
for dfile in find_file_for_fileglob(glob):
if dfile is not None:
referenced_files.append(dfile)
......@@ -242,11 +192,13 @@ def get_data_glob(header):
else:
raise Exception("no suitable header fields")
globs = []
for el in header[name]:
if isinstance(el, dict) and "filename" in el:
globs.append(el["filename"])
else:
globs.append(el)
return globs
......@@ -254,6 +206,7 @@ def find_file_for_fileglob(glob):
# TODO this probalby needs to be extended for different kinds of glob
query_string = "FIND file which is stored at {}".format(glob)
print(query_string)
return db.execute_query(query_string)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment