instead of mainconfig the specifier value is now saved in a field with the name SPECIERFIERFIELD

This commit is contained in:
Bela 2018-07-16 11:25:00 +02:00
parent f0a3d09d8a
commit b9084b7493
2 changed files with 17 additions and 19 deletions

View file

@ -51,6 +51,7 @@ VARIABLE_PARTS_SEP = "|"
VARIABLE_DEFAULT_SEP = "#"
NON_FORMFIELD = "Nonfield"
CONFIGFIELD = "Mainconfig"
SPECIFIERFIELD = "Specifier"
OUTPUTFIELD = "Outputconfig"
FORMOUTPUTFIELD = "Formoutputconfig"
ON = ["Ja", "On", "ja"]

View file

@ -58,6 +58,7 @@ import commands
import formfield
import readformdata
from constants import (NON_FORMFIELD, CONFIGFIELD, OUTPUTFIELD,
SPECIFIERFIELD,
FORMOUTPUTFIELD, SUBINFO_SEP, ConfigError,
GENERALADVICE, EPILOG)
import writetopdf
@ -152,10 +153,12 @@ def readDataPaths(configs, maindir="."):
Configs is a list of FormFields.
In the configs there can be a field with the FieldName "Mainconfig".
This can specify with the info Data and the data specifier-Path
paths for data to be found in.
If this path is a file, try to use that file for this data.
If this path is a directory, search for a file that gives this
data. This is the case if the mainconfig of this other form file
specifies that is to be called this name in the info "Specifier".
data. This is the case if the config value SPECIFIERFIELD
of this other form file
specifies that is to be called this name.
Attributes:
configs ([FormField]):
@ -219,8 +222,8 @@ def findDataFile(directory, specifier):
Attributes:
directory (str): directory in which to be searched.
specifier (str):
the file searched for has the info "Specifier" with the value
specifier in the field with the FieldName "Mainconfig"
the file searched for has the Field SPECIFIERFIELD with the value
specifier.
Returns:
a list of fields from this file.
@ -231,6 +234,8 @@ def findDataFile(directory, specifier):
"""
for dirpath, _, files in os.walk(directory):
print("debug: directory:", directory)
if ".git" in dirpath:
continue
print("debug: dirpath:", dirpath)
print("debug: files:", files)
for datafile in files:
@ -253,22 +258,14 @@ def findDataFile(directory, specifier):
"attempting to understand",
filepath + ":",
str(e))
try:
mainconfig = formfield.FormField.findByFieldName(
datalist, CONFIGFIELD,
include=lambda fi: NON_FORMFIELD in fi)
except KeyError:
print("debug", datafile, "has no mainconfig")
else:
try:
if mainconfig["Specifier"] == specifier:
if getConfigvalue(fieldname=SPECIFIERFIELD,
fields=datalist,
argument=None,
default=None) == specifier:
return datalist
else:
print("debug:", datafile,
"has mainconfig but wrong specifier")
except KeyError:
print("debug:", datafile,
"has no specifier in mainconfig")
print("debug:", datafile, "has no or wrong specifier.")
# if none found
print("debug: no file for", specifier, "found.")
raise ConfigError("I looked for a data file for the specifier " +