Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
isaak yansane-sisk
slapos
Commits
adc1b1a1
Commit
adc1b1a1
authored
Nov 02, 2012
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
track multiple callbacks
parent
ff9e82be
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
5 deletions
+23
-5
slapos/recipe/librecipe/generic.py
slapos/recipe/librecipe/generic.py
+18
-1
slapos/recipe/notifier.py
slapos/recipe/notifier.py
+5
-4
No files found.
slapos/recipe/librecipe/generic.py
View file @
adc1b1a1
# -*- 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
)
...
...
slapos/recipe/notifier.py
View file @
adc1b1a1
...
...
@@ -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'
])]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment