예제 #1
0
 def do_POST(self):
     self.server.log.debug('fromCollaboration received notification at %f'\
                           % time.clock())
     cl = int(self.headers.dict['content-length'])
     msg = json.loads(urllib.unquote_plus(self.rfile.read(cl)))
     try: # Send the HTTP response
         self.server.log.debug('fromCollaboration sending response at %f'\
                               % time.clock())
         self.send_response(httplib.OK)
         self.send_header('content-length', '0')
         self.end_headers()
         self.wfile.write('\r\n')
     except Exception, ex:
         log = self.server.log.error if self.server.log else None
         log.debug('Acknowledge error in fromCollaboration %s' % str(ex))
         reportException.report(ex, log)
예제 #2
0
 def doGitRm(self, ret, file):
     if self._localrepo is not None:
         args = ['git','rm', file]
         self.runCommand('Git rm', ret, args)
     else:
         try:
             os.remove(file)
         except Exception, ex:
             ret[0] = 1
             ret[1].append(reportException.report(ex))
예제 #3
0
 def doGitMv(self, ret, old, new):
     if self._localrepo is not None:
         args = ['git','mv', old, new]
         self.runCommand('Git mv', ret, args)
     else:
         try:
             os.rename(old, new)
         except Exception, ex:
             ret[0] = 1
             ret[1].append(reportException.report(ex))
예제 #4
0
 def post(self):
     ret = httplib.OK
     try:
         gitpush = simplejson.loads(\
                     urllib.unquote_plus(self.request.body_file.getvalue()))
         subscriber = gitpush[SUBSCRIBER]
         logging.debug('Sending Github notification to %s at %f'\
                       % (subscriber, time.clock()))
         result = urlfetch.fetch(url=subscriber,
                                 payload=self.request.body_file.getvalue(),
                                 method=urlfetch.POST, deadline=10)
         logging.debug(\
                  'Github transmission to %s completed with code %i at %s'\
                        % (result.final_url if result.final_url else subscriber,
                           result.status_code,
                           time.clock()))
         ret = result.status_code
         return
     except Exception, ex:
         logging.debug('Github transmission to %s failed at %f'\
                       % (subscriber, time.clock()))
         reportException.report(ex, logging.error)
         return
예제 #5
0
def send(msg, url, dest_host='0.0.0.0', dest_port=80,
         logger=logging.warning):
    host = dest_host if dest_host is not None else '0.0.0.0'
    port = 80
    try:
        conn = httplib.HTTPConnection(host, port)
        if conn is not None:
            conn.connect()
            js = None
            qp = None
            try:
                js = json.dumps(msg)
            except Exception, ex:
                
                return (httplib.UNPROCESSABLE_ENTITY,
                        reportException.report(ex, logging.error), None)
            try:
                qp = urllib.quote_plus(js, str('/'))
            except Exception, ex:
                return (httplib.UNPROCESSABLE_ENTITY,
                        reportException.report(ex, logging.error), None)
            conn.request('POST', url, qp)
            ret = conn.getresponse()
            return (ret.status, ret.reason, ret)
예제 #6
0
 def post(self):
     try:
         str1 = unicode(urllib.unquote_plus(self.request.body_file.getvalue()))
         if string.find(str1, 'payload=') >= 0:
             msg = string.split(str1, 'payload=')[1]
             gitpush = simplejson.loads(msg)
             self.response.set_status(httplib.OK)
             repo = gitpush['repository']
             url = repo['url']
             publisher = GITHUB + '/' + string.split(url, 'http://github.com/')[1]
             queue_pub_notifications(publisher, gitpush)
         else:
             # If we don't recognise the payload, send an accepted
             # status anyway as this is likely from someone disruptive
             # and it would be a good idea to give the disrupter as
             # little information as possible
             logging.warning('''Received invalid message, theoretically from Github.\n'''
                             '''   Headers; %s\n   Payload: %s''' % self.headers, str1)
             self.response.set_status(httplib.OK)
         return
     except Exception , ex:
         self.doReturn(logging.ERROR, httplib.UNPROCESSABLE_ENTITY,
                        reportException.report(ex))
         return
