Revisions
-
narusemotoki revised this gist
Jul 31, 2012 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -9,10 +9,9 @@ import signal def getPath(dir, prefix = None): files = sorted(filter(lambda f: os.path.isfile(dir + f), os.listdir(dir))) if None != prefix: files = filter(lambda f: f.startswith(prefix), files) return dir + files[-1] class Tailer: -
narusemotoki revised this gist
Jul 31, 2012 . 1 changed file with 12 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -8,9 +8,11 @@ from threading import Thread import signal def getPath(dir, prefix = None): files = sorted(filter(lambda f: os.path.isfile(f), os.listdir(dir))) if None != prefix: files = filter(lambda f: f.startswith(prefix), files) print files return dir + files[-1] class Tailer: @@ -20,12 +22,17 @@ def __call__(self, path): self.proc = subprocess.Popen('tail -f ' + path, shell=True) argv = sys.argv if 1 == len(argv): print(u'第一引数に監視対象のディレクトリを指定してください') print(u'第二引数にファイルの接頭語を指定することが任意でできます') sys.exit() dir = argv[1] if '/' == argv[1][-1] else argv[1] + '/' prefix = None if 3 != len(argv) else argv[2] print('watching: ' + dir) last = '' tailer = None while(True): path = getPath(dir, prefix) if path != last: print path if None != tailer: @@ -34,4 +41,4 @@ def __call__(self, path): tailer = Tailer() thread = Thread(target=tailer, args=(path, )) thread.start() time.sleep(1) -
narusemotoki created this gist
Jul 30, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- import sys import os import time import subprocess from threading import Thread import signal def getPath(dir): files = sorted(filter(lambda f: not os.path.isdir(f), os.listdir(dir))) return dir + files[-1] class Tailer: proc = None def __call__(self, path): self.proc = subprocess.Popen('tail -f ' + path, shell=True) argv = sys.argv dir = argv[1] if '/' == argv[1][-1] else argv[1] + '/' print('watching: ' + dir) last = '' tailer = None while(True): path = getPath(dir) if path != last: print path if None != tailer: os.kill(tailer.proc.pid, signal.SIGUSR1) last = path tailer = Tailer() thread = Thread(target=tailer, args=(path, )) thread.start() time.sleep(1)