flexget.plugins.module_change_warn
Covered: 73 lines
Missed: 28 lines
Skipped 37 lines
Percent: 72 %
  1
import logging
  2
import os
  3
from flexget.manager import Session
  4
from flexget.plugin import register_plugin
  6
log = logging.getLogger('change')
  7
found_deprecated = False
 10
class ChangeWarn(object):
 11
    """
 12
        Gives warning if user has deprecated / changed configuration in the root level.
 14
        Will be replaced by root level validation in the future!
 16
        Contains ugly hacks, better to include all deprecation warnings here during 1.0 BETA phase
 17
    """
 19
    def __init__(self):
 20
        self.warned = False
 22
    def old_database(self, feed, reason='', solution=''):
 23
        if not self.warned:
 24
            feed.manager.disable_feeds()
 25
            feed.abort()
 26
            log.critical('You\'re running old database! Please see \'Upgrade Actions\' at flexget.com for necessary actions!')
 27
            self.warned = True
 28
        if reason:
 29
            log.critical('Reason     : %s' % reason)
 30
        if solution:
 31
            log.critical('Please run : %s' % solution)
 33
    def on_process_start(self, feed):
 34
        found_deprecated = False
 35
        config = feed.manager.config
 37
        if 'torrent_size' in feed.config:
 38
            log.critical('Plugin torrent_size is deprecated, use content_size instead')
 39
            found_deprecated = True
 41
        if 'nzb_size' in feed.config:
 42
            log.critical('Plugin nzb_size is deprecated, use content_size instead')
 43
            found_deprecated = True
 46
        allow = ['feeds', 'presets', 'variables']
 47
        for key in config.iterkeys():
 48
            if key not in allow:
 49
                log.critical('Keyword \'%s\' is not allowed in the root level of configuration!' % key)
 52
        if isinstance(feed.config.get('priority', None), dict):
 53
            log.critical('Plugin \'priority\' was renamed to \'plugin_priority\'')
 56
        from flexget.utils.sqlalchemy_utils import table_columns, table_exists
 58
        session = Session()
 60
        columns = table_columns('imdb_movies', session)
 61
        if not 'photo' in columns:
 62
            self.old_database(feed, 'photo missing from imdb_movies table')
 63
        if not 'updated' in columns:
 64
            self.old_database(feed, 'updated missing from imdb_movies table',
 65
                'sqlite3 %s "ALTER TABLE imdb_movies ADD updated DateTime;"' % feed.manager.db_filename)
 66
        if not 'mpaa_rating' in columns:
 67
            self.old_database(feed, 'mpaa_rating missing from imdb_movies table',
 68
                'sqlite3 %s "ALTER TABLE imdb_movies ADD mpaa_rating VARCHAR;"' % feed.manager.db_filename)
 70
        columns = table_columns('make_rss', session)
 71
        if not 'rsslink' in columns:
 72
            self.old_database(feed, 'rsslink missing from make_rss table')
 74
        columns = table_columns('imdb_queue', session)
 75
        if not 'title' in columns:
 76
            self.old_database(feed, 'title missing from imdb_queue table')
 78
        if table_exists('episode_qualities', session):
 79
            self.old_database(feed, 'old series format)')
 81
        columns = table_columns('thetvdb_favorites', session)
 82
        if not 'series_id' in columns:
 83
            self.old_database(feed, 'series_id missing from thetvdb_favorites table',
 84
                'sqlite3 %s "ALTER TABLE thetvdb_favorites ADD series_id VARCHAR;"' % feed.manager.db_filename)
 86
        if found_deprecated:
 87
            feed.manager.disable_feeds()
 88
            feed.abort()
 90
        session.close()
 92
register_plugin(ChangeWarn, 'change_warn', builtin=True)
 95
try:
 96
    import sys
 97
    import os.path
 98
    plugin_dir = os.path.normpath(sys.path[0] + '/../flexget/plugins/')
 99
    for name in os.listdir(plugin_dir):
100
        require_clean = False
101
        if 'resolver' in name:
102
            require_clean = True
104
        if 'filter_torrent_size' in name:
105
            require_clean = True
107
        if 'filter_nzb_size' in name:
108
            require_clean = True
110
        if 'module_priority' in name:
111
            require_clean = True
113
        if 'ignore_feed' in name:
114
            require_clean = True
116
        if 'module_manual' in name:
117
            require_clean = True
119
        if 'output_exec' in name:
120
            require_clean = True
122
        if 'plugin_adv_exec' in name:
123
            require_clean = True
125
        if 'output_transmissionrpc' in name:
126
            require_clean = True
128
        if require_clean:
129
            log.critical('-' * 79)
130
            log.critical('IMPORTANT: Please remove all pre-compiled .pyc and .pyo files from')
131
            log.critical('           path: %s' % plugin_dir)
132
            log.critical('           After this FlexGet should run again normally')
133
            log.critical('-' * 79)
134
            found_deprecated = True
135
            break
136
except:
137
    pass