예제 #7
0
    def post(self):
        try:
            req = simplejson.loads(urllib.unquote_plus(\
                                            self.request.body_file.getvalue()))
            if REQ_SUBSCRIPTION not in req or REQ_PUBLISHER not in req:
                self.doReturn(logging.WARNING, httplib.PRECONDITION_FAILED,
                    'No or incomplete subscription status provided in request')
                return
            status = req[REQ_SUBSCRIPTION]
            publisher = req[REQ_PUBLISHER]
            port = req[REQ_PORT]
            
            # Make sure this user is registered at Google and logged on
            guser = users.get_current_user()
            if not guser:
                guser = users.User(email=req[USER_ID])
#                if guser.user_id() == None and not testing:
#                    self.doReturn(logging.WARNING, httplib.NOT_ACCEPTABLE,
#                                  'Urecognized Google user %s' % req[USER_ID])
#                    return
                        
                
            
            # Get online user list from memcache if it is there, otherwise
            # load it from the data store
            
            ul = self.cache.load_cache(publisher, load_online_subscribers)
                
            
            # See if user in cache
            # If not add user to  cache
            uid = guser.user_id()
            if uid is None:
                uid = string.split(guser.email(),'@')[0]
            key = uid+req[SUBSCRIBER_DNS]+str(port)
            cuser = ul[key] if key in ul else None
            if cuser is None:
                cuser = Subscriber(google_id=guser, status=status,
                                   user_ip=req[SUBSCRIBER_DNS], user_port=port,
                                   email_address=guser.email(),
                                   publisher=publisher
#                                   first_name=req[FIRST_NAME],
#                                   middle_name=req[MIDDLE_NAME],
#                                   last_name=req[LAST_NAME]
                                   )
                self.cache.update(publisher, key, cuser)
            
            # If user is coming online update
            # the user entity in the data store to show online status
            if status == SUBSCRIBE:
                if cuser.status != SUBSCRIBE:
                    cuser.status = SUBSCRIBE
                    self.cache.update(publisher, key, cuser)
                    
            # If user is going offline update                   
            # the user entity in the data store to show offline status
            elif status == UNSUBSCRIBE:
                if cuser.status != UNSUBSCRIBE:
                    cuser.status = UNSUBSCRIBE
                    self.cache.update(publisher, key, cuser)
            else:
                self.doReturn(logging.WARNING, httplib.NOT_ACCEPTABLE,
                              'Urecognized status notification')
                return
            
            # Normal return
            self.doReturn(logging.DEBUG, httplib.OK,
                          'Status set to %s' % TEST_SUBSCRIBED
                                               if status == SUBSCRIBE
                                               else TEST_UNSUBSCRIBED )
            return
            
        except Exception , ex:
            self.doReturn(logging.ERROR, httplib.UNPROCESSABLE_ENTITY,
                          reportException.report(ex))
            return
예제 #8
0
def send(msg, url, dest_host='0.0.0.0', dest_port=80,
         logger=logging.warning):
    host = dest_host if dest_host is not None else '0.0.0.0'
    port = 80
    try:
        conn = httplib.HTTPConnection(host, port)
        if conn is not None:
            conn.connect()
            js = None
            qp = None
            try:
                js = json.dumps(msg)
            except Exception, ex:
                
                return (httplib.UNPROCESSABLE_ENTITY,
                        reportException.report(ex, logging.error), None)
            try:
                qp = urllib.quote_plus(js, str('/'))
            except Exception, ex:
                return (httplib.UNPROCESSABLE_ENTITY,
                        reportException.report(ex, logging.error), None)
            conn.request('POST', url, qp)
            ret = conn.getresponse()
            return (ret.status, ret.reason, ret)
    except Exception, ex:
        reportException.report(ex, logger)
        return (httplib.FAILED_DEPENDENCY, None, None)
    finally:
        if conn is not None: conn.close()