OSDN Git Service

make DVB driver usable.
[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-2012 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     str="99"+","+datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")+","+configreader.getConfEnv("iff")+","+chtxt+","+title+","+optt\r
24     f.write(str.encode('utf-8'))\r
25     f.close()\r
26     if not os.path.exists(outputpath):\r
27         if os.path.exists(tmpoppath):\r
28             os.remove(tmpoppath)\r
29         f2=open(tmpoppath,"w")\r
30         f2.write(str.encode('utf-8'))\r
31         f2.close()\r
32         try:\r
33             os.chmod(tmpoppath)\r
34         except:\r
35             ""\r
36         shutil.copy(tmpoppath,outputpath)\r
37         os.remove(tmpoppath)\r
38 def readRecQue(recquepath):\r
39     f=open(recquepath,"r")\r
40     line = unicode(f.readline(),'utf-8')\r
41     title=""\r
42     opts=""\r
43     chtxt=""\r
44     while line:\r
45         linec=line.split(",")\r
46         if len(linec)>3:\r
47             if linec[0]=="99":\r
48                 title=linec[4]\r
49                 opts=linec[5]\r
50                 chtxt=linec[2]+u"_"+linec[3]\r
51                 break\r
52         line = unicode(f.readline(),'utf-8')\r
53     dbkey=""\r
54     if opts.find("R")>-1:\r
55         dbkey=recdblist.REC_TS_DECODE_QUE\r
56         opts=opts.replace("R","")\r
57     elif opts.find("D")>-1:\r
58         dbkey=recdblist.REC_ENCODE_QUE\r
59         opts=opts.replace("D","")\r
60     elif opts.find("E")>-1:\r
61         dbkey=""\r
62         opts=opts.replace("E","")\r
63     \r
64     bt=datetime.datetime.now()+datetime.timedelta(minutes=5)\r
65     et=bt+datetime.timedelta(minutes=30)\r
66     btime=bt.strftime("%Y-%m-%d %H:%M:%S")\r
67     etime=et.strftime("%Y-%m-%d %H:%M:%S")\r
68     if len(dbkey)>2:\r
69         recdb.reserveReckey(dbkey, title, chtxt, btime, etime, opts)\r
70 def searchRecQue(folderpath):\r
71     for file in glob.glob(os.path.join(folderpath,"*.recq")):\r
72         dtime = time.time()-os.path.getmtime(file)\r
73         dtime = int(dtime)\r
74         if dtime > 300:\r
75             try:\r
76                 readRecQue(os.path.join(folderpath, file))\r
77                 os.remove(os.path.join(folderpath, file))\r
78             except Exception, inst:\r
79                 recdblist.addCommonlogEX("Error", "searchRecQue(recque.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200)\r
80                 \r