예제 #1
0
def test_add_remove_eps():
    cache = Cache(":memory:")
    cache.recreate_cache()

    eps, spc = make_series()

    Settings["db_update"] = 7

    cache.add_show("test show", eps, spc)

    eps = cache.get_episodes("test show")

    spc = filter(lambda x: x.is_special, eps)
    eps = filter(lambda x: not x.is_special, eps)

    for count, e in enumerate(eps):
        name = "Episode {}".format(count)  # single ascii letter name

        assert e.title == name
        assert e.number == count
        assert e.season == 1

    for count, s in enumerate(spc):
        s_name = "Special {}".format(count)
        assert s.title == s_name
        assert s.number == count

    cache.remove_show(1)
    cache.close()
예제 #2
0
def test_bad_get_episodes():
    cache = Cache(":memory:")

    assert_raises(ValueError, cache.get_episodes, showTitle=None)
    assert_raises(ValueError, cache.get_episodes, showTitle={})
    assert_raises(ValueError, cache.get_episodes, showTitle=[])
    assert_equal(cache.get_episodes(showTitle="FAKE"), [])
    assert_equal(cache.get_episodes(showTitle="test"), [])

    cache.close()
예제 #3
0
def test_bad_get_episodes():
    cache = Cache(':memory:')

    assert_raises(ValueError, cache.get_episodes, showTitle=None)
    assert_raises(ValueError, cache.get_episodes, showTitle={})
    assert_raises(ValueError, cache.get_episodes, showTitle=[])
    assert_equal(cache.get_episodes(showTitle="FAKE"), [])
    assert_equal(cache.get_episodes(showTitle="test"), [])

    cache.close()
예제 #4
0
def test_update_old_entry():
    cache = Cache(":memory:")
    cache.recreate_cache()

    eps, spc = make_series()

    cache.add_show("test show", eps, spc)

    eps = cache.get_episodes("test show", -1)

    cache.close()
예제 #5
0
def test_update_old_entry():
    cache = Cache(":memory:")
    cache.recreate_cache()

    eps, spc = make_series()

    cache.add_show("test show", eps, spc)

    eps = cache.get_episodes("test show", -1)

    cache.close()
예제 #6
0
def test_good_connection():
    cache = Cache(":memory:")

    assert cache is not None
    assert cache.connection is not None

    with cache.connection as conn:
        conn.execute("CREATE TABLE test (id INTEGER PRIMARY KEY);")
        conn.execute("INSERT INTO test VALUES (1)")
        conn.execute("INSERT INTO test VALUES (2)")
        curs = conn.execute("INSERT INTO test VALUES (3)")
        assert curs.lastrowid == 3

    cache.close()

    try:
        cache.cursor.execute("SELECT * FROM test")
        assert False  # Database should be scrapped
    except:
        assert True  # Database was successfully destroyed
예제 #7
0
def test_good_connection():
    cache = Cache(':memory:')

    assert cache is not None
    assert cache.connection is not None

    with cache.connection as conn:
        conn.execute("CREATE TABLE test (id INTEGER PRIMARY KEY);")
        conn.execute("INSERT INTO test VALUES (1)")
        conn.execute("INSERT INTO test VALUES (2)")
        curs = conn.execute("INSERT INTO test VALUES (3)")
        assert curs.lastrowid == 3

    cache.close()

    try:
        cache.cursor.execute("SELECT * FROM test")
        assert False  # Database should be scrapped
    except:
        assert True  # Database was successfully destroyed
