""" import glob import logging import os from oslo_config import cfg from seedbox.common import tools from seedbox import constants from seedbox.db import models from seedbox.torrent import parser LOG = logging.getLogger(__name__) cfg.CONF.import_group('torrent', 'seedbox.options') COMPRESSED_TYPES = tools.format_file_ext(cfg.CONF.torrent.compressed_filetypes) VIDEO_TYPES = tools.format_file_ext(cfg.CONF.torrent.video_filetypes) def load_torrents(dbapi): """Loads torrents into database. Find all the torrents in the specified directory, verify it is a valid torrent file (via parsing) and capture the relevant details. Next create a record in the cache for each torrent. """ for torrent_file in glob.glob(os.path.join(cfg.CONF.torrent.torrent_path, '*.torrent')): # get the entry in the cache or creates it if it doesn't exist
def test_format_file_ext(self): self.assertIsInstance(tools.format_file_ext([]), list) self.assertEqual(len(tools.format_file_ext([])), 0) self.assertIsInstance(tools.format_file_ext(''), list) self.assertEqual(len(tools.format_file_ext('')), 0) self.assertIsInstance(tools.format_file_ext([' ']), list) self.assertEqual(len(tools.format_file_ext([' '])), 0) self.assertIsInstance(tools.format_file_ext(None), list) self.assertEqual(len(tools.format_file_ext(None)), 0) self.assertEqual( len(tools.format_file_ext(['.avi', None, '.mp4', None, ''])), 2) self.assertEqual(len(tools.format_file_ext(['.avi', '.mp4'])), 2) self.assertEqual(len(tools.format_file_ext(['avi', 'mp4'])), 2) self.assertEqual(len(tools.format_file_ext(['avi', '.mp4'])), 2) self.assertEqual(len(tools.format_file_ext(['.avi', 'mp4'])), 2) for ext in ['.avi', '.mp4', 'avi', 'mp4']: ext_list = tools.format_file_ext([ext]) self.assertEqual(len(ext_list[0]), 4)