-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathsource_file.py
38 lines (30 loc) · 895 Bytes
/
source_file.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
import os
import time
class source_file(object):
def __init__(self, filename):
self.filename = os.path.abspath(filename)
self.modified = self.get_last_modified()
self.last_size = os.path.getsize(filename)
def get_last_modified(self):
return time.ctime(os.path.getmtime(self.filename))
def was_updated(self):
t = self.get_last_modified()
if t > self.modified:
self.modified = t
return True
else:
return False
def get_base_name(self):
return os.path.basename(self.filename)
def get_directory(self):
return os.path.dirname(self.filename)
def get_text(self, only_new_text = False):
text = ""
while len(text) == 0:
with open(self.filename, 'r') as content_file:
if only_new_text:
content_file.seek(self.last_size)
text = content_file.read()
time.sleep(0.1)
self.last_size = os.path.getsize(self.filename)
return text