Created
December 19, 2012 18:44
-
-
Save pcon/4339272 to your computer and use it in GitHub Desktop.
Watches a folder for a new rpm and runs createrepo after it has been updated. Plus sends a pushover notification.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import httplib, urllib | |
from subprocess import call | |
ROOT_DIR = '/path/to/dir' | |
wm = pyinotify.WatchManager(); | |
mask = pyinotify.IN_CLOSE_WRITE | |
def pushover(message): | |
conn = httplib.HTTPSConnection("api.pushover.net:443") | |
conn.request("POST", "/1/messages.json", | |
urllib.urlencode({ | |
"token": "TOKEN", | |
"user": "USER", | |
"message": message, | |
}), { "Content-type": "application/x-www-form-urlencoded" }) | |
conn.getresponse() | |
def gen_repo(): | |
pushover('rebuilding repo') | |
call(["createrepo", ROOT_DIR]) | |
class EventHandler(pyinotify.ProcessEvent): | |
def process_IN_CLOSE_WRITE(self, event): | |
if event.pathname.endswith('.rpm'): | |
gen_repo() | |
handler = EventHandler(); | |
notifier = pyinotify.Notifier(wm, handler) | |
wdd = wm.add_watch(ROOT_DIR, mask, rec=True) | |
notifier.loop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment