Added the optional parameter "need-file-in(dir)", to check if the file exists

This commit is contained in:
Bruno Macabeus 2015-08-30 23:39:31 -03:00 committed by Elvish_Hunter
parent 71b4d75f15
commit a0c882b02d
2 changed files with 23 additions and 6 deletions

View file

@ -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

View file

@ -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(","):