Beispiel #1
0
    def __init__(self):
        super(MainWidget, self).__init__()

        self.collectionView = QWebView()
        self.collectionView.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
        # self.collectionView.page().setLinkDelegationPolicy(QWebPage.DelegateExternalLinks)
        self.setZoomFactor(QSettings().value("zoom_factor", QVariant(1.0)).toDouble()[0])
        self.connect(self.collectionView, SIGNAL("linkClicked(const QUrl&)"), self.linkClicked)

        layout = QVBoxLayout()
        layout.addWidget(self.collectionView)

        self.smewtd = SmewtDaemon()
        self.smewtd.taskManager.progressChanged.connect(self.progressChanged)

        self.setLayout(layout)

        self.history = []
        self.index = 0
        baseUrl = QSettings().value("base_url").toString()
        if baseUrl == "":
            baseUrl = "smewt://media/speeddial/"
        self.setSmewtUrl(baseUrl)
        # somehow it looks like this refresh is necessary otherwise our main widget doesn't get inserted in the javascript
        self.refreshCollectionView()

        self.externalProcess = QProcess()
Beispiel #2
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 #3
0
class MainWidget(QWidget):
    def __init__(self):
        super(MainWidget, self).__init__()

        self.collectionView = QWebView()
        self.collectionView.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
        # self.collectionView.page().setLinkDelegationPolicy(QWebPage.DelegateExternalLinks)
        self.setZoomFactor(QSettings().value("zoom_factor", QVariant(1.0)).toDouble()[0])
        self.connect(self.collectionView, SIGNAL("linkClicked(const QUrl&)"), self.linkClicked)

        layout = QVBoxLayout()
        layout.addWidget(self.collectionView)

        self.smewtd = SmewtDaemon()
        self.smewtd.taskManager.progressChanged.connect(self.progressChanged)

        self.setLayout(layout)

        self.history = []
        self.index = 0
        baseUrl = QSettings().value("base_url").toString()
        if baseUrl == "":
            baseUrl = "smewt://media/speeddial/"
        self.setSmewtUrl(baseUrl)
        # somehow it looks like this refresh is necessary otherwise our main widget doesn't get inserted in the javascript
        self.refreshCollectionView()

        self.externalProcess = QProcess()

    def progressChanged(self, finished, total):
        if total == 0:
            self.refreshCollectionView()

    def quit(self):
        self.smewtd.quit()

    def setZoomFactor(self, factor):
        self.collectionView.page().mainFrame().setTextSizeMultiplier(factor)

    def zoomIn(self):
        zoomFactor = min(QSettings().value("zoom_factor", QVariant(1.0)).toDouble()[0] + stepZoomFactor, maxZoomFactor)
        QSettings().setValue("zoom_factor", QVariant(zoomFactor))

        self.setZoomFactor(zoomFactor)

    def zoomOut(self):
        zoomFactor = max(QSettings().value("zoom_factor", QVariant(1.0)).toDouble()[0] - stepZoomFactor, minZoomFactor)
        QSettings().setValue("zoom_factor", QVariant(zoomFactor))

        self.setZoomFactor(zoomFactor)

    def back(self):
        self.setSmewtUrl(None, self.index - 1)

    def forward(self):
        self.setSmewtUrl(None, self.index + 1)

    def speedDial(self):
        self.setSmewtUrl(SmewtUrl("media", "speeddial/"))

    def setSmewtUrl(self, url, index=None):
        if index is not None:
            self.index = min(max(index, 0), len(self.history) - 1)
            self.smewtUrl = self.history[self.index]

        else:
            if not isinstance(url, SmewtUrl):
                url = SmewtUrl(url=url)

            self.smewtUrl = url

            self.history[self.index + 1 :] = []
            self.history.append(url)
            self.index = len(self.history) - 1

        QSettings().setValue("base_url", QVariant(unicode(self.smewtUrl)))
        try:
            self.refreshCollectionView()
        except Exception, e:
            import sys, traceback

            log.warning("Exception:\n%s" % "".join(traceback.format_exception(*sys.exc_info())))

            # In case of error, return to the home screen
            log.warning("Returning to Speed Dial view")
            self.speedDial()
Beispiel #4
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