OSDN Git Service

implement recque 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 import os.path
8 import glob
9 import time
10 import traceback
11
12 import configreader
13 import recdblist
14 import recdb
15 def writeRecQue(parentpath,chtxt,title,opts):
16     f=open(os.path.join(parentpath,title+".recq"),"w")
17     optt=opts
18     #optt=opts.replace("E","")
19     #optt=optt.replace("D","")
20     #optt=optt.replace("R","")
21     str="99"+","+datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")+","+configreader.getenv("iff")+","+chtxt+","+title+","+optt
22     f.write(str.encode('utf-8'))
23     f.close()
24
25 def readRecQue(recquepath):
26     f=open(recquepath,"r")
27     line = unicode(f.readline(),'utf-8')
28     title=""
29     opts=""
30     chtxt=""
31     while line:
32         linec=line.split(",")
33         if len(linec)>3:
34             if linec[0]=="99":
35                 title=linec[4]
36                 opts=linec[5]
37                 chtxt=linec[2]+u"_"+linec[3]
38                 break
39         line = unicode(f.readline(),'utf-8')
40     dbkey=""
41     if opts.find("E"):
42         dbkey=""
43         opts=opts.replace("E","")
44     if opts.find("D"):
45         dbkey=recdblist.REC_ENCODE_QUE
46         opts=opts.replace("D","")
47     if opts.find("R"):
48         dbkey=recdblist.REC_TS_DECODE_QUE
49         opts=opts.replace("E","")
50     bt=datetime.datetime.now()+datetime.timedelta(minutes=5)
51     et=bt+datetime.timedelta(minutes=30)
52     btime=bt.strftime("%Y-%m-%d %H:%M:%S")
53     etime=et.strftime("%Y-%m-%d %H:%M:%S")
54     if len(dbkey)>2:
55         recdb.rec_reckey(dbkey, title, chtxt, btime, etime, opts)
56 def searchRecQue(folderpath):
57     for file in glob.glob(os.path.join(folderpath,"*.recq")):
58         dtime = time.time()-os.path.getmtime(file)
59         dtime = int(dtime)
60         if dtime > 300:
61             try:
62                 readRecQue(os.path.join(folderpath, file))
63                 os.remove(os.path.join(folderpath, file))
64             except Exception, inst:
65                 recdblist.Commonlogex("Error", "searchRecQue(recque.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200)
66