Beispiel #1
0
def main():
    """ This function returns a Pyramid WSGI application."""
    settings = { 'pyramid.reload_templates': smewt.config.RELOAD_MAKO_TEMPLATES,
                 'pyramid.debug_authorization':  False,
                 'pyramid.debug_notfound': False,
                 'pyramid.debug_routematch':  False,
                 'pyramid.default_locale_name': 'en',
                 'pyramid.includes': 'pyramid_debugtoolbar' if smewt.config.PYRAMID_DEBUGTOOLBAR else ''
                 }

    from smewt.base import SmewtDaemon
    smewt.SMEWTD_INSTANCE = SmewtDaemon()

    atexit.register(SmewtDaemon.quit, smewt.SMEWTD_INSTANCE)

    config = Configurator(settings=settings)
    config.add_static_view('static', 'smewt:static', cache_max_age=3600)
    config.add_static_view('user', smewt.dirs.user_data_dir, cache_max_age=3600)

    config.add_route('home', '/')
    config.add_route('speeddial', '/speeddial')
    config.add_route('media', '/media')
    config.add_route('feeds', '/feeds')
    config.add_route('tvu', '/tvu')

    config.add_route('movies_table', '/movies/table')
    config.add_route('recent_movies', '/movies/recent')
    config.add_route('unwatched_movies', '/movies/unwatched')
    config.add_route('all_movies', '/movies')
    config.add_route('movie', '/movie/{title}')
    config.add_route('no_movie', '/movie')

    config.add_route('all_series', '/series')
    config.add_route('series_suggestions', '/series/suggestions')
    config.add_route('series', '/series/{title}')

    config.add_route('config_get', '/config/get/{name}')
    config.add_route('config_set', '/config/set/{name}')

    config.add_route('action', '/action/{action}')
    config.add_route('info', '/info/{name}')

    config.add_route('preferences', '/preferences')
    config.add_route('controlpanel', '/controlpanel')


    config.scan('smewt')
    app = config.make_wsgi_app()


    from waitress import serve
    serve(app, host='0.0.0.0', port=6543)
Beispiel #2
0
    def testSmewtDaemon(self):
        # we need to remove traces of previous test runs, even though we're supposed to have cleaned it after the test,
        # a previous run of the test that failed might not have done that
        os.system('rm -fr ~/.config/Falafelton_tmp')
        os.system('rm -fr /tmp/smewt_test_daemon')

        import smewt
        orgname = smewt.ORG_NAME
        appname = smewt.APP_NAME

        smewt.ORG_NAME = 'Falafelton_tmp'
        smewt.APP_NAME = 'Smewt_tmp'

        from PyQt4.QtCore import QCoreApplication
        app = QCoreApplication([])
        app.setOrganizationName(smewt.ORG_NAME)
        app.setOrganizationDomain('smewt.com')
        app.setApplicationName(smewt.APP_NAME)

        smewtd = SmewtDaemon()

        # create fake database
        cmds = '''mkdir -p /tmp/smewt_test_daemon/Monk
        touch /tmp/smewt_test_daemon/Monk/Monk.2x05.Mr.Monk.And.The.Very,.Very.Old.Man.DVDRip.XviD-MEDiEVAL.[tvu.org.ru].avi
        touch /tmp/smewt_test_daemon/Monk/Monk.2x05.Mr.Monk.And.The.Very,.Very.Old.Man.DVDRip.XviD-MEDiEVAL.[tvu.org.ru].English.srt
        '''
        for cmd in cmds.split('\n'):
            os.system(cmd.strip())

        smewtd.episodeCollection.folders = { '/tmp/smewt_test_daemon': True }

        # make sure we don't have a residual collection from previous test runs
        self.assertEqual(len(list(smewtd.database.nodes())), 0)

        # initial import of the collection
        smewtd.episodeCollection.rescan()
        smewtd.taskManager.queue.join() # wait for all import tasks to finish

        #smewtd.database.display_graph()
        self.collectionTestIncomplete(smewtd.database)

        # update collection, as we haven't changed anything it should be the same
        smewtd.episodeCollection.update()
        smewtd.taskManager.queue.join() # wait for all import tasks to finish

        #smewtd.database.display_graph()
        self.collectionTestIncomplete(smewtd.database)

        # fully rescan collection, should still be the same
        smewtd.episodeCollection.rescan()
        smewtd.taskManager.queue.join() # wait for all import tasks to finish

        #smewtd.database.display_graph()
        self.collectionTestIncomplete(smewtd.database)

        # add some more files
        cmds = '''mkdir -p /tmp/smewt_test_daemon/Monk
        touch /tmp/smewt_test_daemon/Monk/Monk.2x06.Mr.Monk.Goes.To.The.Theater.DVDRip.XviD-MEDiEVAL.[tvu.org.ru].avi
        touch /tmp/smewt_test_daemon/Monk/Monk.2x06.Mr.Monk.Goes.To.The.Theater.DVDRip.XviD-MEDiEVAL.[tvu.org.ru].English.srt
        '''
        for cmd in cmds.split('\n'):
            os.system(cmd.strip())

        # update collection
        smewtd.episodeCollection.update()
        smewtd.taskManager.queue.join() # wait for all import tasks to finish

        #smewtd.database.display_graph()
        self.collectionTest(smewtd.database)

        # clean up our mess before we exit
        os.system('rm -fr ~/.config/Falafelton_tmp')
        os.system('rm -fr /tmp/smewt_test_daemon')

        smewt.ORG_NAME = orgname
        smewt.APP_NAME = appname