Ejemplo n.º 1
0
 def update(cls, **update):
     cls._meta.database = Database.get_adapter(Database.WRITE)
     return super(Model, cls).update(**update)
Ejemplo n.º 2
0
 def raw(cls, sql, *params):
     cls._meta.database = Database.get_adapter(Database.READ)
     return super(Model, cls).raw(sql, *params)
Ejemplo n.º 3
0
 def select(cls, *selection):
     cls._meta.database = Database.get_adapter(Database.READ)
     return super(Model, cls).select(*selection)
Ejemplo n.º 4
0
# 加入第三方类库搜索路径
sys.path.append(os.path.join(os.path.dirname(__file__), 'modules'))

# 加载程序配置
from wiki import config
from xcat import cache, Database

# 取缓存实例
cache.client = getattr(
    cache, 
    config.settings['xcat_cache'][config.settings['run_mode']]
)()

# 加载数据库配置
Database.load_config(
    config.settings['database'].get(config.settings['run_mode'], False)
)

import xcat.web
import xcat.plugins

from wiki import uimodules

# 加载UImodel
config.settings['ui_modules'] = uimodules

# run app
from wiki.handlers import *
application = xcat.web.Application([], **config.settings)

# 为插件注册 application
Ejemplo n.º 5
0
#coding=utf-8
from peewee import *
from xcat import Database 

Model._meta.database = Database.get_adapter(Database.READ)

class Model(Model):
    """
    基础模型
    """
    class Meta:
        database = Database.get_adapter(Database.READ)

    @classmethod
    def raw(cls, sql, *params):
        cls._meta.database = Database.get_adapter(Database.READ)
        return super(Model,cls).raw(sql, *params)

    @classmethod
    def select(cls, *selection):
        cls._meta.database = Database.get_adapter(Database.READ)
        return super(Model,cls).select(*selection)

    @classmethod
    def update(cls, **update):
        cls._meta.database = Database.get_adapter(Database.WRITE)
        return super(Model,cls).update(**update)

    @classmethod
    def insert(cls, **insert):
        cls._meta.database = Database.get_adapter(Database.WRITE)
Ejemplo n.º 6
0
 def create(cls, **query):
     cls._meta.database = Database.get_adapter(Database.WRITE)
     return super(Model, cls).create(**query)
Ejemplo n.º 7
0
 def save(self, force_insert=False):
     self._meta.database = Database.get_adapter(Database.WRITE)
     return super(Model, self).save(force_insert)
Ejemplo n.º 8
0
 def create(cls, **query):
     cls._meta.database = Database.get_adapter(Database.WRITE)
     return super(Model,cls).create(**query)
Ejemplo n.º 9
0
 def drop_table(cls, fail_silently=False):
     cls._meta.database = Database.get_adapter(Database.WRITE)
     return super(Model,cls).drop_table(fail_silently)
Ejemplo n.º 10
0
 def insert(cls, **insert):
     cls._meta.database = Database.get_adapter(Database.WRITE)
     return super(Model,cls).insert(**insert)
Ejemplo n.º 11
0
 def delete(cls):
     cls._meta.database = Database.get_adapter(Database.WRITE)
     return super(Model,cls).delete()
Ejemplo n.º 12
0
 def update(cls, **update):
     cls._meta.database = Database.get_adapter(Database.WRITE)
     return super(Model,cls).update(**update)
Ejemplo n.º 13
0
 def select(cls, *selection):
     cls._meta.database = Database.get_adapter(Database.READ)
     return super(Model,cls).select(*selection)
Ejemplo n.º 14
0
 def raw(cls, sql, *params):
     cls._meta.database = Database.get_adapter(Database.READ)
     return super(Model,cls).raw(sql, *params)
Ejemplo n.º 15
0
 def insert(cls, **insert):
     cls._meta.database = Database.get_adapter(Database.WRITE)
     return super(Model, cls).insert(**insert)
Ejemplo n.º 16
0
 def save(self, force_insert=False):
     self._meta.database = Database.get_adapter(Database.WRITE)
     return super(Model,self).save(force_insert)
Ejemplo n.º 17
0
 def delete(cls):
     cls._meta.database = Database.get_adapter(Database.WRITE)
     return super(Model, cls).delete()
Ejemplo n.º 18
0
 def on__finish(self):
     # 关闭主从数据库连接
     Database.close()
Ejemplo n.º 19
0
 def drop_table(cls, fail_silently=False):
     cls._meta.database = Database.get_adapter(Database.WRITE)
     return super(Model, cls).drop_table(fail_silently)
Ejemplo n.º 20
0
#coding=utf-8
from peewee import *
from xcat import Database

Model._meta.database = Database.get_adapter(Database.READ)


class Model(Model):
    """
    基础模型
    """
    class Meta:
        database = Database.get_adapter(Database.READ)

    @classmethod
    def raw(cls, sql, *params):
        cls._meta.database = Database.get_adapter(Database.READ)
        return super(Model, cls).raw(sql, *params)

    @classmethod
    def select(cls, *selection):
        cls._meta.database = Database.get_adapter(Database.READ)
        return super(Model, cls).select(*selection)

    @classmethod
    def update(cls, **update):
        cls._meta.database = Database.get_adapter(Database.WRITE)
        return super(Model, cls).update(**update)

    @classmethod
    def insert(cls, **insert):
Ejemplo n.º 21
0
 def on__finish(self):
     # 关闭主从数据库连接
     Database.close()
Ejemplo n.º 22
0
 class Meta:
     database = Database.get_adapter(Database.READ)
Ejemplo n.º 23
0
import sys

# 设置系统编码为utf8
reload(sys)
sys.setdefaultencoding('utf8')

# 加入第三方类库搜索路径
sys.path.append(os.path.join(os.path.dirname(__file__), 'modules'))

# 加载程序配置
from wiki import config
# 引入Database
from xcat import Database

# 加载数据库配置
Database.load_config(config.settings['database'].get(
    config.settings['run_mode'], False))
Database.connect()

import wiki.models
import wiki.models.wiki

for m in dir(wiki.models):
    model = getattr(wiki.models, m)

    if m != 'Model' and str(type(model)) == "<class 'peewee.BaseModel'>":
        if model.table_exists() == False:
            try:
                model.create_table()
            except Exception, e:
                pass
    elif str(type(model)) == "<type 'module'>":
Ejemplo n.º 24
0
reload(sys)
sys.setdefaultencoding("utf8")

# 加入第三方类库搜索路径
sys.path.append(os.path.join(os.path.dirname(__file__), "modules"))

import requests

# 加载程序配置
from wiki import config

# 引入Database
from xcat import Database

# 加载数据库配置
Database.load_config(config.settings["database"].get(config.settings["run_mode"], False))
Database.connect()

from wiki.models import wiki

# 按每个url 3秒超时算, 1分钟要get 20个url
for v in wiki.Task.select().order_by(wiki.Task.level.desc()).limit(20):

    try:
        requests.get(v.url, timeout=2.8)
        print "get %s" % v.url
        # 删除任务
        wiki.Task.delete().where(wiki.Task.id == v.id).execute()
    except Exception, e:
        pass