Example #1
0
def db_sync(request,table=''):
    from libs.db import db
    dbIns = db(set='aifang_backup_information')
    sql = "select * from information_schema.tables where table_schema = '"+ table +"' order by create_time desc"
    table_list_result = dbIns.findBySql(sql)
    table_list = [ {'table_schema':item[1],'table_name':item[2],'table_type':item[3],'engine':item[4],'table_row':item[7],'create_time':item[14],'update_time':item[15],'table_comment':item[20]} for item in table_list_result]
    db_info = Db.objects.get(name=table)
    for list in table_list:
        data = Table.objects.filter(table_schema=list['table_schema'],table_name=list['table_name'])
        if data:
            continue
        table_result = Table(table_schema = list['table_schema'],
                             table_name = list['table_name'],
                             table_type = list['table_type'],
                             engine = list['engine'],
                             table_row = list['table_row'],
                             create_time = list['create_time'],
                             update_time = list['update_time'],
                             table_comment = list['table_comment'],
#                             group = db_info.group_id,
                             mygroup_id = db_info.mygroup_id,
                             user = request.user
                             )
        table_result.save()
    message = '恭喜,数据表同步成功!'
    Table.objects.all()
    local_table_list = Table.objects.filter(table_schema=table)
    return render(request,'tools/table_list.html',{'local_table_list':local_table_list,'table':table,'message':message})
Example #2
0
def corrent_accdata(userid):
    '''

    :param userid: user  card's id
    :return:
    '''
    accdata_path = db.db(settings.DATABASEINFO)
    acc_file = '%s/%s.json'%(accdata_path,userid)
    with open(acc_file) as f:
        corrent_accdata = json.load(f)
        return corrent_accdata
Example #3
0
def dump_accdata(data):
    '''

    :param data: user data
    :return:
    '''
    accdata_path = db.db(settings.DATABASEINFO)
    acc_file = '%s/%s.json'%(accdata_path,data['id'])
    with open(acc_file,'w') as f:
        json.dump(data,f)

    return True
Example #4
0
    def importIn(publisher, versionId):
        try:
            locker.lock('setAifangTestDatabaseTo')

            version = DataVersion.objects.get(id=versionId)

            dbIns = db(set='aifang_dev')
            dbIns.importIn(dumpFile(version.name), 'aifangcrm_db')

            version.published = datetime.now()
            version.publisher = publisher
            version.save()

        except:
            # todo
            pass
        finally:
            locker.unlock('setAifangTestDatabaseTo')
Example #5
0
    def generate(generator):
        locker.lock('generateAifangTestData')

        dbIns = db(set='aifang_backup')
        databases = getTablesFromDumpSql()

        # dump 数据到文件
        for (database, table, where) in databases:
            dbIns.dump(dumpFile(versionName()), database, table, where)

        # dump 完成后,压缩
        os.popen("gzip %s -9" % dumpFile(versionName()))

        # 生成版本信息
        DataVersion(
            name=versionName(),
            created=time.strftime("%Y-%m-%d %X", time.localtime()),
            generator=generator
        ).save()

        locker.unlock('generateAifangTestData')
Example #6
0
def auth(userid, password):
    '''
    account libs func
    :param userid: user card id
    :param password: user pasword
    :return:
    '''
    userdbpath = db.db(settings.DATABASEINFO)
    account_file = '%s/%s.json' % (userdbpath, userid)
    # print(account_file)
    if os.path.isfile(account_file):
        with open(account_file) as f:
            account_data = json.load(f)
            if account_data['password'] == password:
                indate = time.mktime(
                    time.strptime(account_data['expire_date'], '%Y-%m-%d'))
                if indate < time.time():
                    print("\033[31;1m your card was out of date\033[0m")
                else:
                    return account_data
            else:
                print('\033[31;1m your id or password incorrect\033[0m')
    else:
        print('\033[31;1maccount [%s] does not exist\033[0m' % userid)
