Esempio n. 1
0
File: Model.py Progetto: BYYY/BA
 def remove(cls, lst):
     if type(lst) == cls:
         DAL.delete_from(cls.table, **lst._working_dict())
     else:
         with DAL.connection():
             for entry in lst:
                 DAL.delete_from(cls.table, **entry._working_dict())
Esempio n. 2
0
File: Model.py Progetto: BYYY/BA
 def add(cls, lst):
     if type(lst) == cls:
         DAL.insert_into(cls.table, **lst._working_dict())
     else:
         # 是否需要保持事务性?
         with DAL.connection():
             for entry in lst:
                 DAL.insert_into(cls.table, **entry._working_dict())
Esempio n. 3
0
def save_html(url, html):
    import base64

    encoded_html = base64.b64encode(html)
    print encoded_html
    with DAL.connection():
        t = Entry.Page(url=url, content=encoded_html)
        Entry.Page.add(t)
        del (t)
Esempio n. 4
0
def save():
    global Q
    with DAL.connection():
        while not Q.empty():
            u = Q.get()
            t = Entry.Url(url=u)
            Entry.Url.add(t)
            del (t)
    print 'all saved!!!!!!!!!!!!!!!!'
    return True
Esempio n. 5
0
File: db_test.py Progetto: BYYY/BA
import src.DB.DAL as DAL
import urllib2
from utils import DBconfig
import src.DB.Entry as Entry

__author__ = "Sapocaly"

config = DBconfig.DBConfig("conf/byyy_ba_db.cfg")
config_args = dict(
    zip(["host", "user", "passwd", "database"], [config.DB_HOST, config.DB_USER, config.DB_PASSWORD, config.DB_NAME])
)
DAL.create_engine(**config_args)


with DAL.connection():
    for i in range(10):
        t = Entry.Page(url="test_url", content="test_content")
        Entry.Page.add(t)
        del (t)

with DAL.transaction():
    Entry.Page.remove(Entry.Page.get())
Esempio n. 6
0
import src.DB.Entry as Entry
import src.DB.DAL as DAL


from utils import DBconfig



Q = Queue.Queue()
S = set()

config = DBconfig.DBConfig("conf/byyy_ba_db.cfg")
config_args = dict(zip(['host', 'user', 'passwd', 'database'],
                           [config.DB_HOST, config.DB_USER, config.DB_PASSWORD, config.DB_NAME]))
DAL.create_engine(**config_args)

def save():
    global Q
    with DAL.connection():
        while not Q.empty():
            u = Q.get()
            t = Entry.Url(url=u)
            Entry.Url.add(t)
            del (t)
    print 'all saved!!!!!!!!!!!!!!!!'
    return True


def put(url):
    try:
Esempio n. 7
0
File: Model.py Progetto: BYYY/BA
 def get(cls, **args):
     selection = DAL.select_from(cls.table, **args)
     # 获取entry信息,创建新instance,initialize,生成list
     return [cls(**dict(zip(cls.fields, entry))) for entry in selection]
Esempio n. 8
0
File: Model.py Progetto: BYYY/BA
 def save(self):
     DAL.update(self.__class__.table, **self)
     for key in self.__class__.fields:
         self[key] = self['_' + key]