Example #1
0
def delete(self, *appids):
    from core.base import Base

    result = []
    try:
        engine = Base(settings)
        for rs in engine.remove(*appids):
            if not self.request.called_directly:
                self.update_state(
                    state='PROGRESS',
                    meta={'current': rs}
                )
            result.append(rs)
            rd.hdel('app_record', rs[0])
    except socket.error, e:
        raise self.retry(exc=e)
Example #2
0
    def __init__(self, settings):
        config = dict(
            template_path=os.path.join(os.path.dirname(__file__),
                                       settings.TEMPLATE_ROOT),
            static_path=os.path.join(os.path.dirname(__file__),
                                     settings.STATIC_ROOT),
            cookie_secret="__E720175A1F2957AFD8EC0E7B51275EA7__",
            login_url='/login',
            autoescape=None,
            debug=settings.DEBUG
        )
        Application.__init__(self, handlers, **config)

        conn = S3Connection()
        self.bucket = conn.get_bucket(settings.APK_BUCKET)
        self.redis = redis.Redis(
            host=settings.REDIS_HOST,
            port=settings.REDIS_PORT,
            db=settings.REDIS_DB,
            password=settings.REDIS_PASS
        )

        self.db = MotorReplicaSetClient(
            settings.MONGO_CONNECTION_STRING,
            replicaSet='android'
        )[settings.MONGO_DB]

        self.engine = Base(settings)
        self.api = self.engine.login(async=True)
Example #3
0
    import core.mock

    # Mock all url names so they can be reversed.
    url_names = []
    with open(__file__) as urls:
        for line in urls:
            match = re.search(r'name="(\w+)"', line)
            if match:
                url_names.append(match.groups()[0])
    urlpatterns = [
        path("", core.mock.index, name=url_name) for url_name in url_names
    ]
