3
from optparse import OptionParser
4
import user, string, dircache, sys, os.path
7
class HookFiles(object):
8
""" represents all hook files """
10
# the hooks are stored here
11
hookDir = "/var/lib/update-notifier/user.d/"
13
class HookFile(object):
14
""" represents a single hook file """
15
__slots__ = [ "filename", "mtime", "cmd_run", "seen" ]
17
def __init__(self, filename):
18
self.filename = filename
19
self.mtime = os.stat(HookFiles.hookDir+filename).st_mtime
24
""" show the summary for the notification """
25
# FIXME: read rfc822 style file and get the i18n version of
28
summary = property(summary)
30
def description(self):
31
""" show a long description for the notification """
32
# FIXME: read rfc822 style file and get the i18n version of
33
# "Description", convert "\n" -> " " and strstrip it afterwards
35
description = property(description)
43
def _readSeenFile(self):
44
""" read the users config file that stores what hook files are
46
hooks_seen = user.home+"/.update-notifier/hooks_seen"
47
if os.path.exists(hooks_seen):
48
for line in open(hooks_seen):
49
filename, mtime, cmd_run = string.split(line)
50
if os.path.exists(self.hookDir+filename) and \
51
not self._hooks.has_key(filename):
52
h = self.HookFile(filename)
56
# check if file was motified since we last saw it
57
if os.stat(self.hookDir+filename).st_mtime > int(mtime):
59
self._hooks[filename] = h
62
""" update hook dict with the current state on the fs """
63
for hook in dircache.listdir(self.hookDir):
64
if self._hooks.has_key(hook):
65
# we have it already, check if it was motified since
68
if os.stat(self.hookDir+hook).st_mtime > int(h.mtime):
71
self._hooks[hook] = self.HookFile(hook)
74
""" return the list of unseen hook files """
77
for hook in self._hooks:
78
if not self._hooks[hook].seen:
79
new.append(self._hooks[hook])
85
new = hooks.checkNew()
90
new = hooks.checkNew()
91
print "Hooks: %s" % len(new)
92
for hook in hooks._hooks:
93
print hooks._hooks[hook].notification
96
if __name__ == "__main__":
97
parser = OptionParser()
98
parser.add_option("-c", "--check", action="store_true", dest="check",
99
default=False, help="check for new hooks")
100
parser.add_option("-r", "--run", action="store_true", dest="run",
101
default=False, help="run interactive hook view")
102
parser.add_option("-t", "--test", action="store_true", dest="test",
103
default=False, help="run test")
104
(options, args) = parser.parse_args()