Example #7
0
def stageTimesReport(request):
    requestDict = request.REQUEST
    if not requestDict.has_key('type'):
        type = 'common'
    else:
        type = requestDict['type']


    from libs.db import db
    if not requestDict.has_key("month"):
        month = time.strftime("%Y-%m",time.localtime())
    else:
        month = requestDict['month']
    dbIns = db()
    sql = "select name,created,sha1 from deploy_release_list where `created` > '"+ month + "-00' and `created` <= '"+ month + "-31' order by created asc"

    releaseList = dbIns.findBySql(sql)
    releaseList = [ {'name':item[0],'sha1':item[2],'day':str(item[1].month)+'-'+(((item[1].day<10) and '0'+str(item[1].day)) or str(item[1].day))} for item in releaseList]
    countList = {}
    for item in releaseList:
        if not countList.has_key(item['day']):
            countList[item['day']] = 1
        else:
            countList[item['day']] += 1
    dateList = sorted(countList.keys())
    countList = [[item,countList[item]] for item in dateList]

    data = {}
    if type == 'ajax': #表示ajax传值,直接返回list数据
        import json
        return json.dumps(countList)
    else:
        data['countList'] = countList
        data['channelName'] = 'deploy'
        data['month'] = month
        return render(request,'tools/stagereport.html',{'data':data})
Example #8
0
 def __init__(self):
     self.config = config.getConfig()
     self.db = db(w_db = self.config.site_db_w) 
Example #9
0
#coding:utf-8
from libs.db import db

testdb = db()
cur = testdb.connectdb("./database/minions.db")
testdb.modify(cur,"create table 'manager'('id' INTEGER PRIMARY KEY autoincrement,'username' varhar(20) NOT NULL,'password' char(16) NOT NULL)")
testdb.modify(cur,"insert into manager(username,password) values('admin','e6e061838856bf47e1de730719fb2609')")
Example #10
0
#coding:utf-8
from libs.db import db

testdb = db()
cur = testdb.connectdb("./database/minions.db")
testdb.modify(
    cur,
    "create table 'manager'('id' INTEGER PRIMARY KEY autoincrement,'username' varhar(20) NOT NULL,'password' char(16) NOT NULL)"
)
testdb.modify(
    cur,
    "insert into manager(username,password) values('admin','e6e061838856bf47e1de730719fb2609')"
)
Example #11
0
#!usr/bin/env python
#-*- coding:utf-8 -*-

# author:yangva
# datetime:2018/1/20 0020 15:43

import json, sys, os, datetime

base_dir = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
sys.path.append(base_dir)

from conf import settings
from libs import db

path = db.db(settings.DATABASEINFO)

acc_dic = {
    'id': 123,  #卡号
    'password': '******',  #密码
    'credit': 15000,  #额度
    'balance': 15000,  #余额
    'enroll_date': '2016-01-02',  #注册日期
    'expire_date': '2021-01-01',  #失效日期
    'pay_day': 22,  #还款日
    'status': 0  # 0 = normal, 1 = locked, 2 = disabled
}

id = int(input('\033[36;1menter your user id:\033[0m'))
corrent_path = '%s/%s.json' % (path, id)

acc_dic['id'] = id
Example #12
0
from libs.utils import daemonize, markdown, fetchGithubData, qrToB64, twitterAPI, newBuild, randomcode, buildCheck, webHook
#import libs.wraps.auth as auth
import libs.wraps.misc as misc
import configparser
import libs.db as database

app = flask.Flask(__name__)
socket = SocketIO(app)
config = configparser.ConfigParser()
config.read("auth/auth.cfg")
construction_mode = False
building = False
running = False
updateTime = 3600
PKSM_commits = 0
db = database.db(config['Database']['Address'])


@app.errorhandler(404)
def page_not_found(error):
    nav_projects = database.get_all(db, "repos", "name")
    return flask.render_template('404.html', nav_projects=nav_projects), 404


@app.route('/nav')
@app.route('/base')
@app.route('/project')
@app.route('/graph')
@app.route('/stats')
@app.route('/construction')
@app.route('/extra_saves.html')