else:
    from core.base import Base

    BASE = Base()

    MUSIQ_URLS = [
        path("state/", BASE.musiq.get_state, name="musiq_state"),
        path(
            "random_suggestion/",
            BASE.musiq.suggestions.random_suggestion,
            name="random_suggestion",
        ),
        path("request_music/", BASE.musiq.request_music, name="request_music"),
        path("suggestions/",
             BASE.musiq.suggestions.get_suggestions,
             name="suggestions"),
        path("restart/", BASE.musiq.player.restart, name="restart_song"),
        path("seek_backward/",
             BASE.musiq.player.seek_backward,
Example #4
0
"""This module contains all url endpoints and maps them to their corresponding functions."""

import re

from django.urls import include, URLPattern
from django.urls import path
from django.views.generic import RedirectView

from core import mock
from main import settings

from core.base import Base

BASE = Base()

MUSIQ_URLS = [
    path("state/", BASE.musiq.get_state, name="musiq_state"),
    path(
        "random_suggestion/",
        BASE.musiq.suggestions.random_suggestion,
        name="random_suggestion",
    ),
    path("request_music/", BASE.musiq.request_music, name="request_music"),
    path("suggestions/",
         BASE.musiq.suggestions.get_suggestions,
         name="suggestions"),
    path("restart/", BASE.musiq.controller.restart, name="restart_song"),
    path("seek_backward/",
         BASE.musiq.controller.seek_backward,
         name="seek_backward"),
    path("play/", BASE.musiq.controller.play, name="play_song"),
Example #5
0
from django.urls import include
from django.urls import path
from django.contrib import admin
from django.views.generic import RedirectView

import os

if os.environ.get('DJANGO_MOCK'):
    import core.mock
    urlpatterns = [
        path('', core.mock.index),
    ]
else:
    from core.base import Base
    base = Base()

    urlpatterns = [
        path('', RedirectView.as_view(pattern_name='musiq', permanent=False), name='base'),

        path('musiq/', base.musiq.index, name='musiq'),
        path('lights/', base.lights.index, name='lights'),
        path('pad/', base.pad.index, name='pad'),
        path('settings/', base.settings.index, name='settings'),
        path('accounts/', include('django.contrib.auth.urls')),
        path('login/', RedirectView.as_view(pattern_name='login', permanent=False)),
        path('logged_in/', base.logged_in, name='logged_in'),
        path('logout/', RedirectView.as_view(pattern_name='logout', permanent=False)),

        path('ajax/', include([
            path('state/', base.get_state, name='base_state'),
            path('submit_hashtag/', base.submit_hashtag, name='submit_hashtag'),
Example #6
0
def main():
    usage = "Usage: %prog [crawl|worker|fetch|update|remove|add|download|admin|shell] [options] arg"
    parser = OptionParser(usage)
    try:
        cmd = sys.argv[1]
    except IndexError:
        parser.error("incorrect number of arguments")

    parser.add_option("-l", "--loglevel", dest="loglevel",
                      help="log level.")

    if cmd == "crawl":
        from crawler import Detailer, Downloader

        parser.add_option("-a", "--action", dest="action",
                          help="detail or download?")
        options, args = parser.parse_args(args=sys.argv[1:])
        if options.action == "detail":
            c = Detailer(config=settings)
        elif options.action == "download":
            c = Downloader(config=settings)

        c.start()
    elif cmd == "update":
        from core.base import Base

        parser.add_option("-t", "--ptype", dest="ptype",
                          help="paid or free", default="free")
        options, args = parser.parse_args(args=sys.argv[1:])
        engine = Base(settings)
        engine.reschedule(options.ptype)
    elif cmd == 'remove':
        from core.base import Base

        parser.add_option("-a", "--appids", dest="appids",
                          help="app id string")
        options, args = parser.parse_args(args=sys.argv[1:])
        engine = Base(settings)
        [_ for _ in engine.remove(*options.appids.split(','))]
    elif cmd == 'add':
        from core.base import Base

        parser.add_option("-a", "--appid", dest="appid",
                          help="app id string", default="")
        parser.add_option("", "--force", dest="force",
                          help="schedule appid immedite")
        options, args = parser.parse_args(args=sys.argv[1:])
        engine = Base(settings)
        appids = options.appid.split(',')
        n = engine.add(appids, force=options.force)

        print "%d appids scheduled." % n
    elif cmd == 'shell':
        from core.base import Base

        parser.add_option("-u", "--uid", dest="uid",
                          help="use the specifid google user to fetch.")
        options, args = parser.parse_args(args=sys.argv[1:])
        engine = Base(settings)
        engine.shell(options.uid)
    elif cmd == 'fetch':
        """Sync fetch, get detail and download apk file, then save to s3 and mongodb."""
        from core.base import Base

        parser.add_option("-a", "--appid", dest="appid",
                          help="give the appid")
        parser.add_option("-u", "--uid", dest="uid",
                          help="use the specifid google user to fetch.")
        options, args = parser.parse_args(args=sys.argv[1:])
        engine = Base(settings)
        engine.fetch(options.appid, options.uid)

    elif cmd == 'detail':
        from core.base import Base

        parser.add_option("-a", "--appid", dest="appid",
                          help="give the appid")
        options, args = parser.parse_args(args=sys.argv[1:])
        engine = Base(settings)
        engine.detail(options.appid)
    elif cmd == 'download':
        from core.base import Base

        parser.add_option("-a", "--appid", dest="appid",
                          help="give the appid")
        parser.add_option("-d", "--dist", dest="dist",
                          help="relocate the file to distination.")
        options, args = parser.parse_args(args=sys.argv[1:])
        engine = Base(settings)
        engine.download(options.appid, dist=options.dist)
    elif cmd == 'admin':
        from admin import app

        parser.add_option("-H", "--host", dest="host",
                          help="the host for web handler",
                          default=settings.HOST)
        parser.add_option("-P", "--port", dest="port",
                          help="the port for web handler",
                          default=settings.PORT)
        options, args = parser.parse_args(args=sys.argv[1:])
        settings.HOST = options.host
        settings.PORT = options.port
        app.run(settings)
    elif cmd == 'worker':
        from importlib import import_module

        from celery.bin import worker

        parser.add_option("-a", "--app", dest="app",
                          help="specify a celery app")
        parser.add_option("-q", "--queues", dest="queues",
                          help="the queues whole worker handle")
        parser.add_option("-c", "--concurrency", dest="concurrency",
                          help="concurrency number",
                          type=int, default=4)
        options, args = parser.parse_args(args=sys.argv[1:])
        app_module = import_module('.{}'.format(options.app), package='worker')
        if options.queues:
            app_module.c.select_queues(options.queues.split(','))
        task = worker.worker(app=app_module.c)
        opt = {
            'hostname': "celery@{}_{}".format(options.app, options.queues or 'all'),
            'concurrency': options.concurrency,
            'loglevel': 'INFO',
            'traceback': True
        }
        task.run(**opt)