Skip to content

Commit

Permalink
Case-insensitive rules, and gear list filters
Browse files Browse the repository at this point in the history
  • Loading branch information
kofalt committed Apr 12, 2017
1 parent 3207499 commit e543522
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
8 changes: 7 additions & 1 deletion api/jobs/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ def get(self):
if self.public_request:
self.abort(403, 'Request requires login')

return get_gears()
gears = get_gears()
filters = self.request.GET.getall('filter')

if 'single_input' in filters:
gears = list(filter(lambda x: len(x["gear"]["inputs"].keys()) <= 1, gears))

return gears

class GearHandler(base.RequestHandler):
"""Provide /gears/x API routes."""
Expand Down
15 changes: 11 additions & 4 deletions api/jobs/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,37 @@ def eval_match(match_type, match_param, file_, container):
Given a match entry, return if the match succeeded.
"""

def lower(x):
return x.lower()


# Match the file's type
if match_type == 'file.type':
try:
return file_['type'] == match_param
return file_['type'].lower() == match_param.lower()
except KeyError:
_log_file_key_error(file_, container, 'has no type key')
return False

# Match a shell glob for the file name
elif match_type == 'file.name':
return fnmatch.fnmatch(file_['name'], match_param)
return fnmatch.fnmatch(file_['name'].lower(), match_param.lower())

# Match any of the file's measurements
elif match_type == 'file.measurements':
try:
return match_param in file_['measurements']
if match_param:
return match_param.lower() in map(lower, file_.get('measurements', []))
else:
return False
except KeyError:
_log_file_key_error(file_, container, 'has no measurements key')
return False

# Match the container having any file (including this one) with this type
elif match_type == 'container.has-type':
for c_file in container['files']:
if match_param == c_file.get('type'):
if match_param.lower() == c_file.get('type').lower():
return True

return False
Expand Down
2 changes: 1 addition & 1 deletion test/unit_tests/python/test_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_eval_match_file_measurements():
assert result == False

# Check match returns false without raising when not given a file.type
args = part.gen(file_={'a': 'b'}, container={'a': 'b'})
args = part.gen(file_={'a': 'b'}, match_param='', container={'a': 'b'})
result = rules.eval_match(*args)
assert result == False

Expand Down

0 comments on commit e543522

Please sign in to comment.