Skip to content

Commit

Permalink
Merge 82f435d into 524d45b
Browse files Browse the repository at this point in the history
  • Loading branch information
aschroed committed Jan 3, 2019
2 parents 524d45b + 82f435d commit 1e3c93b
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions chalicelib/checks/wrangler_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,15 +468,25 @@ def change_in_item_counts(connection, **kwargs):
return check


@check_function(search_add_on=None)
@check_function(file_type=None, status=None, file_format=None, search_add_on=None)
def identify_files_without_filesize(connection, **kwargs):
check = init_check_res(connection, 'identify_files_without_filesize')
# must set this to be the function name of the action
check.action = "patch_file_size"
search_query = ('search/?type=File&status=released%20to%20project'
'&status=released&status=uploaded&frame=object')
if kwargs.get('search_add_on'):
search_query = ''.join([search_query, kwargs['search_add_on']])
default_filetype = 'File'
default_stati = 'released%20to%20project&status=released&status=uploaded&status=pre-release'
filetype = kwargs.get('file_type') or default_filetype
stati = 'status=' + (kwargs.get('status') or default_stati)
search_query = 'search/?type={}&{}&frame=object'.format(filetype, stati)
ff = kwargs.get('file_format')
if ff is not None:
ff = '&file_format.file_format=' + ff
search_query += ff
addon = kwargs.get('search_add_on')
if addon is not None:
if not addon.startswith('&'):
addon = '&' + addon
search_query += addon
problem_files = []
file_hits = ff_utils.search_metadata(search_query, ff_env=connection.ff_env, page_limit=200)
for hit in file_hits:
Expand All @@ -488,13 +498,24 @@ def identify_files_without_filesize(connection, **kwargs):
'upload_key': hit.get('upload_key')
}
problem_files.append(hit_dict)
check.brief_output = '{} files with no file size'.format(len(problem_files))
check.full_output = problem_files
if problem_files:
check.status = 'WARN'
check.summary = 'File metadata found without file_size'
check.description = "One or more files that are released/released to project/uploaded don't have file_size."
status_str = 'pre-release/released/released to project/uploaded'
if kwargs.get('status'):
status_str = kwargs.get('status')
type_str = ''
if kwargs.get('file_type'):
type_str = kwargs.get('file_type') + ' '
ff_str = ''
if kwargs.get('file_format'):
ff_str = kwargs.get('file_format') + ' '
check.description = "{cnt} {type}{ff}files that are {st} don't have file_size.".format(
cnt=len(problem_files), type=type_str, st=status_str, ff=ff_str)
check.action_message = "Will attempt to patch file_size for %s files." % str(len(problem_files))
check.allow_action = True # allows the action to be run
check.allow_action = True # allows the action to be run
else:
check.status = 'PASS'
return check
Expand Down

0 comments on commit 1e3c93b

Please sign in to comment.