OSDN Git Service

add recovery write recque mode.
[rec10/rec10-git.git] / rec10 / trunk / src / recque.py
1 #!/usr/bin/python\r
2 # coding: UTF-8\r
3 # Rec10 TS Recording Tools\r
4 # Copyright (C) 2009-2011 Yukikaze\r
5 import datetime\r
6 import os\r
7 import os.path\r
8 import glob\r
9 import time\r
10 import traceback\r
11 \r
12 import configreader\r
13 import recdblist\r
14 import recdb\r
15 tmppath = configreader.getConfPath("tmp")+"/"\r
16 if not os.path.exists(tmppath):\r
17     os.mkdir(tmppath)\r
18 def writeRecQue(parentpath,chtxt,title,opts):\r
19     outputpath=os.path.join(parentpath,title+".recq")\r
20     tmpoppath=os.path.join(tmppath,title+".recq")\r
21     f=open(outputpath,"w")\r
22     optt=opts\r
23     #optt=opts.replace("E","")\r
24     #optt=optt.replace("D","")\r
25     #optt=optt.replace("R","")\r
26     str="99"+","+datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")+","+configreader.getConfEnv("iff")+","+chtxt+","+title+","+optt\r
27     f.write(str.encode('utf-8'))\r
28     f.close()\r
29     if not os.path.exists(outputpath):\r
30         if os.path.exists(tmpoppath):\r
31             os.remove(tmpoppath)\r
32         f2=open(tmpoppath,"w")\r
33         f2.write(str.encode('utf-8'))\r
34         f2.close()\r
35         try:\r
36             os.chmod(tmpoppath)\r
37         except:\r
38             ""\r
39         shutil.copy(tmpoppath,outputpath)\r
40         os.remove(tmpoppath)\r
41 def readRecQue(recquepath):\r
42     f=open(recquepath,"r")\r
43     line = unicode(f.readline(),'utf-8')\r
44     title=""\r
45     opts=""\r
46     chtxt=""\r
47     while line:\r
48         linec=line.split(",")\r
49         if len(linec)>3:\r
50             if linec[0]=="99":\r
51                 title=linec[4]\r
52                 opts=linec[5]\r
53                 chtxt=linec[2]+u"_"+linec[3]\r
54                 break\r
55         line = unicode(f.readline(),'utf-8')\r
56     dbkey=""\r
57     if opts.find("E")>-1:\r
58         dbkey=""\r
59         opts=opts.replace("E","")\r
60     elif opts.find("D")>-1:\r
61         dbkey=recdblist.REC_ENCODE_QUE\r
62         opts=opts.replace("D","")\r
63     elif opts.find("R")>-1:\r
64         dbkey=recdblist.REC_TS_DECODE_QUE\r
65         opts=opts.replace("R","")\r
66     bt=datetime.datetime.now()+datetime.timedelta(minutes=5)\r
67     et=bt+datetime.timedelta(minutes=30)\r
68     btime=bt.strftime("%Y-%m-%d %H:%M:%S")\r
69     etime=et.strftime("%Y-%m-%d %H:%M:%S")\r
70     if len(dbkey)>2:\r
71         recdb.reserveReckey(dbkey, title, chtxt, btime, etime, opts)\r
72 def searchRecQue(folderpath):\r
73     for file in glob.glob(os.path.join(folderpath,"*.recq")):\r
74         dtime = time.time()-os.path.getmtime(file)\r
75         dtime = int(dtime)\r
76         if dtime > 300:\r
77             try:\r
78                 readRecQue(os.path.join(folderpath, file))\r
79                 os.remove(os.path.join(folderpath, file))\r
80             except Exception, inst:\r
81                 recdblist.addCommonlogEX("Error", "searchRecQue(recque.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200)\r
82                 \r