Don't use ctime on unix system. Cleanup check a bit. close #2904

This commit is contained in:
Ruud
2014-03-07 18:58:27 +01:00
parent 7af1d00ea2
commit 2066625bf0
3 changed files with 47 additions and 51 deletions
+37 -1
View File
@@ -1,7 +1,7 @@
from couchpotato.core.event import fireEvent, addEvent
from couchpotato.core.helpers.encoding import ss, toSafeString, \
toUnicode, sp
from couchpotato.core.helpers.variable import getExt, md5, isLocalIP, scanForPassword
from couchpotato.core.helpers.variable import getExt, md5, isLocalIP, scanForPassword, tryInt
from couchpotato.core.logger import CPLog
from couchpotato.environment import Env
import requests
@@ -307,6 +307,42 @@ class Plugin(object):
return ''
def checkFilesChanged(self, files, unchanged_for = 60):
now = time.time()
for cur_file in files:
# File got removed while checking
if not os.path.isfile(cur_file):
file_too_new = now
break
# File has changed in last 60 seconds
file_time = self.self.getFileTimes(cur_file)
for t in file_time:
if t > now - unchanged_for:
file_too_new = tryInt(time.time() - t)
break
if file_too_new:
break
if file_too_new:
try:
time_string = time.ctime(file_time[0])
except:
try:
time_string = time.ctime(file_time[1])
except:
time_string = 'unknown'
return file_too_new, time_string
return False, None
def getFileTimes(self, file_path):
return [os.path.getmtime(file_path), os.path.getctime(file_path) if os.name != 'posix' else 0]
def isDisabled(self):
return not self.isEnabled()