您的位置:首页 > 编程语言 > Python开发

[PYTHON] 将perforce的 changelist放到 sqlite 数据库里面

2010-11-02 17:10 459 查看
from P4 import P4
import sqlite3
import time

def InsertChanges(): #insert change to db
p4=P4()
p4.connect()
#exittable=cursor.execute("select count(*) from sqlite_master where type='table' and name='changes'") test whether the table existes or not.
#print exittable
conn=sqlite3.connect("perforceChanges.db")
cursor=conn.cursor()
try:
cursor.execute("drop table changes")#delete the table
except:
pass
cursor.execute("create table changes(change,time,user,client,desc)")
changes=p4.run("changes","-m20","-l")
for change in changes:
ti=time.strftime('%Y/%m/%d %H:%M:%S',time.localtime((float)(change['time'])))
t=(change['change'],ti,change['user'],change['client'],change['desc'])
cursor.execute("insert into changes  values(?,?,?,?,?)",t)
conn.commit()
cursor.close()
conn.close()

def PrintChange():#print the changes at db
conn=sqlite3.connect("perforceChanges.db")
cursor=conn.cursor()
rows=cursor.execute("select * from changes")
for row in rows:
print "changelist:",row[0]
print "time:",row[1]
print "user:",row[2]
print "client:",row[3]
print "description:",row[4]
print "======================================================="

InsertChanges()
PrintChange()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: