Пример #1
0
    def post(self):
        self.set_header('Content-type', 'text/plain')
        self.write('Environment ID: %s\n' % self.get_argument('env_choice'))
        self.write(self.get_argument('code'))
        code = self.get_argument('code')
        env_id = self.get_argument('env_choice')
        env = CodeboxHandler.ENVIRONMENTS[env_id]

        apiurl = get_config().get('codebox', 'api')
    
        data = {'filename': env['fname'],
                'source': code,
                'sbtype': env['sbtype']}
        
        jobsubmit = requests.post(apiurl+'job/new', data=data)
        job_id = jobsubmit.json()['job_id']

        self.write('\n-------------\n\n')
        self.write(jobsubmit.json())
        
        memcache = get_config().get_memcache_client()
        uid = get_random_uid(lambda x: not memcache.get(make_padded_id(x)))
        padded_uid = make_padded_id(uid)

        memcache.set(padded_uid, {
                'job_id': job_id,
                'result': None,
                'state': 'sent',
                'code': code,
                'env_id': env_id,
                })

        self.redirect('/demos/codebox_result/%s' % uid)
        '''
Пример #2
0
    def post(self):
        data = self.get_argument('this is a real contact info request')

        if data != 'yup':
            return self.error_me_scotty()

        contact = get_config().get('contact')
        self.set_header('Content-Type', 'application/json')
        self.write(json.dumps(contact))
Пример #3
0
    def update_status(self, uid):
        memcache = get_config().get_memcache_client()
        padded_uid = make_padded_id(uid)
        req_data = memcache.get(padded_uid)
        if not req_data:
            return None
        if req_data['result']:
            return req_data  #If it already has a result, it's done

        apiurl = get_config().get('codebox', 'api')

        jobget = requests.get(apiurl + 'job/get/' + req_data['job_id'])
        cb_data = jobget.json()

        req_data['state'] = 'sent'
        if not cb_data['build_done']:
            req_data['state'] = 'building'
        elif not cb_data['run_done']:
            req_data['state'] = 'running'
        else:
            req_data['state'] = 'done'

        if cb_data['build_exception']:
            req_data['state'] = 'error/build'
            req_data['result'] = "Build exception:\n%s\n%s" % (
                cb_data['build_exception'], cb_data['build_result'])

        elif cb_data['run_exception']:
            req_data['state'] = 'error/run'
            req_data['result'] = "Runtime exception:\n%s" % (
                cb_data['run_exception'])

        else:
            # All is well
            if cb_data['run_done']:
                req_data['state'] = 'done'
                req_data['result'] = cb_data['run_result']['logs']

        memcache.set(padded_uid, req_data)
        return req_data
Пример #4
0
    def update_status(self, uid):
        memcache = get_config().get_memcache_client()
        padded_uid = make_padded_id(uid)
        req_data = memcache.get(padded_uid)
        if not req_data:
            return None
        if req_data['result']:
            return req_data  #If it already has a result, it's done

        apiurl = get_config().get('codebox', 'api')

        jobget = requests.get(apiurl+'job/get/'+req_data['job_id'])
        cb_data = jobget.json()

        req_data['state'] = 'sent'
        if not cb_data['build_done']:
            req_data['state'] = 'building'
        elif not cb_data['run_done']:
            req_data['state'] = 'running'
        else:
            req_data['state'] = 'done'
            
        if cb_data['build_exception']:
            req_data['state'] = 'error/build'
            req_data['result'] = "Build exception:\n%s\n%s" % (cb_data['build_exception'], cb_data['build_result'])

        elif cb_data['run_exception']:
            req_data['state'] = 'error/run'
            req_data['result'] = "Runtime exception:\n%s" % (cb_data['run_exception'])
            
        else:
            # All is well
            if cb_data['run_done']:
                req_data['state'] = 'done'
                req_data['result'] = cb_data['run_result']['logs']

        memcache.set(padded_uid, req_data)
        return req_data
Пример #5
0
    def post(self):
        self.set_header('Content-type', 'text/plain')
        self.write('Environment ID: %s\n' % self.get_argument('env_choice'))
        self.write(self.get_argument('code'))
        code = self.get_argument('code')
        env_id = self.get_argument('env_choice')
        env = CodeboxHandler.ENVIRONMENTS[env_id]

        apiurl = get_config().get('codebox', 'api')

        data = {
            'filename': env['fname'],
            'source': code,
            'sbtype': env['sbtype']
        }

        jobsubmit = requests.post(apiurl + 'job/new', data=data)
        job_id = jobsubmit.json()['job_id']

        self.write('\n-------------\n\n')
        self.write(jobsubmit.json())

        memcache = get_config().get_memcache_client()
        uid = get_random_uid(lambda x: not memcache.get(make_padded_id(x)))
        padded_uid = make_padded_id(uid)

        memcache.set(
            padded_uid, {
                'job_id': job_id,
                'result': None,
                'state': 'sent',
                'code': code,
                'env_id': env_id,
            })

        self.redirect('/demos/codebox_result/%s' % uid)
        '''
Пример #6
0
 def get(self, uid=None):
     if not uid:
         self.set_status(400)
         return "Must specify a request ID"
     padded_uid = make_padded_id(uid)
     
     memcache = get_config().get_memcache_client()
     data = self.update_status(uid)
     if not data:
         self.set_status(404)
         return "Invalid request ID"
     
     return {
         "env": CodeboxHandler.ENVIRONMENTS[data['env_id']],
         "code": data['code'],
         "update": json.dumps({
             "error": "error" in data['state'],
             "state": data['state'],
             "result": data['result'],
             }),
         }
Пример #7
0
    def get(self, uid=None):
        if not uid:
            self.set_status(400)
            return "Must specify a request ID"
        padded_uid = make_padded_id(uid)

        memcache = get_config().get_memcache_client()
        data = self.update_status(uid)
        if not data:
            self.set_status(404)
            return "Invalid request ID"

        return {
            "env":
            CodeboxHandler.ENVIRONMENTS[data['env_id']],
            "code":
            data['code'],
            "update":
            json.dumps({
                "error": "error" in data['state'],
                "state": data['state'],
                "result": data['result'],
            }),
        }
Пример #8
0
 def save(self):
     cache = get_config().get_memcache_client()
     cache_key = DiceSession.make_cache_key(self.uid)
     cache.set(cache_key, self)
Пример #9
0
 def get_cached_session(uid):
     cache = get_config().get_memcache_client()
     cache_key = DiceSession.make_cache_key(uid)
     return cache.get(cache_key)
Пример #10
0
 def save(self):
     cache = get_config().get_memcache_client()
     cache_key = DiceSession.make_cache_key(self.uid)
     cache.set(cache_key, self)
Пример #11
0
 def get_cached_session(uid):
     cache = get_config().get_memcache_client()
     cache_key = DiceSession.make_cache_key(uid)
     return cache.get(cache_key)
Пример #12
0
def main_cli():
    confpath = None
    if len(sys.argv)>1:
        confpath = sys.argv[1]
    conf = get_config(generate=True, confpath=confpath)
    runserv(conf)
Пример #13
0
def main_service():
    conf = get_config(generate=True)
    daemon = HomeWebDaemon(conf)
    run_as_service(daemon)