Lines Matching refs:self
32 def __init__(self, level):
35 self.level = level
37 def emit(self, record):
38 if record.levelno >= self.level:
52 def __init__(self, callback, delay=1.2, threshold=0.8):
54 self.delay = delay
55 self.threshold = timedelta(seconds=threshold)
56 self.callback = callback
57 self.event_dirs = set([])
58 self.timer = None
59 self.lock = Lock()
61 def start_timer(self):
62 if self.timer is None:
63 self.timer = Timer(self.delay, self.process_dirs)
64 self.timer.start()
66 def process_dirs(self):
69 with self.lock:
70 self.timer = None
71 while self.event_dirs:
72 time, event_dir = self.event_dirs.pop()
74 if delta < self.threshold:
78 self.event_dirs = event_dirs
80 self.callback(os.path.commonpath(result_dirs))
81 if self.event_dirs:
82 self.start_timer()
84 def add_dir(self, path):
85 with self.lock:
89 for (_, event_dir) in self.event_dirs):
90 self.event_dirs.add((datetime.now(), path))
91 if self.timer is None:
92 self.start_timer()
97 def __init__(self, root_dir, tree_dir):
99 self.root_dir = root_dir
100 self.tree_dir = tree_dir
101 self.rel_dir = os.path.relpath(tree_dir, root_dir)
102 self.name = os.path.basename(tree_dir)
103 self.include_dir = os.path.abspath(os.path.join(tree_dir, INCLUDE))
104 self.header = os.path.abspath(os.path.join(tree_dir, SINGLE_INCLUDE, HEADER))
105 self.rel_header = os.path.relpath(self.header, root_dir)
106 self.dirty = True
107 self.build_count = 0
108 t = os.path.getmtime(self.header)
110 self.build_time = t.strftime(DATETIME_FORMAT)
112 def __hash__(self):
114 return hash((self.tree_dir))
116 def __eq__(self, other):
118 if not isinstance(other, type(self)):
120 return self.tree_dir == other.tree_dir
122 def update_dirty(self, path):
123 if self.dirty:
127 if os.path.commonpath([path, self.include_dir]) == self.include_dir:
128 logging.info(f'{self.name}: working tree marked dirty')
129 self.dirty = True
131 def amalgamate_header(self):
132 if not self.dirty:
135 mtime = os.path.getmtime(self.header)
136 subprocess.run([WorkTree.make_command, 'amalgamate'], cwd=self.tree_dir,
138 if mtime == os.path.getmtime(self.header):
139 logging.info(f'{self.name}: no changes')
141 self.build_count += 1
142 self.build_time = datetime.now().strftime(DATETIME_FORMAT)
143 logging.info(f'{self.name}: header amalgamated (build count {self.build_count})')
145 self.dirty = False
148 def __init__(self, root_dir):
151 self.root_dir = root_dir
152 self.trees = set([])
153 self.tree_lock = Lock()
154 self.scan(root_dir)
155 self.created_bucket = DirectoryEventBucket(self.scan)
156 self.observer = Observer()
157 self.observer.schedule(self, root_dir, recursive=True)
158 self.observer.start()
160 def scan(self, base_dir):
166 self.scan_tree(scan_dir)
175 def scan_tree(self, scan_dir):
184 tree = WorkTree(self.root_dir, scan_dir)
185 with self.tree_lock:
186 if not tree in self.trees:
193 self.trees.add(tree)
195 def rescan(self, path=None):
200 with self.tree_lock:
201 while self.trees:
202 tree = self.trees.pop()
212 self.trees = trees
214 def find(self, path):
217 with self.tree_lock:
218 for tree in self.trees:
223 def on_any_event(self, event):
230 self.created_bucket.add_dir(path)
233 self.rescan(path)
235 with self.tree_lock:
236 for tree in self.trees:
239 def stop(self):
240 self.observer.stop()
241 self.observer.join()
244 def __init__(self, request, client_address, server):
246 self.worktrees = server.worktrees
247 self.worktree = None
254 def translate_path(self, path):
266 def send_head(self):
269 path = self.translate_path(self.path)
270 self.worktree = self.worktrees.find(path)
271 if self.worktree is not None:
272 self.worktree.amalgamate_header()
273 logging.info(f'{self.worktree.name}; serving header (build count {self.worktree.build_count})')
275 logging.info(f'invalid request path: {self.path}')
279 def send_header(self, keyword, value):
285 def end_headers (self):
290 def copyfile(self, source, outputfile):
299 f'{self.worktree.build_count}\n', 'utf-8'))
301 f'"{self.worktree.build_time}"\n\n', 'utf-8'))
308 self.send_header('Access-Control-Allow-Origin', '*')
310 self.send_header('Cache-Control', 'no-cache, no-store, must-revalidate')
311 self.send_header('Pragma', 'no-cache')
312 self.send_header('Expires', '0')
319 def log_message(self, format, *args):
323 def __init__(self, addr, worktrees):
325 self.worktrees = worktrees
328 def server_bind(self):
331 self.socket.setsockopt(