def index_content(root_dir, file_types, content_type): """ Scan the media directory, creating an index of file properties for display and serving """ logger.debug('indexing') hasher = sha1() content_dir = os.path.join(root_dir, app.config['CONTENT_DIR']) files = file_paths(filtered_walk( content_dir, included_files=file_types, )) for contentfile in files: rel_path = os.path.relpath(contentfile, root_dir) filepath = os.path.join(root_dir, rel_path) filename = os.path.split(contentfile)[1] local_path = os.path.relpath(filepath, root_dir) if os.path.exists(os.path.join(filepath, 'folder.jpg')): img = os.path.join(filepath, 'folder.jpg') else: img = '' hasher.update(local_path) file_key = hasher.hexdigest() tags = _get_tags(filepath) media = Media() media.type = content_type media.path = filepath media.filename = filename media.file_id = file_key media.tags = tags media.img = img media.type = content_type media.save()
def index_content(root_dir, file_types, content_type): """ Scan the media directory, creating an index of file properties for display and serving """ logger.debug('indexing') hasher = sha1() content_dir = os.path.join(root_dir, app.config['CONTENT_DIR']) files = file_paths(filtered_walk(content_dir, included_files=file_types, )) for contentfile in files: rel_path = os.path.relpath(contentfile, root_dir) filepath = os.path.join(root_dir, rel_path) filename = os.path.split(contentfile)[1] local_path = os.path.relpath(filepath, root_dir) if os.path.exists(os.path.join(filepath, 'folder.jpg')): img = os.path.join(filepath, 'folder.jpg') else: img = '' hasher.update(local_path) file_key = hasher.hexdigest() tags = _get_tags(filepath) media = Media() media.type = content_type media.path = filepath media.filename = filename media.file_id = file_key media.tags = tags media.img = img media.type = content_type media.save()