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
47
data_home = os.getenv("XDG_CONFIG_HOME", os.path.join(user.home, '.config'))
48
hooks_seen = os.path.join(data_home, 'update-notifier', 'hooks_seen')
49
if os.path.exists(hooks_seen):
50
for line in open(hooks_seen):
51
filename, mtime, cmd_run = string.split(line)
52
if os.path.exists(self.hookDir+filename) and \
53
not self._hooks.has_key(filename):
54
h = self.HookFile(filename)
58
# check if file was motified since we last saw it
59
if os.stat(self.hookDir+filename).st_mtime > int(mtime):
61
self._hooks[filename] = h
64
""" update hook dict with the current state on the fs """
65
for hook in dircache.listdir(self.hookDir):
66
if self._hooks.has_key(hook):
67
# we have it already, check if it was motified since
70
if os.stat(self.hookDir+hook).st_mtime > int(h.mtime):
73
self._hooks[hook] = self.HookFile(hook)
76
""" return the list of unseen hook files """
79
for hook in self._hooks:
80
if not self._hooks[hook].seen:
81
new.append(self._hooks[hook])
87
new = hooks.checkNew()
92
new = hooks.checkNew()
93
print "Hooks: %s" % len(new)
94
for hook in hooks._hooks:
95
print hooks._hooks[hook].notification
98
if __name__ == "__main__":
99
parser = OptionParser()
100
parser.add_option("-c", "--check", action="store_true", dest="check",
101
default=False, help="check for new hooks")
102
parser.add_option("-r", "--run", action="store_true", dest="run",
103
default=False, help="run interactive hook view")
104
parser.add_option("-t", "--test", action="store_true", dest="test",
105
default=False, help="run test")
106
(options, args) = parser.parse_args()