]> git.pld-linux.org Git - projects/pld-builder.new.git/blob - PLD_Builder/blacklist.py
rewrite Blacklist_File with set
[projects/pld-builder.new.git] / PLD_Builder / blacklist.py
1 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
2
3 import string
4 import fnmatch
5 import os
6 import stat
7 import re
8
9 import path
10 import log
11 import status
12 from mailer import Message
13 from config import config
14
15 class Blacklist_File:
16     def __init__(self):
17         self.reload()
18
19     def try_reload(self):
20         mtime = os.stat(path.blacklist_file)[stat.ST_MTIME]
21         if mtime != self.blacklist_file_mtime:
22             log.notice("blacklist file has changed, reloading...")
23             self.reload()
24             return True
25         return False
26
27     def reload(self):
28         self.blacklist_file_mtime = os.stat(path.blacklist_file)[stat.ST_MTIME]
29         self.blacklist = set()
30         status.push("reading package-blacklist")
31         with open(path.blacklist_file) as f:
32             for l in f:
33                 p = l.rstrip()
34                 if re.match(r"^#.*", p):
35                     continue
36                 self.blacklist.add(p)
37                 log.notice("blacklist added: %s" % l)
38         status.pop()
39
40     def package(self, p):
41 #       log.notice("blacklist check: %s (%d)" % (p, self.blacklist.has_key(p)))
42         if p in self.blacklist:
43             return True
44         return False
45
46     def packages(self):
47         return self.blacklist
48
49 blacklist = Blacklist_File()
This page took 0.064782 seconds and 3 git commands to generate.