Parent: [a8bcd2] (diff)

Download this file

react.py    85 lines (72 with data), 3.4 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import logging
from lamson.routing import route, route_like, stateless
from config.settings import relay
from lamson import view, queue
import os
import ming
import pylons
from pylons import c
from paste.deploy import appconfig
from pyforge.config.environment import load_environment
from pyforge import model as M
from pyforge.model import Project
from pyforge.lib.app_globals import Globals
logging.config.fileConfig("config/react_logging.conf")
class EmptyClass(object): pass
class ProjectContents:
def __init__(self,indict):
self.contents = indict
def __getattr__(self,which):
return self.contents.get(which,None)
@route("(appmount)\\.(apploc)@(proj)\\.(host)", appmount=".*", apploc=".*", proj=".*")
@stateless
def REACTING(message, post_name=None, appmount=None, apploc=None, proj=None, host=None):
conf = appconfig('config:%s' % '../pyforge/development.ini',relative_to=os.getcwd())
load_environment(conf.global_conf, conf.local_conf)
pylons.c._push_object(EmptyClass())
pylons.g._push_object(Globals())
ming.configure(**conf)
try:
valid = ProjectContents(Project.query.find({"name":proj, "database":"projects:"+proj}).one())
except:
try:
valid = ProjectContents(Project.query.find({"name":proj, "database":"users:"+proj}).one())
except:
logging.debug('REACT: project "' + proj + '" does not exist as project or user')
else:
logging.debug('REACT: project "' + proj + '" exists as user with _id:' + valid._id)
else:
logging.debug('REACT: project "' + proj + '" exists as project with _id:' + valid._id)
try:
c.project = Project.query.get(_id=valid._id)
except:
logging.debug('REACT: cannot initialize valid project')
else:
logging.debug('REACT: retrieved valid project with mount point:' + appmount)
try:
c.project.app_config(appmount)
c.app = c.project.app_instance(appmount)
plugin_name=c.app.config.plugin_name
except:
logging.debug('REACT: invalid mount point (' + appmount + ')')
else:
logging.debug('REACT: valid mount point (' + appmount + ') with plugin_name:' + plugin_name)
routing_key = plugin_name + '.' + apploc
mailto = message.__getitem__('To')
mailfrom = message.__getitem__('From')
mailsubj = message.__getitem__('Subject')
mailbody = message.body()
logging.debug('REACT: *** TO *** = ' + mailto)
logging.debug('REACT: *** FROM *** = ' + mailfrom)
logging.debug('REACT: *** SUBJECT *** = ' + mailsubj)
logging.debug('REACT: *** CONTENT *** = ' + message.body())
try:
pylons.g.publish('audit', routing_key,
dict(to=mailto,fro=mailfrom,subject=mailsubj,body=mailbody),
# dict(content=str(message)),
serializer='yaml')
except:
logging.debug('REACT: unable to queue message in carrot')
else:
logging.debug('REACT: successfully queued message in carrot with key:' + routing_key)
return REACTING