Commit adc1b1a1 authored by Marco Mariani's avatar Marco Mariani

track multiple callbacks

parent ff9e82be
# -*- coding: utf-8 -*-
# vim: set et sts=2:
##############################################################################
#
# Copyright (c) 2010 Vifib SARL and Contributors. All Rights Reserved.
......@@ -24,6 +26,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import io
import logging
import os
import sys
......@@ -90,6 +93,21 @@ class GenericBaseRecipe(object):
def createExecutable(self, name, content, mode=0700):
return self.createFile(name, content, mode)
def addLineToFile(self, filepath, line, encoding='utf8'):
"""Append a single line to a text file, if the line does not exist yet.
line must be unicode."""
try:
lines = io.open(filepath, 'r', encoding=encoding).readlines()
except IOError:
lines = []
if not line in lines:
lines.append(line)
with io.open(filepath, 'w+', encoding=encoding) as f:
f.write(u'\n'.join(lines))
def createPythonScript(self, name, absolute_function, arguments=''):
"""Create a python script using zc.buildout.easy_install.scripts
......@@ -115,7 +133,6 @@ class GenericBaseRecipe(object):
Takes care of quoting.
"""
q = shlex.quote
lines = [
'#!/bin/sh',
'exec %s' % shlex.quote(command)
......
......@@ -47,12 +47,13 @@ class Callback(GenericBaseRecipe):
def createCallback(self, notification_id, callback):
callback_id = sha512(notification_id).hexdigest()
callback = self.createFile(os.path.join(self.options['callbacks'],
callback_id),
callback)
return callback
filepath = os.path.join(self.options['callbacks'], callback_id)
self.addLineToFile(filepath, callback)
return filepath
def install(self):
# XXX this path is returned multiple times, one for each callback that has been added.
return [self.createCallback(self.options['on-notification-id'],
self.options['callback'])]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment