Beispiel #1
0
def run(project):
    task = json.loads(request.form['task'])
    project_info = {
        'name': project,
        'status': 'DEBUG',
        'script': request.form['script'],
    }

    fetch_result = {}
    start_time = time.time()
    try:
        fetch_result = app.config['fetch'](task)
        response = rebuild_response(fetch_result)
        module = build_module(project_info, {'debugger': True})
        ret = module['instance'].run(module['module'], task, response)
    except Exception, e:
        type, value, tb = sys.exc_info()
        tb = hide_me(tb, globals())
        logs = ''.join(traceback.format_exception(type, value, tb))
        result = {
            'fetch_result': fetch_result,
            'logs': logs,
            'follows': [],
            'messages': [],
            'result': None,
            'time': time.time() - start_time,
        }
Beispiel #2
0
def run(project):
    task = json.loads(request.form['task'])
    project_info = {
            'name': project,
            'status': 'DEBUG',
            'script': request.form['script'],
            }

    fetch_result = ""
    start_time = time.time()
    try:
        fetch_result = app.config['fetch'](task)
        response = rebuild_response(fetch_result)
        module = build_module(project_info, {'debugger': True})
        ret = module['instance'].run(module['module'], task, response)
    except Exception, e:
        type, value, tb = sys.exc_info()
        tb = hide_me(tb, globals())
        logs = ''.join(traceback.format_exception(type, value, tb))
        result = {
                'fetch_result': fetch_result,
                'logs': logs,
                'follows': [],
                'messages': [],
                'result': None,
                'time': time.time() - start_time,
                }
Beispiel #3
0
 def logstr(self):
     result = []
     formater = LogFormatter(color=False)
     for record in self.logs:
         if isinstance(record, basestring):
             result.append(record)
             continue
         else:
             if record.exc_info:
                 a, b, tb = record.exc_info
                 tb = hide_me(tb, globals())
                 record.exc_info = a, b, tb
             result.append(formater.format(record))
             result.append('\n')
     return ''.join(result)
Beispiel #4
0
 def logstr(self):
     result = []
     formater = LogFormatter(color=False)
     for record in self.logs:
         if isinstance(record, basestring):
             result.append(record)
             continue
         else:
             if record.exc_info:
                 a, b, tb = record.exc_info
                 tb = hide_me(tb, globals())
                 record.exc_info = a, b, tb
             result.append(formater.format(record))
             result.append('\n')
     return ''.join(result)
Beispiel #5
0
 def logstr(self):
     result = []
     formater = LogFormatter(color=False)
     for record in self.logs:
         if isinstance(record, basestring):
             result.append(record)
             continue
         else:
             if record.exc_info:
                 a, b, tb = record.exc_info
                 tb = hide_me(tb, globals())
                 record.exc_info = a, b, tb
             result.append(formater.format(record))
             result.append('\n')
     ret = ''.join(result)
     if isinstance(ret, unicode):
         return ret
     else:
         try:
             return ret.decode('utf8')
         except UnicodeDecodeError as e:
             return repr(ret)
Beispiel #6
0
    else:
        result = {
            'fetch_result': fetch_result,
            'logs': ret.logstr(),
            'follows': ret.follows,
            'messages': ret.messages,
            'result': ret.result,
            'time': time.time() - start_time,
        }
        result['fetch_result']['content'] = response.text

    try:
        return json.dumps(result), 200, {'Content-Type': 'application/json'}
    except Exception, e:
        type, value, tb = sys.exc_info()
        tb = hide_me(tb, globals())
        logs = ''.join(traceback.format_exception(type, value, tb))
        result = {
            'fetch_result': "",
            'logs': logs,
            'follows': [],
            'messages': [],
            'result': None,
            'time': time.time() - start_time,
        }
        return json.dumps(result), 200, {'Content-Type': 'application/json'}


@app.route('/debug/<project>/save', methods=[
    'POST',
])
Beispiel #7
0
    else:
        result = {
                'fetch_result': fetch_result,
                'logs': ret.logstr(),
                'follows': ret.follows,
                'messages': ret.messages,
                'result': ret.result,
                'time': time.time() - start_time,
                }
        result['fetch_result']['content'] = response.text

    try:
        return json.dumps(result), 200, {'Content-Type': 'application/json'}
    except Exception, e:
        type, value, tb = sys.exc_info()
        tb = hide_me(tb, globals())
        logs = ''.join(traceback.format_exception(type, value, tb))
        result = {
                'fetch_result': "",
                'logs': logs,
                'follows': [],
                'messages': [],
                'result': None,
                'time': time.time() - start_time,
                }
        return json.dumps(result), 200, {'Content-Type': 'application/json'}

@app.route('/debug/<project>/save', methods=['POST', ])
def save(project):
    if not verify_project_name(project):
        return 'project name is not allowed!', 400