예제 #8
0
def test_bad_add_show_eps():
    cache = Cache(":memory:")
    cache.recreate_cache()

    eps, spc = make_series()

    assert_raises(ValueError, cache.add_show, showTitle="", episodes=eps)
    assert_raises(ValueError, cache.add_show, showTitle=None, episodes=None)
    assert_raises(ValueError, cache.add_show, showTitle="Show", episodes=None)
    assert_raises(ValueError,
                  cache.add_show,
                  showTitle="Show",
                  episodes="Title")
    assert_raises(ValueError, cache.add_show, showTitle="Title", episodes=[])
    assert_raises(ValueError, cache.add_show, showTitle="Title", episodes={})
    assert_raises(ValueError,
                  cache.add_show,
                  showTitle="test",
                  episodes=(1, 3))

    ## Specials
    assert_raises(ValueError, cache.add_show, showTitle=None, specials=None)
    assert_raises(ValueError, cache.add_show, showTitle="Show", specials=None)
    assert_raises(ValueError,
                  cache.add_show,
                  showTitle="Show",
                  specials="Title")
    assert_raises(ValueError, cache.add_show, showTitle="Title", specials=[])
    assert_raises(ValueError,
                  cache.add_show,
                  showTitle="Title",
                  specials={'title': 't'})
    assert_raises(ValueError, cache.add_show, showTitle="test", specials=[])

    cache.close()
예제 #9
0
def test_bad_add_show_eps():
    cache = Cache(":memory:")
    cache.recreate_cache()

    eps, spc = make_series()

    assert_raises(ValueError, cache.add_show, showTitle="", episodes=eps)
    assert_raises(ValueError, cache.add_show, showTitle=None, episodes=None)
    assert_raises(ValueError, cache.add_show, showTitle="Show", episodes=None)
    assert_raises(ValueError, cache.add_show, showTitle="Show", episodes="Title")
    assert_raises(ValueError, cache.add_show, showTitle="Title", episodes=[])
    assert_raises(ValueError, cache.add_show, showTitle="Title", episodes={})
    assert_raises(ValueError, cache.add_show, showTitle="test", episodes=(1, 3))

    ## Specials
    assert_raises(ValueError, cache.add_show, showTitle=None, specials=None)
    assert_raises(ValueError, cache.add_show, showTitle="Show", specials=None)
    assert_raises(ValueError, cache.add_show, showTitle="Show", specials="Title")
    assert_raises(ValueError, cache.add_show, showTitle="Title", specials=[])
    assert_raises(ValueError, cache.add_show, showTitle="Title", specials={"title": "t"})
    assert_raises(ValueError, cache.add_show, showTitle="test", specials=[])

    cache.close()
