OSDN Git Service

add Que system.
[rec10/rec10-git.git] / rec10 / trunk / src / recque.py
1 #!/usr/bin/python
2 # coding: UTF-8
3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2010 Yukikaze
5 import datetime
6 import os
7
8 import configreader
9 import recdblist
10 import recdb
11 def writeRecQue(parentpath,chtxt,title,opts):
12     f=open(os.path.join(parentpath,title+".recq"),"w")
13     optt=opts.replace("E","")
14     optt=optt.replace("D","")
15     optt=optt.replace("R","")
16     str="99"+","+datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")+","+configreader.getenv("iff")+","+chtxt+","+title+","+optt
17     f.write(str.encode('utf-8'))
18     f.close()
19
20 def readRecQue(recquepath):
21     f=open(os.path.join(parentpath,title+".recq"),"r")
22     line = unicode(f.readline(),'utf-8')
23     title=""
24     opts=""
25     chtxt=""
26     while line:
27         linec=line.split(",")
28         if len(linec)>3:
29             if linec[0]=="99":
30                 title=linec[4]
31                 opts=linec[5]
32                 chtxt=linec[2]+u"_"+linec[3]
33                 break
34         line = unicode(f.readline(),'utf-8')
35     dbkey=""
36     if opts.find("E"):
37         dbkey=""
38         opts=opts.replace("E","")
39     if opts.find("D"):
40         dbkey=recdblist.REC_ENCODE_QUE
41         opts=opts.replace("D","")
42     if opts.find("R"):
43         dbkey=recdblist.REC_TS_DECODE_QUE
44         opts=opts.replace("E","")
45     bt=datetime.datetime.now()+datetime.timedelta(minutes=5)
46     et=bt+datetime.timedelta(minutes=30)
47     btime=bt.strftime("%Y-%m-%d %H:%M:%S")
48     etime=et.strftime("%Y-%m-%d %H:%M:%S")
49     recdb.rec_reckey(dbkey, title, chtxt, btime, etime, opts)