def remove_old_tmp_files(profiles=None, max_lifetime=(<NUM_LIT:7> * <NUM_LIT>)):
assert isinstance(profiles, (list, tuple)) or profiles is None<EOL>if profiles is None:<EOL><INDENT>profiles = dju_settings.DJU_IMG_UPLOAD_PROFILES.keys()<EOL><DEDENT>profiles = set(('<STR_LIT:default>',) + tuple(profiles))<EOL>total = removed = <NUM_LIT:0><EOL>old_dt = datetime.datetime.utcnow() - datetime.timedelta(hours=max_lifetime)<EOL>for profile in profiles:<EOL><INDENT>conf = get_profile_configs(profile=profile)<EOL>root_path = os.path.join(settings.MEDIA_ROOT, dju_settings.DJU_IMG_UPLOAD_SUBDIR, conf['<STR_LIT>'])<EOL>for file_path in get_files_recursive(root_path):<EOL><INDENT>m = re_tmp.match(os.path.basename(file_path))<EOL>if m is None:<EOL><INDENT>continue<EOL><DEDENT>total += <NUM_LIT:1><EOL>fdt = dtstr_to_datetime(m.group('<STR_LIT>'))<EOL>if fdt and old_dt > fdt:<EOL><INDENT>os.remove(file_path)<EOL>removed += <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>return removed, total<EOL>
Removes old temp files that is older than expiration_hours.
If profiles is None then will be use all profiles.