def on_db_complete(self, success, db_results): self.check_db_results(success, db_results) insert_results, select_results = db_results pushurl = '/push?id=%s' % insert_results.lastrowid if self.pushtype in ('private', 'morning'): people = None elif self.pushtype == 'urgent': people = set(x['user'] for x in select_results if 'urgent' in x['tags'].split(',')) else: people = set(x['user'] for x in select_results) pushmanager_servername = Settings['main_app']['servername'] pushmanager_url = "https://%s%s" % (pushmanager_servername, pushurl) if people: subprocess.call([ '/nail/sys/bin/nodebot', '-i', Settings['irc']['nickname'], Settings['irc']['channel'], '%s: %s push starting! %s' % (', '.join(people), self.pushtype, pushmanager_url), ]) XMPPQueue.enqueue_user_xmpp(people, 'Push starting! %s' % pushmanager_url) elif self.pushtype == 'morning': subprocess.call([ '/nail/sys/bin/nodebot', '-i', Settings['irc']['nickname'], Settings['irc']['channel'], 'Morning push opened. %s' % (pushmanager_servername, ), ]) return self.redirect(pushurl)
def on_db_complete(self, success, db_results): self.check_db_results(success, db_results) for req in db_results[-1]: msg = (""" <p> %(pushmaster)s has accepted your request into a push: </p> <p> <strong>%(user)s - %(title)s</strong><br /> <em>%(repo)s/%(branch)s</em> </p> <p> Regards,<br /> PushManager </p>""") % core.util.EscapedDict({ 'pushmaster': self.current_user, 'user': req['user'], 'title': req['title'], 'repo': req['repo'], 'branch': req['branch'], }) subject = "[push] %s - %s" % (req['user'], req['title']) MailQueue.enqueue_user_email([req['user']], msg, subject) msg = '%(pushmaster)s has accepted your request "%(title)s" into a push:\nhttps://%(pushmanager_servername)s/push?id=%(pushid)s' % { 'pushmanager_servername': Settings['main_app']['servername'], 'pushmaster': self.current_user, 'title': req['title'], 'pushid': self.pushid, } XMPPQueue.enqueue_user_xmpp([req['user']], msg)
def on_db_complete(self, success, db_results): self.check_db_results(success, db_results) insert_results, select_results = db_results pushurl = '/push?id=%s' % insert_results.lastrowid if self.pushtype in ('private', 'morning'): people = None elif self.pushtype == 'urgent': people = set(x['user'] for x in select_results if 'urgent' in x['tags'].split(',')) else: people = set(x['user'] for x in select_results) pushmanager_servername = Settings['main_app']['servername'] pushmanager_url = "https://%s%s" % (pushmanager_servername, pushurl) if people: subprocess.call([ '/nail/sys/bin/nodebot', '-i', Settings['irc']['nickname'], Settings['irc']['channel'], '%s: %s push starting! %s' % (', '.join(people), self.pushtype, pushmanager_url), ]) XMPPQueue.enqueue_user_xmpp(people, 'Push starting! %s' % pushmanager_url) elif self.pushtype == 'morning': subprocess.call([ '/nail/sys/bin/nodebot', '-i', Settings['irc']['nickname'], Settings['irc']['channel'], 'Morning push opened. %s' % (pushmanager_servername,), ]) return self.redirect(pushurl)
def start_services(self): # HTTPS server sockets = tornado.netutil.bind_sockets( self.port, address=Settings['main_app']['servername']) redir_sockets = tornado.netutil.bind_sockets( self.redir_port, address=Settings['main_app']['servername']) tornado.process.fork_processes(0) server = tornado.httpserver.HTTPServer( self.main_app, ssl_options={ 'certfile': Settings['main_app']['ssl_certfile'], # This really should be read into a string so we can drop privileges # after reading the key but before starting the server, but Python # doesn't let us use strings for keys until Python 3.2 :( 'keyfile': Settings['main_app']['ssl_keyfile'], }) server.add_sockets(sockets) # HTTP server (to redirect to HTTPS) redir_server = tornado.httpserver.HTTPServer(self.redir_app) redir_server.add_sockets(redir_sockets) # Start the mail, git, reviewboard and XMPP queue handlers MailQueue.start_worker() GitQueue.start_worker() RBQueue.start_worker() XMPPQueue.start_worker()
def start_services(self): # HTTPS server sockets = tornado.netutil.bind_sockets(self.port, address=Settings["main_app"]["servername"]) redir_sockets = tornado.netutil.bind_sockets(self.redir_port, address=Settings["main_app"]["servername"]) tornado.process.fork_processes(0) server = tornado.httpserver.HTTPServer( self.main_app, ssl_options={ "certfile": Settings["main_app"]["ssl_certfile"], # This really should be read into a string so we can drop privileges # after reading the key but before starting the server, but Python # doesn't let us use strings for keys until Python 3.2 :( "keyfile": Settings["main_app"]["ssl_keyfile"], }, ) server.add_sockets(sockets) # HTTP server (to redirect to HTTPS) redir_server = tornado.httpserver.HTTPServer(self.redir_app) redir_server.add_sockets(redir_sockets) # Start the mail, git, reviewboard and XMPP queue handlers MailQueue.start_worker() GitQueue.start_worker() RBQueue.start_worker() XMPPQueue.start_worker()
def on_db_complete(self, success, db_results): self.check_db_results(success, db_results) for req in db_results[-1]: msg = ( """ <p> %(pushmaster)s has accepted your request into a push: </p> <p> <strong>%(user)s - %(title)s</strong><br /> <em>%(repo)s/%(branch)s</em> </p> <p> Regards,<br /> PushManager </p>""" ) % core.util.EscapedDict({ 'pushmaster': self.current_user, 'user': req['user'], 'title': req['title'], 'repo': req['repo'], 'branch': req['branch'], }) subject = "[push] %s - %s" % (req['user'], req['title']) MailQueue.enqueue_user_email([req['user']], msg, subject) msg = '%(pushmaster)s has accepted your request "%(title)s" into a push:\nhttps://%(pushmanager_servername)s/push?id=%(pushid)s' % { 'pushmanager_servername': Settings['main_app']['servername'], 'pushmaster': self.current_user, 'title': req['title'], 'pushid': self.pushid, } XMPPQueue.enqueue_user_xmpp([req['user']], msg)
def on_db_complete(self, success, db_results): self.check_db_results(success, db_results) _, staged_requests, push_result = db_results push = push_result.fetchone() for req in staged_requests: if req['watchers']: user_string = '%s (%s)' % (req['user'], req['watchers']) users = [req['user']] + req['watchers'].split(',') else: user_string = req['user'] users = [req['user']] msg = ( """ <p> %(pushmaster)s has deployed request for %(user)s to %(pushstage)s: </p> <p> <strong>%(user)s - %(title)s</strong><br /> <em>%(repo)s/%(branch)s</em> </p> <p> Once you've checked that it works, mark it as verified here: <a href="https://%(pushmanager_servername)s/push?id=%(pushid)s"> https://%(pushmanager_servername)s/push?id=%(pushid)s </a> </p> <p> Regards,<br /> PushManager </p>""" ) % core.util.EscapedDict({ 'pushmaster': self.current_user, 'pushmanager_servername': Settings['main_app']['servername'], 'user': user_string, 'title': req['title'], 'repo': req['repo'], 'branch': req['branch'], 'pushid': self.pushid, 'pushstage': push['stageenv'], }) subject = "[push] %s - %s" % (user_string, req['title']) MailQueue.enqueue_user_email(users, msg, subject) msg = '%(pushmaster)s has deployed request "%(title)s" for %(user)s to %(pushstage)s.\nPlease verify it at https://%(pushmanager_servername)s/push?id=%(pushid)s' % { 'pushmaster': self.current_user, 'pushmanager_servername': Settings['main_app']['servername'], 'title': req['title'], 'pushid': self.pushid, 'user': user_string, 'pushstage': push['stageenv'], } XMPPQueue.enqueue_user_xmpp(users, msg) if push['extra_pings']: for user in push['extra_pings'].split(','): XMPPQueue.enqueue_user_xmpp([user], '%s has deployed a push to stage.' % self.current_user)
def on_db_complete(self, success, db_results): self.check_db_results(success, db_results) push = db_results[0].first() unfinished_requests = db_results[2].first() pushmanager_servername = Settings['main_app']['servername'] if not unfinished_requests: msg = "All currently staged requests in http://%s/push?id=%s have been marked as verified." % (pushmanager_servername, self.pushid) XMPPQueue.enqueue_user_xmpp([push['user']], msg)
def on_db_complete(self, success, db_results): self.check_db_results(success, db_results) _, staged_requests, push_result = db_results for req in staged_requests: if req['watchers']: user_string = '%s (%s)' % (req['user'], req['watchers']) users = [req['user']] + req['watchers'].split(',') else: user_string = req['user'] users = [req['user']] msg = (""" <p> %(pushmaster)s has deployed request for %(user)s to stage: </p> <p> <strong>%(user)s - %(title)s</strong><br /> <em>%(repo)s/%(branch)s</em> </p> <p> Once you've checked that it works, mark it as verified here: <a href="https://%(pushmanager_servername)s/push?id=%(pushid)s"> https://%(pushmanager_servername)s/push?id=%(pushid)s </a> </p> <p> Regards,<br /> PushManager </p>""") % core.util.EscapedDict( { 'pushmaster': self.current_user, 'pushmanager_servername': Settings['main_app']['servername'], 'user': user_string, 'title': req['title'], 'repo': req['repo'], 'branch': req['branch'], 'pushid': self.pushid, }) subject = "[push] %s - %s" % (user_string, req['title']) MailQueue.enqueue_user_email(users, msg, subject) msg = '%(pushmaster)s has deployed request "%(title)s" for %(user)s to stage.\nPlease verify it at https://%(pushmanager_servername)s/push?id=%(pushid)s' % { 'pushmaster': self.current_user, 'pushmanager_servername': Settings['main_app']['servername'], 'title': req['title'], 'pushid': self.pushid, 'user': user_string, } XMPPQueue.enqueue_user_xmpp(users, msg) push = push_result.fetchone() if push['extra_pings']: for user in push['extra_pings'].split(','): XMPPQueue.enqueue_user_xmpp( [user], '%s has deployed a push to stage.' % self.current_user)
def on_db_complete(self, success, db_results): self.check_db_results(success, db_results) push = db_results[0].first() unfinished_requests = db_results[2].first() pushmanager_servername = Settings['main_app']['servername'] if not unfinished_requests: msg = "All currently staged requests in http://%s/push?id=%s have been marked as verified." % ( pushmanager_servername, self.pushid) XMPPQueue.enqueue_user_xmpp([push['user']], msg)
def on_db_complete(self, success, db_results): self.check_db_results(success, db_results) reqs, _, _ = db_results removal_dicts = [] for req in reqs: if req['watchers']: user_string = '%s (%s)' % (req['user'], req['watchers']) users = [req['user']] + req['watchers'].split(',') else: user_string = req['user'] users = [req['user']] msg = (""" <p> %(pushmaster)s has removed request for %(user)s from a push: </p> <p> <strong>%(user)s - %(title)s</strong><br /> <em>%(repo)s/%(branch)s</em> </p> <p> Regards,<br /> PushManager </p>""") % core.util.EscapedDict({ 'pushmaster': self.current_user, 'user': user_string, 'title': req['title'], 'repo': req['repo'], 'branch': req['branch'], }) subject = "[push] %s - %s" % (user_string, req['title']) MailQueue.enqueue_user_email(users, msg, subject) msg = '%(pushmaster)s has removed request "%(title)s" for %(user)s from a push' % { 'pushmaster': self.current_user, 'title': req['title'], 'pushid': self.pushid, 'user': user_string, } XMPPQueue.enqueue_user_xmpp(users, msg) removal_dicts.append({ 'request': req['id'], 'push': self.pushid, 'reason': 'removal after %s' % req['state'], 'pushmaster': self._current_user, 'timestamp': int(time.time()), }) removal_queries = [ db.push_removals.insert(removal) for removal in removal_dicts ] db.execute_transaction_cb(removal_queries, self.on_db_insert_complete)
def on_db_complete(self, success, db_results): self.check_db_results(success, db_results) reqs, _, _ = db_results removal_dicts = [] for req in reqs: if req['watchers']: user_string = '%s (%s)' % (req['user'], req['watchers']) users = [req['user']] + req['watchers'].split(',') else: user_string = req['user'] users = [req['user']] msg = ( """ <p> %(pushmaster)s has removed request for %(user)s from a push: </p> <p> <strong>%(user)s - %(title)s</strong><br /> <em>%(repo)s/%(branch)s</em> </p> <p> Regards,<br /> PushManager </p>""" ) % core.util.EscapedDict({ 'pushmaster': self.current_user, 'user': user_string, 'title': req['title'], 'repo': req['repo'], 'branch': req['branch'], }) subject = "[push] %s - %s" % (user_string, req['title']) MailQueue.enqueue_user_email(users, msg, subject) msg = '%(pushmaster)s has removed request "%(title)s" for %(user)s from a push' % { 'pushmaster': self.current_user, 'title': req['title'], 'pushid': self.pushid, 'user': user_string, } XMPPQueue.enqueue_user_xmpp(users, msg) removal_dicts.append({ 'request': req['id'], 'push': self.pushid, 'reason': 'removal after %s' % req['state'], 'pushmaster': self._current_user, 'timestamp': int(time.time()), }) removal_queries = [db.push_removals.insert(removal) for removal in removal_dicts] db.execute_transaction_cb(removal_queries, self.on_db_insert_complete)
def on_db_complete(self, success, db_results): self.check_db_results(success, db_results) _, blessed_requests, push_results = db_results for req in blessed_requests: if req['watchers']: user_string = '%s (%s)' % (req['user'], req['watchers']) users = [req['user']] + req['watchers'].split(',') else: user_string = req['user'] users = [req['user']] msg = ( """ <p> %(pushmaster)s has deployed request for %(user)s to production: </p> <p> <strong>%(user)s - %(title)s</strong><br /> <em>%(repo)s/%(branch)s</em> </p> <p> Regards,<br /> PushManager </p>""" ) % core.util.EscapedDict({ 'pushmaster': self.current_user, 'user': user_string, 'title': req['title'], 'repo': req['repo'], 'branch': req['branch'], }) subject = "[push] %s - %s" % (user_string, req['title']) MailQueue.enqueue_user_email(users, msg, subject) msg = '%(pushmaster)s has deployed request "%(title)s" for %(user)s to production.' % { 'pushmaster': self.current_user, 'title': req['title'], 'user': user_string, } XMPPQueue.enqueue_user_xmpp(users, msg) push = push_results.fetchone() if push['extra_pings']: for user in push['extra_pings'].split(','): XMPPQueue.enqueue_user_xmpp([user], '%s has deployed a push to production.' % self.current_user) self.finish()
def on_db_complete(self, success, db_results): self.check_db_results(success, db_results) _, blessed_requests, push_results = db_results for req in blessed_requests: if req['watchers']: user_string = '%s (%s)' % (req['user'], req['watchers']) users = [req['user']] + req['watchers'].split(',') else: user_string = req['user'] users = [req['user']] msg = (""" <p> %(pushmaster)s has deployed request for %(user)s to production: </p> <p> <strong>%(user)s - %(title)s</strong><br /> <em>%(repo)s/%(branch)s</em> </p> <p> Regards,<br /> PushManager </p>""") % core.util.EscapedDict({ 'pushmaster': self.current_user, 'user': user_string, 'title': req['title'], 'repo': req['repo'], 'branch': req['branch'], }) subject = "[push] %s - %s" % (user_string, req['title']) MailQueue.enqueue_user_email(users, msg, subject) msg = '%(pushmaster)s has deployed request "%(title)s" for %(user)s to production.' % { 'pushmaster': self.current_user, 'title': req['title'], 'user': user_string, } XMPPQueue.enqueue_user_xmpp(users, msg) push = push_results.fetchone() if push['extra_pings']: for user in push['extra_pings'].split(','): XMPPQueue.enqueue_user_xmpp( [user], '%s has deployed a push to production.' % self.current_user) self.finish()
def send_notifications(people, pushtype, pushurl): pushmanager_servername = Settings["main_app"]["servername"] pushmanager_servername = pushmanager_servername.rstrip("/") pushurl = pushurl.lstrip("/") pushmanager_url = "https://%s/%s" % (pushmanager_servername, pushurl) if people: msg = "%s: %s push starting! %s" % (", ".join(people), pushtype, pushmanager_url) XMPPQueue.enqueue_user_xmpp(people, "Push starting! %s" % pushmanager_url) elif pushtype == "morning": msg = "Morning push opened. %s" % pushmanager_servername else: msg = "push starting. %s" % pushmanager_url subprocess.call(["/nail/sys/bin/nodebot", "-i", Settings["irc"]["nickname"], Settings["irc"]["channel"], msg]) subject = "New push notification" MailQueue.enqueue_user_email(Settings["mail"]["notifyall"], msg, subject)
def on_db_complete(self, success, db_results): self.check_db_results(success, db_results) if db_results: req = db_results[1].first() msg = ( """ <p> %(pushmaster)s has commented on your request: </p> <p> <strong>%(user)s - %(title)s</strong><br /> <em>%(repo)s/%(branch)s</em> </p> <pre> %(comment)s </pre> <p> Regards,<br /> PushManager </p>""" ) % core.util.EscapedDict({ 'pushmaster': self.current_user, 'user': req['user'], 'title': req['title'], 'repo': req['repo'], 'branch': req['branch'], 'comment': self.comment, }) subject = "[push comment] %s - %s" % (req['user'], req['title']) MailQueue.enqueue_user_email([req['user']], msg, subject) msg = '%(pushmaster)s has commented on your request "%(title)s":\n%(comment)s' % { 'pushmaster': self.current_user, 'title': req['title'], 'comment': self.comment, } XMPPQueue.enqueue_user_xmpp([req['user']], msg) newcomments = req[db.push_requests.c.comments] self.write(xhtml_escape(newcomments))
def send_notifications(people, pushtype, pushurl): pushmanager_servername = Settings['main_app']['servername'] pushmanager_servername = pushmanager_servername.rstrip('/') pushurl = pushurl.lstrip('/') pushmanager_url = "https://%s/%s" % (pushmanager_servername, pushurl) if people: msg = '%s: %s push starting! %s' % (', '.join(people), pushtype, pushmanager_url) XMPPQueue.enqueue_user_xmpp(people, 'Push starting! %s' % pushmanager_url) elif pushtype == 'morning': msg = 'Morning push opened. %s' % pushmanager_servername else: msg = 'push starting. %s' % pushmanager_url subprocess.call([ '/nail/sys/bin/nodebot', '-i', Settings['irc']['nickname'], Settings['irc']['channel'], msg ]) subject = "New push notification" MailQueue.enqueue_user_email(Settings['mail']['notifyall'], msg, subject)