本文整理汇总了Python中notifier.Notifier.message方法的典型用法代码示例。如果您正苦于以下问题:Python Notifier.message方法的具体用法?Python Notifier.message怎么用?Python Notifier.message使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类notifier.Notifier
的用法示例。
在下文中一共展示了Notifier.message方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from notifier import Notifier [as 别名]
# 或者: from notifier.Notifier import message [as 别名]
def run (repository):
n = Notifier( title=NOTIFIER_TITLE )
n.message( message=( "committer::run( '%s' )" % repository ) )
# - create a lock file
file_lock = open( Config.PATH_TETHERBALL_COMMIT, 'w' )
file_lock.write( str( os.getpid() ) )
file_lock.close()
# timeout
time.sleep( SEC_SLEEP )
try:
str_last = subprocess.check_output( COMMAND, shell=True )
ms_now = int( time.time() * 1000 )
if str_last != '':
ms_last = int( str_last.strip() )
else:
ms_last = ms_now - int(SEC_SLEEP * 1000) - 1
if (ms_now - ms_last) > (SEC_SLEEP * 1000):
_run_main(repository)
else:
run(repository)
except Exception, e:
l = Logger(Config)
l.debug( 'Failed on committer.py: %s' % e)
示例2: run
# 需要导入模块: from notifier import Notifier [as 别名]
# 或者: from notifier.Notifier import message [as 别名]
def run (path, repository):
#imports
import daemon
# daemonize
pid = daemon.createDaemon()
# spit pid
try:
file_pid = open( os.path.join( Config.PATH_TETHERBALL_PROC, repository ), 'w' )
file_pid.write( str(pid) )
file_pid.close()
except Exception, e:
# l = Logger(Config)
# l.debug( "Failed to write pid into file: %s" )
n = Notifier( title=NOTIFIER_TITLE )
n.message( message=("Failed to write pid into file: %s" % e) )
示例3: log_error
# 需要导入模块: from notifier import Notifier [as 别名]
# 或者: from notifier.Notifier import message [as 别名]
def log_error (msg):
n = Notifier( title=NOTIFIER_TITLE )
n.message( message=( msg ) )
l = Logger(Config)
l.debug( msg )
print(msg)
示例4: len
# 需要导入模块: from notifier import Notifier [as 别名]
# 或者: from notifier.Notifier import message [as 别名]
try:
if len(action_add) > 0:
git.add( *action_add )
if len(action_rm) > 0:
git.rm( *action_rm )
if len(action_add) > 0 or len(action_rm) > 0:
_t = int( time.time() )
git.commit( '-m tetherball %d' % _t )
# git.push()
except Exception, e:
log_error( "Failed to operate git: %s" % e )
exit( 1 )
# - run notifier
n = Notifier( title=NOTIFIER_TITLE )
n.message( message=("Files added: (%s) removed(%s)" % (", ".join(action_add), ", ".join(action_rm)) ) )
# - delete lock file
try:
# delete all queues
shutil.rmtree( Config.PATH_TETHERBALL_QUEUE )
os.mkdir( Config.PATH_TETHERBALL_QUEUE )
# delete lock file
os.unlink( Config.PATH_TETHERBALL_COMMIT )
except Exception, e:
log_error( "Failed to delete lock file: %s" % e )
# - check if there's standbys
# FIXME: implement this
exit( 0 )
示例5: _callback
# 需要导入模块: from notifier import Notifier [as 别名]
# 或者: from notifier.Notifier import message [as 别名]
def _callback(FileEvent):
try:
timestamp = int(time.time())
d = Data( config=Config )
len_path_prefix = len( Config.repository[ repository ]['local'] )
event_path = FileEvent.name[len_path_prefix:]
arr_event_path = event_path.split( os.sep )
basedir_event_path = os.sep.join( arr_event_path[0:-1] )
basename_event_path = arr_event_path[-1]
ignores = Config.repository[ repository ]['ignore']
is_matched = False
#debug
l = Logger(Config)
n = Notifier( title=NOTIFIER_TITLE )
n.message( message=("time: %i, repo: %s, path: %s, mask: %s, cookie: %s" % (timestamp, repository, FileEvent.name, FileEvent.mask, FileEvent.cookie)) )
l.debug( "FSEvent: repository(%s), event_path(%s), config(%s)" % (repository, event_path, json.dumps(Config.repository[repository]) ) )
# FIXME: this won't support * dir name. For example: "foo/*/bar"
# FIXME: ignore path should not start with "/". Bad => "/foo/", Good => "foo/"
# FIXME: probably this path matching algo needs to be external and tests.
for ignore_path in ignores:
arr_ignore_path = ignore_path.split( os.sep )
regex_matcher = regex_matchee = None
# l.debug( 'matcher: %s (%i) matchee: %s (%i)' % (ignore_path, len(arr_ignore_path), event_path, len(arr_event_path)) )
if len( arr_ignore_path ) > 1:
basedir_ignore_path = os.sep.join( arr_ignore_path[0:-1] )
basename_ignore_path = arr_ignore_path[-1]
partial_basedir_ignore_path = os.sep + basedir_ignore_path + os.sep
if len( arr_event_path ) > 1:
# - ignore includes '/' and event path includes '/'
if basename_ignore_path == '':
# - ignore points to directory
# if the ignore path is a part of event, it's matched
if basedir_event_path.startswith( basedir_ignore_path ):
is_matched = True
elif partial_basedir_ignore_path in basedir_ignore_path:
is_matched = True
else:
# - ignore points to deep file
# if the ignore path is a part of event
# then blob match
if basedir_event_path.startswith( basedir_ignore_path ):
regex_matcher = re.compile( fnmatch.translate(basename_ignore_path) )
regex_matchee = basename_event_path
elif partial_basedir_ignore_path in basedir_ignore_path:
regex_matcher = re.compile( fnmatch.translate(basename_ignore_path) )
regex_matchee = basename_event_path
else:
# - ignore includes '/' and event path doesn't include '/'
pass
else:
if len( arr_event_path ) > 1:
# - ignore doesn't include '/' and event path includes '/'
regex_matcher = re.compile( fnmatch.translate(ignore_path) )
regex_matchee = basename_event_path
else:
# - ignore doesn't include '/' and event path doesn't include '/'
regex_matcher = re.compile( fnmatch.translate(ignore_path) )
regex_matchee = event_path
if is_matched or ((regex_matcher and regex_matchee) and regex_matcher.match( regex_matchee )):
is_matched = True
# l.debug( " ** %s matched to %s" % (event_path, ignore_path) )
continue
if is_matched:
# l.debug( "IGNORED: %s" % event_path )
pass
else:
# l.debug( "REGISTERED: %s" % event_path )
d.queue( timestamp, [{'repository': repository, 'path': event_path }] )
# make file-base queue
# try:
# open( os.path.join( Config.PATH_TETHERBALL_QUEUE, str(int(time.time() * 1000))), 'w').close()
# path_exec = os.path.join( path_origin, 'committer.py' )
# l.debug( 'WATCHER RUNS: %s' % path_exec )
# proc_commiter = subprocess.Popen( [path_exec, repository] )
# proc_commiter.communicate()
# if proc_commiter.returncode != 0:
# raise Exception ('Return code: %d' % proc_commiter.returncode)
# except Exception, e:
# l.debug( 'Failed to run committer?: %s' % e )
except Exception, e:
n.message( message=("Error on FileEvent callback: %s" % e) )
l.debug( "Error on FileEvent callback: %s" % e )