diff --git a/ptulsconv/commands.py b/ptulsconv/commands.py index 3b2f4de..9eb0dcf 100644 --- a/ptulsconv/commands.py +++ b/ptulsconv/commands.py @@ -152,7 +152,8 @@ def convert(input_file, output_format='fmpxml', output=sys.stdout, warnings=True if warnings: for warning in chain(validate_unique_field(lines, - field='cue_number'), + field='cue_number', + scope='title'), validate_non_empty_field(lines, field='cue_number'), validate_non_empty_field(lines, @@ -175,15 +176,3 @@ def convert(input_file, output_format='fmpxml', output=sys.stdout, warnings=True create_adr_reports(lines, tc_display_format=session_tc_format, reel_list=sorted(reels)) - # elif output_format == 'csv': - # dump_csv(parsed['events']) - # - - # elif output_format == 'fmpxml': - # if xsl is None: - # dump_fmpxml(parsed, input_file, output, adr_field_map) - # else: - # print_section_header_style("Performing XSL Translation") - # print_status_style("Using builtin translation: %s" % xsl) - # fmp_transformed_dump(parsed, input_file, xsl, output) - diff --git a/ptulsconv/validations.py b/ptulsconv/validations.py index 72e6fbe..7579369 100644 --- a/ptulsconv/validations.py +++ b/ptulsconv/validations.py @@ -29,14 +29,20 @@ def validate_value(input_lines: Iterator[ADRLine], key_field, predicate): event=event) -def validate_unique_field(input_lines: Iterator[ADRLine], field='cue_number'): - values = set() +def validate_unique_field(input_lines: Iterator[ADRLine], field='cue_number', scope=None): + values = dict() for event in input_lines: this = getattr(event, field) - if this in values: + if scope is not None: + key = getattr(event, scope) + else: + key = '_values' + + values.setdefault(key, set()) + if this in values[key]: yield ValidationError(message='Re-used {}'.format(field), event=event) else: - values.update(this) + values[key].update(this) def validate_non_empty_field(input_lines: Iterator[ADRLine], field='cue_number'):