Skip to content

Instantly share code, notes, and snippets.

@hron84
Last active December 18, 2015 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hron84/5818615 to your computer and use it in GitHub Desktop.
Save hron84/5818615 to your computer and use it in GitHub Desktop.
Plop

Portage status icon

This gist is a simple status icon for Gentoo Portage

Requirements

The script depends on qlop command, what is provided by app-portage/portage-utils package.

Also, you have to be a member of the portage group

Installation

Just copy plop.py somewhere you can execute easily. Optionally add it to startup applications.

Known bugs & limitations

  • Plop currently handles only one package to report. If you run two or more package installation parallel or if you use --jobs switch of emerge, then you will be notified about oldest installation process.
  • Plop currently does not have a configuration file. To customize check interval or notification display timeout, edit the value of the two constant at the beginning of the script.

License

This script is provided to public domain AS-IS without any warranty.

Copyright (C) 2013 Gabor Garami

#!/usr/bin/env python
import sys, os, re
import pygtk
pygtk.require('2.0')
import gtk
import pynotify
from pynotify import Notification
#### Configuration area ####
# Frequency of portage status query (ms)
REFRESH_TIMEOUT = 3000
# Notification display timeout (ms)
NOTIFY_TIMEOUT = 2000
### DO NOT MODIFY ME BELOW THIS LINE ###
class CurrentMerge:
def __init__(self):
self.actPkg = ""
pynotify.init('CurrentMerge')
self.statusIcon=gtk.StatusIcon()
self.setIconStatus()
self.statusIcon.set_visible(True)
self.menu = gtk.Menu()
mi = gtk.ImageMenuItem(gtk.STOCK_QUIT)
mi.connect('activate', gtk.main_quit, self.statusIcon)
self.menu.append(mi)
self.statusIcon.connect('popup-menu', self.popupMenu, self.menu)
self.statusIcon.connect('activate', self.activate)
self.statusIcon.set_visible(1)
def popupMenu(self,widget,button,time,data = None):
if button == 3:
if data:
data.show_all()
data.popup(None, None, gtk.status_icon_position_menu,
3, time, self.statusIcon)
def setIconStatus(self, *args):
self.__debug("Time tick")
res = self.actualPackage()
if res:
pkg, time = res
else:
pkg = time = False
# TODO make it i18n-aware
if not pkg:
self.statusIcon.set_tooltip("No package being merged")
self.statusIcon.set_from_stock(gtk.STOCK_MEDIA_STOP)
else:
self.statusIcon.set_tooltip("Currently merging: %s " % pkg)
self.statusIcon.set_from_stock(gtk.STOCK_MEDIA_PLAY)
if pkg and self.actPkg != pkg:
self.notifyPkg(pkg, time)
self.actPkg = pkg
self.actTime = time
gtk.timeout_add(REFRESH_TIMEOUT, self.setIconStatus)
def activate(self, widget, *data):
self.notifyPkg(self.actPkg, self.actTime)
def notifyPkg(self, pkg, time):
self.notify("Installing %s" % pkg, time)
def notify(self, msg, body = ''):
notice = Notification(msg, body, 'package')
notice.set_timeout(2000)
notice.show()
def actualPackage(self):
rawlines = os.popen('qlop -cC').readlines()
lines = [line.strip() for line in rawlines]
if len(lines) == 0:
return False
else:
return (lines[0].replace('* ', ''), lines[-1])
def __debug(self, msg):
if len(sys.argv) > 1 and sys.argv[1] == 'debug':
print("DEBUG: %s" % msg)
# END CLASS
if __name__ == '__main__':
app = CurrentMerge()
gtk.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment