def do_download(self, post_data): try: collection_id = post_data['collection_id'] writer = post_data.get('writer', self.default_writer) except KeyError, exc: log.ERROR('POST argument required: %s' % exc) return self.http500()
def _find_collection_dirs_to_purge(collection_dirs, ts): for path in collection_dirs: try: if _path_contains_entry_older_than(path, ts): yield path except OSError as err: if err.errno != errno.ENOENT: log.ERROR("error while examining %r: %s" % (path, err))
def clean_cache(max_age, cache_dir): """Clean all subdirectories of cache_dir whose mtime is before now-max_age @param max_age: max age of directories in seconds @type max_age: int @param cache_dir: cache directory @type cache_dir: basestring """ now = time.time() for d in os.listdir(cache_dir): path = os.path.join(cache_dir, d) if not os.path.isdir(path) or not collection_id_rex.match(d): log.warn('unknown item in cache dir %r: %r' % (cache_dir, d)) continue if now - os.stat(path).st_mtime < max_age: continue try: log.info('removing directory %r' % path) shutil.rmtree(path) except Exception, exc: log.ERROR('could not remove directory %r: %s' % (path, exc))
status = self.read_status_file(collection_id, writer) response = wsgi.Response(content=open(output_path, 'rb')) os.utime(output_path, None) if 'content_type' in status: response.headers['Content-Type'] = status['content_type'].encode('utf-8', 'ignore') else: log.warn('no content type in status file') if 'file_extension' in status: response.headers['Content-Disposition'] = 'inline;filename="collection.%s"' % ( status['file_extension'].encode('utf-8', 'ignore'), ) else: log.warn('no file extension in status file') return response except Exception, exc: log.ERROR('exception in do_download(): %r' % exc) return self.http500() @json_response def do_zip_post(self, post_data): try: metabook_data = post_data['metabook'] base_url = post_data['base_url'] except KeyError, exc: return self.error_response('POST argument required: %s' % exc) template_blacklist = post_data.get('template_blacklist', '') template_exclusion_category = post_data.get('template_exclusion_category', '') login_credentials = post_data.get('login_credentials', '') script_extension = post_data.get('script_extension', '') pod_api_url = post_data.get('pod_api_url', '')
def _rmtree(path): try: shutil.rmtree(path) except OSError as exc: if exc.errno != errno.ENOENT: log.ERROR('could not remove directory %r: %s' % (path, exc))