Created
March 21, 2011 17:15
-
-
Save mizchi/879809 to your computer and use it in GitHub Desktop.
ファイル監視
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
| #!/usr/local/bin/python | |
| #-*- coding:utf-8 -*- | |
| import os, sys | |
| import commands | |
| import Growl | |
| from time import sleep | |
| from glob import glob | |
| build_command = "./build.sh" | |
| output_dir = "out" | |
| sleep_time = 1 | |
| g = Growl.GrowlNotifier( | |
| applicationName='Autobuild', | |
| notifications=['Build']) | |
| g.register() | |
| dirname = os.path.dirname(__file__) | |
| def notify(fname,text): | |
| g.notify( | |
| noteType='Build', | |
| title=fname, | |
| description= text, | |
| sticky=False) | |
| state = {} | |
| def is_updated(): | |
| ret = False | |
| for i in glob("*"): | |
| uptime = os.path.getmtime(dirname+i) | |
| if not i in state: | |
| if i == output_dir: | |
| continue | |
| state[i] = uptime | |
| print i,uptime | |
| elif uptime > state[i] : | |
| state[i] = uptime | |
| ret = True | |
| print i,uptime | |
| return ret | |
| def main(): | |
| while 1: | |
| if is_updated(): | |
| notify("Autobuild", commands.getoutput(build_command)) | |
| sleep(sleep_time) | |
| if __name__ == "__main__": | |
| main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment