OSDN Git Service

stop using trunk directory in rectool
[rec10/rec10-git.git] / rec10 / trunk / src / checker.py
1 #!/usr/bin/python
2 # coding: UTF-8
3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2011 Yukikaze
5 import os
6 import os.path
7 import time
8
9 def checkB25Decode(b25filepath, decodedfilepath , csch):
10     ret = 0
11     if os.path.isfile(decodedfilepath):##tsファイルが存在している
12         dtime = time.time()-os.path.getmtime(decodedfilepath)
13         dtime = int(dtime)
14         if dtime > 20:
15             if csch>0:
16                 if (compareFilesize(b25filepath, decodedfilepath, 10) and minimizeCheck(decodedfilepath, 800)):
17                     ret = 1
18             else:
19                 if (compareFilesize(b25filepath, decodedfilepath, 60) and minimizeCheck(decodedfilepath, 800)):
20                     ret = 1
21         else:
22             time.sleep(30)
23             dtime = time.time()-os.path.getmtime(decodedfilepath)
24             dtime = int(dtime)
25             if dtime > 20:
26                 if csch>0:
27                     if (compareFilesize(b25filepath, decodedfilepath, 10) and minimizeCheck(decodedfilepath, 800)):
28                         ret = 1
29                 else:
30                     if (compareFilesize(b25filepath, decodedfilepath, 60) and minimizeCheck(decodedfilepath, 800)):
31                         ret = 1
32     #recdblist.printutf8("deleting b25 is " + str(ret))
33     return ret
34 def compareFilesize(pathbase, path, percentage):
35     """
36     return true if size of path is larger than that of pathbase.
37     percentage is int(0< <100)
38     """
39     if not os.path.exists(pathbase):
40         return 0
41     basesize = os.path.getsize(pathbase)
42     pathsize = os.path.getsize(path)
43     size = pathsize * 100-basesize * percentage
44     if size < 0:
45         return 0
46     else:
47         return 1
48 def minimizeCheck(filepath, minsize):
49     """
50     minsize is Megabytes
51     """
52     if os.path.getsize(filepath) > minsize * 1000 * 1000:
53         return 1
54     else:
55         return 0