-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileEntity.py
executable file
·44 lines (35 loc) · 1.3 KB
/
FileEntity.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from DependencyGraphEntity import *
import os
from stat import *
class FileEntity(DependencyGraphEntity):
def __init__(self, name, path):
DependencyGraphEntity.__init__(self, name)
self.m_path = path
def path(self):
return self.m_path
def actualFileTimestamp(self):
if not os.path.exists(self.m_path):
timestamp = 0
else:
# timestamp is the modification time of file
timestamp = os.stat(self.m_path)[ST_MTIME]
return datetime.fromtimestamp(timestamp)
def timestamp(self):
return self.actualFileTimestamp()
def update(self):
# make all prerequisites
changed = []
self.updatePrerequisites(changed)
# check to see if execution is needed
needExecute = False
for p in self.prerequisiteList:
if p.timestamp() == datetime.fromtimestamp(0):
# errMsg = "Cannot make `" + p.name() + "', needed by `" + self.name() + "'."
errMsg = self.name() + ": cannot make `" + p.name() + "'"
print errMsg
if self.timestamp() < p.timestamp():
needExecute = True
break
# execute action
if needExecute:
self.executeActions(self, self.prerequisiteList, changed)