diff --git a/data/schema.cfg b/data/schema.cfg index 11083568319..41ebc4f2b64 100644 --- a/data/schema.cfg +++ b/data/schema.cfg @@ -91,7 +91,7 @@ difficulties="required symbol list" difficulty_descriptions="required string" #TODO: this one's especially complicated extra_defines="optional string list" - first_scenario="required identifier" + first_scenario="required identifier need-file-in(scenarios)" icon="optional pathimage" id="required string" image="optional path" @@ -394,7 +394,7 @@ # TODO: _generator=... id="required string" - next_scenario="required string" # TODO: Can be improved to check if the scenario file really exists + next_scenario="required string need-file-in(.)" description="optional string translatable" name="required string translatable" map_data="required string" # TODO: Complex case diff --git a/data/tools/wmlvalidator b/data/tools/wmlvalidator index edbc12df3e4..e81facd1b81 100755 --- a/data/tools/wmlvalidator +++ b/data/tools/wmlvalidator @@ -92,14 +92,31 @@ class Validator: self.validate_result_add(node.file, node.line, "Attribute [%s] %s%s" % (verbosename, attribute.name, gerate_message_with_pos()), "Value should be %s, found: %s" % (attribute.type, value)) regex_limit = re.compile(ur'^limit\((\d+.\d+|\d+),(\d+.\d+|\d+)\)$') - checklimit = [i for i in attribute.optionals if regex_limit.search(i)] - if len(checklimit): - checklimit = checklimit[0] - number_min, number_max = regex_limit.search(checklimit).groups() + check_limit = [i for i in attribute.optionals if regex_limit.search(i)] + if len(check_limit): + check_limit = check_limit[0] + number_min, number_max = regex_limit.search(check_limit).groups() if float(value) > float(number_max) or float(value) < float(number_min): self.validate_result_add(node.file, node.line, "Attribute [%s] %s%s" % (verbosename, attribute.name, gerate_message_with_pos()), "Value must be between %s and %s, found : %s" % (number_min, number_max, value)) + regex_file_exist = re.compile(ur'^need-file-in\(([\w.\-\/]+)\)$') + check_file_exist = [i for i in attribute.optionals if regex_file_exist.search(i)] + if len(check_file_exist): + check_file_exist = check_file_exist[0] + directory = regex_file_exist.search(check_file_exist).group(1) + + import glob + if directory == '.': + sub_directory = os.path.dirname(node.file) + '/' + else: + sub_directory = os.path.dirname(node.file) + '/' + directory + '/' + + files_from_sub_directory = glob.glob(sub_directory + '*') + files_from_sub_directory = [re.sub(re.compile(r'^.*\/(.*)\..*'), r'\1', i) for i in files_from_sub_directory] + if not value in files_from_sub_directory: + self.validate_result_add(node.file, node.line, "Attribute [%s] %s%s" % (verbosename, attribute.name, gerate_message_with_pos()), "The file %s not exist in directory %s" % (value, sub_directory)) + if 'list' in attribute.optionals: pos = 1 for i in match.data.split(","):