예제 #10
0
def main():
    cmd = argparse.ArgumentParser(description="Renames your TV shows",
                                  prog='eplist',
                                  usage='%(prog)s --help [options] title')

    cmd.add_argument('title',
                     default="",
                     nargs='?',
                     help="The title of the show")

    cmd.add_argument('-d',
                     '--display-header',
                     action="store_true",
                     help="Display the header at the top of the output")

    cmd.add_argument('-v',
                     '--verbose',
                     action="store_true",
                     help="Be verbose, enable additional output")

    cmd.add_argument('-s',
                     '--season',
                     default="",
                     type=str,
                     metavar='N',
                     help="The specific season range to search for. Ex: 1-3")

    cmd.add_argument('-e',
                     '--episode',
                     default="",
                     type=str,
                     metavar='N',
                     help="The specific episode range to search for Ex: 15-30")

    cmd.add_argument(
        '-f',
        '--format',
        dest="format",
        metavar='F',
        help="Rename the files in a directory with a custom format")

    cmd.add_argument('-g',
                     '--gui-enabled',
                     action="store_true",
                     help="Use the gui rather than the command line")

    group = cmd.add_mutually_exclusive_group()

    group.add_argument('-r',
                       '--rename',
                       dest='pathname',
                       metavar="PATH",
                       help="Rename the files in the path provided")

    group.add_argument('-u',
                       '--undo-rename',
                       action='store_true',
                       help="Undo the last rename operation")

    cmd.add_argument('--delete-cache',
                     action="store_true",
                     help="Delete the cache file and create a new one")

    cmd.add_argument(
        '--update-db',
        action="store_true",
        help="Update the AniDB titles file, limit to once a day due to size")

    cmd.add_argument(
        '--verify',
        action="store_true",
        help="Verify the checksums in the filename if they are present")

    cmd.add_argument('--filter',
                     choices=['episodes', 'specials', 'both'],
                     help="Filters episodes based on type (default=both)")

    args = cmd.parse_args()

    if 'title' in args:
        Settings.title = args.title
    else:
        Settings.title = ""

    # Set the correct working path
    if args.pathname:
        Settings.path = os.path.realpath(args.pathname)
    else:
        Settings.path = os.path.realpath(os.getcwd())

    # If we are acting on files then load the old names into memory
    if args.pathname or args.undo_rename:
        utils.load_renamed_file()

    if args.filter:
        Settings.filter = args.filter

    cache = Cache(Settings.db_name)
    atexit.register(cache.close)

    if args.delete_cache:
        cache.recreate_cache()

    if Settings.title in ('-', '.', 'pwd'):
        # If a dash is entered use the current basename of the path
        Settings.title = os.path.split(os.getcwd())[1]
        print("Searching for {}".format(Settings.title))

    if args.verbose:
        Settings.verbose = True
        l = logging.getLogger()
        for handle in l.handlers:
            handle.setLevel(logging.NOTSET)
        l.setLevel(logging.NOTSET)

    if args.gui_enabled:
        from .gui.gui import main
        exit(main())

    if args.update_db:
        utils.update_db()

    if args.undo_rename:
        do_rename(utils.find_old_filenames(Settings.path, Settings.title))
        sys.exit(0)

    rename = args.pathname is not None

    if rename and not os.path.exists(args.pathname):
        sys.exit("ERROR - Path provided does not exist")

    if not Settings.title:
        cmd.print_usage()
        sys.exit(1)

    episodeParser = ShowFinder(Settings.title, cache)

    show = episodeParser.getShow()
    formatter = episode.EpisodeFormatter(show, args.format)
    show.formatter = formatter

    if not show.episodes:
        sys.exit(1)

    # If the user specified a specific season we will filter our results
    # this also checks to make sure its a reasonable season number
    eps = filter_episodes(show, args.season, args.episode)

    show.add_episodes(eps)

    ## Renaming functionality
    if rename:
        do_rename(utils.prepare_filenames(Settings.path, show))
        sys.exit(0)

    if args.verify:
        files = utils.clean_filenames(Settings.path)

        verify_files(files)
        sys.exit(1)

    if Settings.filter in ('both', 'episodes'):
        display_episodes(show, show.episodes, args.display_header)

    if Settings.filter in ('specials', 'both'):
        display_specials(show, args.display_header)
예제 #11
0
__author__ = 'Dan Tracy'
__email__ = 'djt5019 at gmail dot com'

import os
import logging

from PySide import QtGui, QtCore

from eplist.show_finder import ShowFinder
from eplist.episode import Show, EpisodeFormatter
from eplist.cache import Cache
from eplist.settings import Settings

from eplist import utils

cache = Cache(Settings.db_name)
show_locater = ShowFinder(cache=cache)
utils.load_renamed_file()

Settings.title = ""

## Snuff the console output for the gui


class UpdateDisplaySignal(QtCore.QObject):
    update_directory = QtCore.Signal()
    update_episodes = QtCore.Signal()


class Window(QtGui.QMainWindow):
    def __init__(self, parent=None):
