3
from __future__ import print_function
5
from optparse import OptionParser
14
class HookFiles(object):
15
""" represents all hook files """
17
# the hooks are stored here
18
hookDir = "/var/lib/update-notifier/user.d/"
20
class HookFile(object):
21
""" represents a single hook file """
22
__slots__ = ["filename", "mtime", "cmd_run", "seen"]
24
def __init__(self, filename):
25
self.filename = filename
26
self.mtime = os.stat(HookFiles.hookDir + filename).st_mtime
31
""" show the summary for the notification """
32
# FIXME: read rfc822 style file and get the i18n version of
35
summary = property(summary)
37
def description(self):
38
""" show a long description for the notification """
39
# FIXME: read rfc822 style file and get the i18n version of
40
# "Description", convert "\n" -> " " and strstrip it afterwards
42
description = property(description)
49
def _readSeenFile(self):
50
""" read the users config file that stores what hook files are
53
data_home = os.getenv("XDG_CONFIG_HOME",
54
os.path.join(user.home, '.config'))
55
hooks_seen = os.path.join(data_home, 'update-notifier', 'hooks_seen')
56
if os.path.exists(hooks_seen):
57
for line in open(hooks_seen):
58
filename, mtime, cmd_run = string.split(line)
59
if os.path.exists(self.hookDir + filename) and \
60
filename not in self._hooks:
61
h = self.HookFile(filename)
65
# check if file was motified since we last saw it
66
if os.stat(self.hookDir + filename).st_mtime > int(mtime):
68
self._hooks[filename] = h
71
""" update hook dict with the current state on the fs """
72
for hook in dircache.listdir(self.hookDir):
73
if hook in self._hooks:
74
# we have it already, check if it was motified since
77
if os.stat(self.hookDir + hook).st_mtime > int(h.mtime):
80
self._hooks[hook] = self.HookFile(hook)
83
""" return the list of unseen hook files """
86
for hook in self._hooks:
87
if not self._hooks[hook].seen:
88
new.append(self._hooks[hook])
94
new = hooks.checkNew()
100
new = hooks.checkNew()
101
print("Hooks: %s" % len(new))
102
for hook in hooks._hooks:
103
print(hooks._hooks[hook].notification)
106
if __name__ == "__main__":
107
parser = OptionParser()
108
parser.add_option("-c", "--check", action="store_true", dest="check",
109
default=False, help="check for new hooks")
110
parser.add_option("-r", "--run", action="store_true", dest="run",
111
default=False, help="run interactive hook view")
112
parser.add_option("-t", "--test", action="store_true", dest="test",
113
default=False, help="run test")
114
(options, args) = parser.parse_args()