本文整理汇总了Python中model.DBSession.commit方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.commit方法的具体用法?Python DBSession.commit怎么用?Python DBSession.commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.DBSession
的用法示例。
在下文中一共展示了DBSession.commit方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FlushofGamelist
# 需要导入模块: from model import DBSession [as 别名]
# 或者: from model.DBSession import commit [as 别名]
def FlushofGamelist(self):
''' No.1 clear table of gamelist '''
localgamelist = DBSession.query(GameList).all()
if len(localgamelist) != 0:
for eachlist in range(len(localgamelist)):
DBSession.delete(localgamelist[eachlist])
DBSession.commit()
''' No.2 analyst Config and create conn '''
self.getConfig = readFromConfigFile().get_config_zonelist('/WebserviceInterface/ServiceConfig/setting.ini')
for eachTuple in range(len(self.getConfig['Zonelist'])):
if self.getConfig['Zonelist'][eachTuple][0] == 'username':
self.change['username'] = self.getConfig['Zonelist'][eachTuple][1]
elif self.getConfig['Zonelist'][eachTuple][0] == 'password':
self.change['password'] = self.getConfig['Zonelist'][eachTuple][1]
elif self.getConfig['Zonelist'][eachTuple][0] == 'ipaddress':
self.change['ipaddress'] = self.getConfig['Zonelist'][eachTuple][1]
elif self.getConfig['Zonelist'][eachTuple][0] == 'port':
self.change['port'] = int(self.getConfig['Zonelist'][eachTuple][1])
elif self.getConfig['Zonelist'][eachTuple][0] == 'dbname':
self.change['dbname'] = self.getConfig['Zonelist'][eachTuple][1]
elif self.getConfig['Zonelist'][eachTuple][0] == 'tablename':
self.change['tablename'] = self.getConfig['Zonelist'][eachTuple][1]
(conn, cursor) = Connect().create(self.change)
sql = 'select * from %s' % self.change['tablename']
cursor.execute(sql)
result=cursor.fetchall()
for i in result:
print i
示例2: create_entry
# 需要导入模块: from model import DBSession [as 别名]
# 或者: from model.DBSession import commit [as 别名]
def create_entry(data):
"""Write data to database
"""
data = map_data(data)
entry = Entry(date=datetime.now(), **data)
DBSession.add(entry)
DBSession.commit()
log.debug("Write entry %r", data)
示例3: flush
# 需要导入模块: from model import DBSession [as 别名]
# 或者: from model.DBSession import commit [as 别名]
def flush(self, oracleCursor):
# execute in oracle VIEW
oracleCursor.execute('select * from MEP_ASSETREPORT')
self.all = self.cursor.fetchall()
for eachline in range(len(self.all)):
DBSession.add(ASSET(eachline, self.all[eachline][1], self.all[eachline][2], self.all[eachline][3], self.all[eachline][4], self.all[eachline][5], self.all[eachline][6], self.all[eachline][7], self.all[eachline][8], self.all[eachline][9], self.all[eachline][10], self.all[eachline][11], self.all[eachline][13], self.all[eachline][14], self.all[eachline][15], self.all[eachline][17], self.all[eachline][22]))
DBSession.commit()
示例4: set_password
# 需要导入模块: from model import DBSession [as 别名]
# 或者: from model.DBSession import commit [as 别名]
def set_password(self, new_password):
salt = random_str()
password_md5 = md5(new_password.encode('utf-8')).hexdigest()
password_final = md5((password_md5 + salt).encode('utf-8')).hexdigest()
session = DBSession()
self.salt = salt
self.password = password_final
session.add(self)
session.commit()
示例5: new
# 需要导入模块: from model import DBSession [as 别名]
# 或者: from model.DBSession import commit [as 别名]
def new(cls, username, password):
salt = random_str()
password_md5 = md5(password.encode('utf-8')).hexdigest()
password_final = md5((password_md5 + salt).encode('utf-8')).hexdigest()
level = USER_LEVEL.ADMIN if cls.count() == 0 else USER_LEVEL.NORMAL # 首个用户赋予admin权限
the_time = int(time.time())
session = DBSession()
ret = cls(username=username, password=password_final, salt=salt, level=level, key=random_str(32),
key_time = the_time, reg_time = the_time)
session.add(ret)
session.commit()
return ret
示例6: new
# 需要导入模块: from model import DBSession [as 别名]
# 或者: from model.DBSession import commit [as 别名]
def new(cls, username, password):
username = username.lower()
salt = random_str()
password_md5 = md5(password.encode('utf-8')).hexdigest()
password_final = md5((password_md5 + salt).encode('utf-8')).hexdigest()
state = USER_STATE.ADMIN if cls.count() == 0 else USER_STATE.NORMAL # first user is admin
the_time = int(time.time())
session = DBSession()
ret = cls(username=username, password=password_final, salt=salt, state=state, key=random_str(32),
key_time = the_time, reg_time = the_time)
session.add(ret)
session.commit()
return ret
示例7: Recovery
# 需要导入模块: from model import DBSession [as 别名]
# 或者: from model.DBSession import commit [as 别名]
def Recovery(self):
localAsset = DBSession.query(ASSET).all()
if len(localAsset) > 100:
for eachAsset in range(len(localAsset)):
DBSession.delete(localAsset[eachAsset])
DBSession.commit()
self.flush(self.cursor)
else:
self.flush(self.cursor)
self.cursor.close()
self.OracleConn.close()
示例8: getFlushoftable
# 需要导入模块: from model import DBSession [as 别名]
# 或者: from model.DBSession import commit [as 别名]
def getFlushoftable(self, signal='ALL'):
# No.1 clear table of gamename
localGameName = DBSession.query(Gameinform).all()
if len(localGameName) != 0:
for eachGamename in range(len(localGameName)):
DBSession.delete(localGameName[eachGamename])
DBSession.commit()
# No.2 get each Game information & fill in table
self.flush = Urlex().getInformationMultiple(signal)
for key,value in self.flush.items():
if key != 'NULL':
DBSession.add(Gameinform(self.count, key, value['ipaddress'], value['port'], value['dbname']))
self.count += 1
DBSession.commit()
示例9: crawling
# 需要导入模块: from model import DBSession [as 别名]
# 或者: from model.DBSession import commit [as 别名]
def crawling(company_short_name):
param = {'first': 'false', 'pn': 0, 'kd': ''}
param = {'first': 'false', 'pn': page, 'sortField': 0, 'havemark': 0}
log = "[{}]\t抓取第 {} 页完毕, 当前页职位个数{}, 累计已抓{}, 该公司总计{}"
count = 0
for i in range(max_iter):
param['pn'] += 1
req = requests.post(job_url, data=param)
info = json.loads(req.content)
total_count = int(info['content']['positionResult']['totalCount'])
job_list = info['content']['positionResult']['result']
count += len(job_list)
print log.format(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), param['pn'],
len(job_list), count, total_count)
session = DBSession()
for job in job_list:
c = Job(
company_id=company.get("companyId"),
company_full_name=company.get("companyFullName"),
company_short_name=company.get("companyShortName"),
city=company.get("city"),
position_num=company.get("positionNum"),
city_score=company.get("cityScore"),
finance_stage=company.get("financeStage"),
industry_field=company.get("industryField"),
country_score=company.get("countryScore"),
company_features=company.get("companyFeatures"),
process_rate=company.get("processRate"),
interview_remark_num=company.get("interviewRemarkNum"),
approve=company.get("approve"),
create_time=datetime.now()
)
session.add(c)
session.commit()
session.close()
time.sleep(3)
if len(job_list) == 0: break
return count
示例10: refresh_key
# 需要导入模块: from model import DBSession [as 别名]
# 或者: from model.DBSession import commit [as 别名]
def refresh_key(self):
session = DBSession()
self.key = random_str(32)
self.key_time = int(time.time())
session.add(self)
session.commit()
示例11: DetailforEachOid
# 需要导入模块: from model import DBSession [as 别名]
# 或者: from model.DBSession import commit [as 别名]
#.........这里部分代码省略.........
if tmpZCBM == '':
return dict(Status='False', msg='Input Server has not ZCBM.')
''' get eth detail '''
tmpEthDict = {}
for key,value in tmpEthInfo.items():
if key == 'eth0':
getSearchofeth = DBSession.query(Ethdetail).filter(Ethdetail.ip == value['ip'], Ethdetail.mask == value['mask']).first()
if getSearchofeth:
tmpEthDict['eth0'] = getSearchofeth.eid
else:
getethcount = DBSession.query(Ethdetail).count()
getethcount = (getethcount + 1)
DBSession.add(Ethdetail(getethcount,value['status'],value['ip'],value['mask'],'eth0'))
tmpEthDict['eth0'] = getethcount
elif key == 'eth1':
getSearchofethone = DBSession.query(Ethdetail).filter(Ethdetail.ip == value['ip'], Ethdetail.mask == value['mask']).first()
if getSearchofethone:
tmpEthDict['eth1'] = getSearchofethone.eid
else:
getethcountone = DBSession.query(Ethdetail).count()
getethcountone = (getethcountone + 1)
DBSession.add(Ethdetail(getethcountone,value['status'],value['ip'],value['mask'],'eth1'))
tmpEthDict['eth1'] = getethcountone
''' Step 2. check server information exist. '''
getSearchofHardware = DBSession.query(AssetForAgent).filter(AssetForAgent.ZCBM == tmpZCBM).first()
if getSearchofHardware:
try:
if int(getSearchofHardware.Timestamp) < message['SendTime']:
DBSession.delete(getSearchofHardware)
DBSession.commit()
tmpeth0 = ""
tmpeth1 = ""
for key,value in tmpEthDict.items():
if key == 'eth0':
tmpeth0 = value
elif key == 'eth1':
tmpeth1 = value
getCountofeth = DBSession.query(EthInfo).count()
getCountofeth = (getCountofeth + 1)
DBSession.add(EthInfo(getCountofeth,tmpeth0,tmpeth1,'None','None'))
DBSession.add(AssetForAgent(tmpProjectName, tmpProjectFunc, tmpKernel, tmpCpuCoreNum, tmpSerialNum, tmpZCBM, tmpMemory, tmpCpuType, tmpModel, tmpHostName, tmpOS, tmpManufacturer, message['SendTime']))
DBSession.commit()
getTmpid = DBSession.query(AssetForAgent).filter_by(ZCBM = tmpZCBM).first()
if getTmpid:
Tmpid = getTmpid.Hid
else:
DBSession.rollback()
return dict(Status='False', msg='flush assetforagent Error.')
getCountofrelation = DBSession.query(AssetidtoEid).count()
getCountofrelation = int(getCountofrelation + 1)
DBSession.add(AssetidtoEid(getCountofrelation, Tmpid, getCountofeth))
DBSession.commit()
return dict(Status='Success')
else:
return dict(Status='Success', msg='Input Hostname Need not fresh.')
示例12: initdata
# 需要导入模块: from model import DBSession [as 别名]
# 或者: from model.DBSession import commit [as 别名]
#.........这里部分代码省略.........
DBSession.add(InfoCheckGameName('NULL','ZT'))
DBSession.add(InfoCheckGameName('JR','JR'))
DBSession.add(InfoCheckGameName('HuaiJiu','ZTHJB'))
DBSession.add(InfoCheckGameName('KOK3','WWZW3'))
DBSession.add(InfoCheckGameName('XSG','WDXSG'))
DBSession.add(InfoCheckGameName('DoDo','JRDD'))
DBSession.add(InfoCheckGameName('HuangJin','HJGD'))
DBSession.add(InfoCheckGameName('XT','XT'))
DBSession.add(InfoCheckGameName('ZTLS','LSZT'))
DBSession.add(InfoCheckGameName('XSG_ALL','XSG'))
DBSession.add(InfoCheckGameName('LH','LH'))
DBSession.add(InfoCheckGameName('ZTII','ZT2'))
DBSession.add(InfoCheckGameName('LS','LS'))
DBSession.add(InfoCheckGameName('DDT','DDT'))
DBSession.add(InfoCheckGameName('ELS','AEZG'))
DBSession.add(InfoCheckGameName('TKZC','XJJH'))
DBSession.add(InfoCheckGameName('SGZH','SGZH'))
DBSession.add(InfoCheckGameName('WSZN','WSZN'))
DBSession.add(InfoCheckGameName('WS','WS'))
DBSession.add(InfoCheckGameName('XXSJ','XXSJ'))
DBSession.add(InfoCheckGameName('CSJZ','CSJZ'))
DBSession.add(InfoCheckGameName('360','QJ'))
DBSession.add(InfoCheckGameName('CK','CK'))
# process hostname
getprocessofhostname = initcheck(HostnameToProcess)
if int(getprocessofhostname) == 0:
DBSession.add(HostnameToProcess(1, 'ZR-Agent-4.x-test', 'GateServer5'))
DBSession.add(HostnameToProcess(2, 'ZR-Agent-4.x-test', 'GateServer3'))
DBSession.add(HostnameToProcess(3, 'ZR-Agent-4.x-test', 'GateServer2'))
DBSession.add(HostnameToProcess(4, 'ZR-Agent-4.x-test', 'GateServer8'))
DBSession.add(HostnameToProcess(5, 'ZR-Agent-4.x-test', 'GateServer1'))
DBSession.add(HostnameToProcess(6, 'ZR-Agent-4.x-test', 'CharServer10'))
DBSession.add(HostnameToProcess(7, 'ZR-Agent-4.x-test', 'CharServer11'))
DBSession.add(HostnameToProcess(8, 'ZR-Agent-4.x-test', 'CharServer14'))
DBSession.add(HostnameToProcess(9, 'ZR-Agent-4.x-test', 'CharServer12'))
DBSession.add(HostnameToProcess(10, 'ZR-Agent-4.x-test', 'CharServer13'))
DBSession.add(HostnameToProcess(11, 'ZR-Agent-4.x-test', 'LoginServer'))
DBSession.add(HostnameToProcess(12, 'ZR-Agent-4.x-test', 'LogServer'))
# Event Level
geteventlevel = initcheck(EventLevel)
if int(geteventlevel) == 0:
DBSession.add(EventLevel(0, '保留位'))
DBSession.add(EventLevel(1, '重大事件'))
DBSession.add(EventLevel(2, '特大事件'))
DBSession.add(EventLevel(3, '高级事件'))
DBSession.add(EventLevel(4, '中级事件'))
DBSession.add(EventLevel(5, '低级事件'))
DBSession.add(EventLevel(6, '普通事件'))
# Game to Group addition
getgametogroup = initcheck(GameGroupRelation)
if int(getgametogroup) == 0:
DBSession.add(GameGroupRelation(1,17,0))
DBSession.add(GameGroupRelation(2,18,1))
# Event operation
geteventoperation = initcheck(EventOperation)
if int(geteventoperation) == 0:
DBSession.add(EventOperation(0,'ALLControl','全部操作权限'))
DBSession.add(EventOperation(1,'PartView','部分查看权限'))
DBSession.add(EventOperation(2,'PartSelect','部分查询权限'))
# Event transport define
geteventtransportdefine = initcheck(EventTransportDefine)
if int(geteventtransportdefine) == 0:
DBSession.add(EventTransportDefine(0,0,-1,-1,1,-1))
DBSession.add(EventTransportDefine(1,0,-1,-1,2,-1))
DBSession.add(EventTransportDefine(2,1,2,0,3,-1))
DBSession.add(EventTransportDefine(3,2,1,0,3,-1))
DBSession.add(EventTransportDefine(4,3,-1,1,4,1))
DBSession.add(EventTransportDefine(5,3,-1,1,6,1))
DBSession.add(EventTransportDefine(6,4,-1,3,5,1))
DBSession.add(EventTransportDefine(7,4,-1,3,6,1))
DBSession.add(EventTransportDefine(8,5,-1,4,10,1))
DBSession.add(EventTransportDefine(9,6,-1,3,10,-1))
DBSession.add(EventTransportDefine(10,6,-1,4,10,-1))
DBSession.add(EventTransportDefine(11,10,-1,5,100,-1))
DBSession.add(EventTransportDefine(12,10,-1,6,100,-1))
DBSession.add(EventTransportDefine(100,100,-1,-1,-1,-1))
# responibility user
getresponibilityuser = initcheck(ResonibilityUser)
if int(getresponibilityuser) == 0:
DBSession.add(ResonibilityUser(0,1,'jiangchao','姜超',13601674151,'[email protected]','[email protected]','运维负责人','True'))
DBSession.add(ResonibilityUser(1,1,'changzonghui','常宗辉',18623759189,'[email protected]','[email protected]','运维人员','False'))
DBSession.add(ResonibilityUser(2,1,'majian','赵俊杰',13817992612,'[email protected]','[email protected]','运维人员','False'))
# responibility group
getresponibilitygroup = initcheck(ResponibilityGroup)
if int(getresponibilitygroup) == 0:
DBSession.add(ResponibilityGroup(1,'yunwei','运维部'))
# responibility relation
getresponibilityrelation = initcheck(ResponibilityRelation)
if int(getresponibilityrelation) == 0:
DBSession.add(ResponibilityRelation(1,300,1))
DBSession.commit()
示例13: setup_database
# 需要导入模块: from model import DBSession [as 别名]
# 或者: from model.DBSession import commit [as 别名]
def setup_database():
init_model(engine)
teardownDatabase()
elixir.setup_all(True)
# Creating permissions
see_site = Permission()
see_site.permission_name = u'see-site'
see_site.description = u'see-site permission description'
DBSession.save(see_site)
edit_site = Permission()
edit_site.permission_name = u'edit-site'
edit_site.description = u'edit-site permission description'
DBSession.save(edit_site)
commit = Permission()
commit.permission_name = u'commit'
commit.description = u'commit permission description'
DBSession.save(commit)
# Creating groups
admins = Group()
admins.group_name = u'admins'
admins.display_name = u'Admins Group'
admins.permissions.append(edit_site)
DBSession.save(admins)
developers = Group(group_name=u'developers',
display_name=u'Developers Group')
developers.permissions = [commit, edit_site]
DBSession.save(developers)
trolls = Group(group_name=u'trolls', display_name=u'Trolls Group')
trolls.permissions.append(see_site)
DBSession.save(trolls)
# Plus a couple of groups with no permissions
php = Group(group_name=u'php', display_name=u'PHP Group')
DBSession.save(php)
python = Group(group_name=u'python', display_name=u'Python Group')
DBSession.save(python)
# Creating users
user = User()
user.user_name = u'rms'
user.password = u'freedom'
user.email_address = u'[email protected]'
user.groups.append(admins)
user.groups.append(developers)
DBSession.save(user)
user = User()
user.user_name = u'linus'
user.password = u'linux'
user.email_address = u'[email protected]'
user.groups.append(developers)
DBSession.save(user)
user = User()
user.user_name = u'sballmer'
user.password = u'developers'
user.email_address = u'[email protected]'
user.groups.append(trolls)
DBSession.save(user)
# Plus a couple of users without groups
user = User()
user.user_name = u'guido'
user.password = u'phytonic'
user.email_address = u'[email protected]'
DBSession.save(user)
user = User()
user.user_name = u'rasmus'
user.password = u'php'
user.email_address = u'[email protected]'
DBSession.save(user)
DBSession.commit()