예제 #12
0
def main():
    cmd = argparse.ArgumentParser(description="Renames your TV shows",
                        prog='eplist', usage='%(prog)s --help [options] title')

    cmd.add_argument('title', default="", nargs='?',
        help="The title of the show")

    cmd.add_argument('-d', '--display-header', action="store_true",
        help="Display the header at the top of the output")

    cmd.add_argument('-v', '--verbose', action="store_true",
        help="Be verbose, enable additional output")

    cmd.add_argument('-s', '--season', default="", type=str, metavar='N',
        help="The specific season range to search for. Ex: 1-3")

    cmd.add_argument('-e', '--episode', default="", type=str, metavar='N',
        help="The specific episode range to search for Ex: 15-30")

    cmd.add_argument('-f', '--format', dest="format", metavar='F',
        help="Rename the files in a directory with a custom format")

    cmd.add_argument('-g', '--gui-enabled', action="store_true",
        help="Use the gui rather than the command line")

    group = cmd.add_mutually_exclusive_group()

    group.add_argument('-r', '--rename', dest='pathname', metavar="PATH",
        help="Rename the files in the path provided")

    group.add_argument('-u', '--undo-rename', action='store_true',
        help="Undo the last rename operation")

    cmd.add_argument('--delete-cache', action="store_true",
        help="Delete the cache file and create a new one")

    cmd.add_argument('--update-db', action="store_true",
        help="Update the AniDB titles file, limit to once a day due to size")

    cmd.add_argument('--verify', action="store_true",
        help="Verify the checksums in the filename if they are present")

    cmd.add_argument('--filter', choices=['episodes', 'specials', 'both'],
        help="Filters episodes based on type (default=both)")

    args = cmd.parse_args()

    if not os.path.exists(constants.resource_path):
        utils.init_resource_folder()

    logger.init_logging()

    atexit.register(utils.save_last_access_times)
    atexit.register(logger.shutdown_logging)

    if 'title' in args:
        Settings.title = args.title
    else:
        Settings.title = ""

    # Set the correct working path
    if args.pathname:
        Settings.path = os.path.realpath(args.pathname)
    else:
        Settings.path = os.path.realpath(os.getcwd())

    # If we are acting on files then load the old names into memory
    if args.pathname or args.undo_rename:
        utils.load_renamed_file()

    if args.filter:
        Settings.filter = args.filter

    cache = Cache(Settings.db_name)
    atexit.register(cache.close)

    if args.delete_cache:
        cache.recreate_cache()

    if Settings.title in ('-', '.', 'pwd'):
        # If a dash is entered use the current basename of the path
        Settings.title = os.path.split(os.getcwd())[1]
        print("Searching for {}".format(Settings.title))

    if args.verbose:
        Settings.verbose = True
        l = logging.getLogger()
        for handle in l.handlers:
            handle.setLevel(logging.NOTSET)
        l.setLevel(logging.NOTSET)

    if args.gui_enabled:
        from .gui.gui import main
        exit(main())

    if args.update_db:
        utils.update_db()

    if args.undo_rename:
        do_rename(utils.find_old_filenames(Settings.path, Settings.title))
        sys.exit(0)

    rename = args.pathname is not None

    if rename and not os.path.exists(args.pathname):
        sys.exit("ERROR - Path provided does not exist")

    if not Settings.title:
        cmd.print_usage()
        sys.exit(1)

    episodeParser = ShowFinder(Settings.title, cache)

    show = episodeParser.getShow()
    formatter = episode.EpisodeFormatter(show, args.format)
    show.formatter = formatter

    if not show.episodes:
        sys.exit(1)

    # If the user specified a specific season we will filter our results
    # this also checks to make sure its a reasonable season number
    eps = filter_episodes(show, args.season, args.episode)

    show.add_episodes(eps)

    ## Renaming functionality
    if rename:
        do_rename(utils.prepare_filenames(Settings.path, show))
        sys.exit(0)

    if args.verify:
        files = utils.clean_filenames(Settings.path)

        verify_files(files)
        sys.exit(1)

    if Settings.filter in ('both', 'episodes'):
        display_episodes(show, show.episodes, args.display_header)

    if Settings.filter in ('specials', 'both'):
        display_specials(show, args.display_header)
예제 #13
0
def test_add_remove_eps():
    cache = Cache(":memory:")
    cache.recreate_cache()

    eps, spc = make_series()

    Settings['db_update'] = 7

    cache.add_show("test show", eps, spc)

    eps = cache.get_episodes("test show")

    spc = filter(lambda x: x.is_special, eps)
    eps = filter(lambda x: not x.is_special, eps)

    for count, e in enumerate(eps):
        name = "Episode {}".format(count)  # single ascii letter name

        assert e.title == name
        assert e.number == count
        assert e.season == 1

    for count, s in enumerate(spc):
        s_name = "Special {}".format(count)
        assert s.title == s_name
        assert s.number == count

    cache.remove_show(1)
    cache.close()