Skip to content
Browse files

Merge pull request #9 from kevinjalbert/ignore_oneself

Feature: Blacklist authors/projects
  • Loading branch information...
2 parents c77bd6a + 0e2d836 commit 8eab46bb81a38697bf5e25d90fded9778a0a88b0 @abiczo abiczo committed Dec 2, 2011
Showing with 147 additions and 63 deletions.
  1. +12 −2 README.md
  2. +135 −61 githubnotifier.py
View
14 README.md
@@ -52,11 +52,14 @@ the `-p` flag. A *config.cfg* file is present within your *~/.githubnotifier/*
directory. The file will be generated if it is not present at run-time.
The *config.cfg* format is as follows:
-
+
[important]
authors=bob,fred,mary
projects=github-notifier,rails,bob/my-project
-
+ [blacklist]
+ authors=james
+ projects=bad_project
+
This configuration will only show notifications that have *bob*, *fred* or
*mary* as the authors. The projects can either be in a general format (ex:
*github-notifier* or *rails*) to only show notifications that deal with either
@@ -65,6 +68,13 @@ project name, regardless of who is the owner of the repository. The stricter
format (ex: *bob/my-project*) will only show notifications of the *my-project*
repository if the owner if *bob*.
+It is also possible to completely blacklist notifications from certain authors
+and/or projects. This is configured the same way as for *important* projects,
+but now the configuration falls under the *blacklist* category.
+
+Filters for important authors/projects will **override** filters for
+blacklisted authors/projects if they both are enabled.
+
TODO
----
View
196 githubnotifier.py
@@ -111,15 +111,25 @@ def __init__(self, upd):
menu_github.show()
self.menu.append(menu_github)
- menu_authors = gtk.CheckMenuItem('Filter Important Authors')
- menu_authors.connect('activate', self.filter_authors)
- menu_authors.show()
- self.menu.append(menu_authors)
-
- menu_projects = gtk.CheckMenuItem('Filter Important Projects')
- menu_projects.connect('activate', self.filter_projects)
- menu_projects.show()
- self.menu.append(menu_projects)
+ menu_important_authors = gtk.CheckMenuItem('Only Important Authors')
+ menu_important_authors.connect('activate', self.important_authors)
+ menu_important_authors.show()
+ self.menu.append(menu_important_authors)
+
+ menu_important_projects = gtk.CheckMenuItem('Only Important Projects')
+ menu_important_projects.connect('activate', self.important_projects)
+ menu_important_projects.show()
+ self.menu.append(menu_important_projects)
+
+ menu_blacklist_authors = gtk.CheckMenuItem('Exclude Blacklisted Authors')
+ menu_blacklist_authors.connect('activate', self.blacklist_authors)
+ menu_blacklist_authors.show()
+ self.menu.append(menu_blacklist_authors)
+
+ menu_blacklist_projects = gtk.CheckMenuItem('Exclude Blacklisted Projects')
+ menu_blacklist_projects.connect('activate', self.blacklist_projects)
+ menu_blacklist_projects.show()
+ self.menu.append(menu_blacklist_projects)
menu_about = gtk.ImageMenuItem(gtk.STOCK_ABOUT)
menu_about.connect('activate', self.show_about)
@@ -131,45 +141,85 @@ def __init__(self, upd):
menu_quit.show()
self.menu.append(menu_quit)
+ # References to the CheckMenuItems
+ self.menu_important_authors = menu_important_authors
+ self.menu_important_projects = menu_important_projects
+ self.menu_blacklist_authors = menu_blacklist_authors
+ self.menu_blacklist_projects = menu_blacklist_projects
+
self.systray_icon.connect('popup_menu', self.show_menu)
+ # Initialize the CheckMenuItems
if self.upd.important_authors:
- menu_authors.set_active(True)
- else:
- menu_authors.set_active(False)
-
+ menu_important_authors.set_active(True)
if self.upd.important_projects:
- menu_projects.set_active(True)
- else:
- menu_projects.set_active(False)
+ menu_important_projects.set_active(True)
+ if self.upd.blacklist_authors:
+ menu_blacklist_authors.set_active(True)
+ if self.upd.blacklist_projects:
+ menu_blacklist_projects.set_active(True)
def show_menu(self, icon, button, time):
self.logger.info('Opening menu')
self.menu.popup(None, None, gtk.status_icon_position_menu, button,
time, icon)
- def filter_authors(self, item):
+ def important_authors(self, item):
if item.active:
- self.logger.info('Enabling author filter')
+ self.logger.info('Enabling important authors')
config = ConfigParser.ConfigParser()
config.read(CONFIG_FILE)
- self.upd.acquire_authors(config)
- self.upd.important_authors = True
+ items = self.upd.acquire_items(config, "important", "authors")
+ if items:
+ self.upd.important_authors = True
+ else:
+ self.menu_important_authors.set_active(False)
else:
- self.logger.info('Disabling author filter')
+ self.logger.info('Disabling important authors')
self.upd.important_authors = False
- def filter_projects(self, item):
+ def important_projects(self, item):
if item.active:
- self.logger.info('Enabling project filter')
+ self.logger.info('Enabling important projects')
config = ConfigParser.ConfigParser()
config.read(CONFIG_FILE)
- self.upd.acquire_projects(config)
- self.upd.important_projects = True
+ items = self.upd.acquire_items(config, "important", "projects")
+ if items:
+ self.upd.important_projects = True
+ else:
+ self.menu_important_projects.set_active(False)
else:
- self.logger.info('Disabling project filter')
+ self.logger.info('Disabling important projects')
self.upd.important_projects = False
+ def blacklist_authors(self, item):
+ if item.active:
+ self.logger.info('Enabling blacklist authors')
+ config = ConfigParser.ConfigParser()
+ config.read(CONFIG_FILE)
+ items = self.upd.acquire_items(config, "blacklist", "authors")
+ if items:
+ self.upd.blacklist_authors = True
+ else:
+ self.menu_blacklist_authors.set_active(False)
+ else:
+ self.logger.info('Disabling blacklist authors')
+ self.upd.blacklist_authors = False
+
+ def blacklist_projects(self, item):
+ if item.active:
+ self.logger.info('Enabling blacklist projects')
+ config = ConfigParser.ConfigParser()
+ config.read(CONFIG_FILE)
+ items = self.upd.acquire_items(config, "blacklist", "projects")
+ if items:
+ self.upd.blacklist_projects = True
+ else:
+ self.menu_blacklist_projects.set_active(False)
+ else:
+ self.logger.info('Disabling blacklist projects')
+ self.upd.blacklist_projects = False
+
def show_github(self, item):
self.logger.info('Opening GitHub website')
webbrowser.open(GITHUB_URL)
@@ -190,7 +240,8 @@ def show_about(self, item):
class GithubFeedUpdatherThread(threading.Thread):
def __init__(self, user, token, interval, max_items, hyperlinks, blog,
- important_authors, important_projects):
+ important_authors, important_projects, blacklist_authors,
+ blacklist_projects):
threading.Thread.__init__(self)
self.logger = logging.getLogger('github-notifier')
@@ -207,35 +258,21 @@ def __init__(self, user, token, interval, max_items, hyperlinks, blog,
self.interval = interval
self.max_items = max_items
self.hyperlinks = hyperlinks
+ self._seen = {}
self.important_authors = important_authors
self.important_projects = important_projects
- self._seen = {}
- self.authors = []
- self.projects = []
-
- def acquire_authors(self, config):
- # Make list of important authors
- authors = config.get('important', 'authors')
- self.authors = [author for author in authors.split(',') if author]
- self.logger.info('Important Author: {}'.format(self.authors))
-
- # Check to ensure authors were acquired
- if not self.authors:
- self.logger.warning('No important authors were found, ensure the'\
- ' config is correct. Disabling author filter')
- self.important_authors = False
-
- def acquire_projects(self, config):
- # Make list of important projects
- projects = config.get('important', 'projects')
- self.projects = [project for project in projects.split(',') if project]
- self.logger.info('Important Project: {}'.format(self.projects))
-
- # Check to ensure projects were acquired
- if not self.projects:
- self.logger.warning('No important projects were found, ensure the'\
- ' config is correct. Disabling project filter')
- self.important_projects = False
+ self.blacklist_authors = blacklist_authors
+ self.blacklist_projects = blacklist_projects
+ self.list_important_authors = []
+ self.list_important_projects = []
+ self.list_blacklist_authors = []
+ self.list_blacklist_projects = []
+
+ def acquire_items(self, config, category, items):
+ config_items = config.get(category, items)
+ aquired_items = [item for item in config_items.split(',') if item]
+ self.logger.info("Items in {} {}: {}".format(category, items, aquired_items))
+ return aquired_items
def run(self):
while True:
@@ -269,6 +306,9 @@ def update_feeds(self, feeds):
users = {}
l = []
+ found_author = False
+ found_project = False
+
for item in notifications:
if not item['author'] in users:
users[item['author']] = get_github_user_info(item['author'])
@@ -293,15 +333,15 @@ def update_feeds(self, feeds):
# Check for important project entry
if self.important_projects:
- for project in self.projects:
+ for project in self.list_important_projects:
found_project = self.important_repository(item['link'],
project)
if found_project:
break
# Check for important author entry
if self.important_authors:
- found_author = item['authors'][0]['name'] in self.authors
+ found_author = item['authors'][0]['name'] in self.list_important_authors
# Report and add only relevant entries
if self.important_authors and found_author:
@@ -311,8 +351,29 @@ def update_feeds(self, feeds):
self.logger.info('Found important project item entry')
l.append(n)
elif not self.important_authors and not self.important_projects:
- self.logger.info('Found item entry')
- l.append(n)
+
+ ignore_author = False
+ ignore_project = False
+
+ # Check to see if entry is a blacklisted author
+ if self.blacklist_authors and item['authors'][0]['name'] in self.list_blacklist_authors:
+ self.logger.info('Ignoring blacklisted author entry')
+ ignore_author = True
+
+ # Check to see if entry is a blacklisted project
+ if self.blacklist_projects:
+ for project in self.list_blacklist_projects:
+ ignore_project = self.important_repository(item['link'],
+ project)
+ if ignore_project:
+ self.logger.info('Ignoring blacklisted project entry')
+ break
+
+ if not ignore_author and not ignore_project:
+ self.logger.info('Found item entry')
+ l.append(n)
+ else:
+ self.logger.info('Ignoring non-important item entry')
notification_queue.put(l)
@@ -379,10 +440,18 @@ def main():
parser.add_option('-p', '--important_projects',
action='store_true', dest='important_projects', default=False,
help='only consider notifications from important projects')
+ parser.add_option('-u', '--blacklist_authors',
+ action='store_true', dest='blacklist_authors', default=False,
+ help='filter out blacklisted authors')
+ parser.add_option('-r', '--blacklist_projects',
+ action='store_true', dest='blacklist_projects', default=False,
+ help='filter out blacklisted projects')
+ parser.add_option('-n', '--new-config',
+ action='store_true', dest='new_config', default=False,
+ help='create a new config.cfg at ~/.githubnotifier/')
parser.add_option('-v', '--verbose',
action='store_true', dest='verbose', default=False,
help='enable verbose logging')
-
(options, args) = parser.parse_args()
# Create logger
@@ -411,12 +480,15 @@ def main():
logger.warning('Making the cache directory {}'.format(CACHE_DIR))
os.makedirs(CACHE_DIR)
- if not os.path.isfile(CONFIG_FILE):
+ if not os.path.isfile(CONFIG_FILE) or options.new_config:
logger.warning('Making the config file {}'.format(CONFIG_FILE))
config_file = open(CONFIG_FILE, 'w')
config_file.write('[important] # Separated by commas, projects (can' \
' be either <user>/<project> or <project>)\n')
config_file.write('authors=\nprojects=')
+ config_file.write('\n[blacklist] # Separated by commas, projects (can' \
+ ' be either <user>/<project> or <project>)\n')
+ config_file.write('authors=\nprojects=')
config_file.close()
if not pynotify.init('github-notifier'):
@@ -444,7 +516,9 @@ def main():
upd = GithubFeedUpdatherThread(user, token, options.interval,
options.max_items, hyperlinks, options.blog,
options.important_authors,
- options.important_projects)
+ options.important_projects,
+ options.blacklist_authors,
+ options.blacklist_projects)
upd.setDaemon(True)
upd.start()

0 comments on commit 8eab46b

Please sign in to comment.
Something went wrong with that request. Please try again.