raise ex.BadMapfileError(
self.uf['filename'], archive_path(yaml_file), exp)
- def check_tag(self, errors, yaml_file, count, file_map, tag):
+ def check_tag(self, errors, yaml_file, count, file_map, tag,
+ required=True, string=True):
'''Confirm that the tag exists and holds a string;
remove the tag from the map
'''
try:
- if not isinstance(file_map[tag], str):
+ if not isinstance(file_map[tag], str) and string:
errors.append(ex.MustBeStringError(
archive_path(yaml_file), count, tag, file_map[tag]))
except KeyError:
- errors.append(ex.MissingFileMapTagError(
- archive_path(yaml_file), count, tag))
+ if required:
+ errors.append(ex.MissingFileMapTagError(
+ archive_path(yaml_file), count, tag))
else:
del file_map[tag]
for key in map_item:
errors.append(execp(archive_path(yaml_file), count, key))
- def validate_file_map(self, errors, yaml_file, count, file_map):
+ def validate_key_existance(self, errors, yaml_file, count, file_map):
'''Confirm that a file_map contains the right tags, if not
add to errors
'''
my_file_map = file_map.copy()
self.check_tag(errors, yaml_file, count, my_file_map, 'file')
self.check_tag(errors, yaml_file, count, my_file_map, 'relation')
+ self.check_tag(
+ errors, yaml_file, count, my_file_map, 'trim',
+ required=False, string=False)
self.extra_tags(errors, yaml_file, count, my_file_map,
ex.ExtraFileMapTagError)
+ def validate_values(self, errors, yaml_file, count, file_map):
+ '''Confirm that a file_map contains the right tag values, if not
+ add to errors
+ (Only used for values that are not a string.)
+ '''
+ if 'trim' in file_map:
+ value = file_map['trim']
+ if not isinstance(value, bool):
+ errors.append(ex.BadTrimValueError(
+ archive_path(yaml_file), count, value))
+
+ def validate_file_map(self, errors, yaml_file, count, file_map):
+ '''Confirm that a file_map contains the right tags, if not
+ add to errors
+ '''
+ self.validate_key_existance(errors, yaml_file, count, file_map)
+ self.validate_values(errors, yaml_file, count, file_map)
+
def validate_map_item(self, errors, yaml_file, count, map_item):
'''Confirm that a map_item is a dict with the right tags, if not
add to errors
if errors:
raise core_ex.MultiError(errors)
+ def _trim(self, fmap):
+ '''Should the file be trimmed?
+ '''
+ if 'trim' in fmap:
+ return fmap['trim']
+ else:
+ return self.uf['trim_upload']
+
def get_filedata(self, dir_name, file_map):
'''Return a list of UploadData instances or raise an error
uf['null_rep'],
name,
fmap['relation'],
- trim=uf['trim_upload']))
+ trim=self._trim(fmap)))
except core_ex.PGWUIError as exp:
relation = fmap['relation']
errors.append(exp.color(map_description(name, relation),