예제 #1
0
def reportabug():
    path = os.path.join(request.folder, "errors")
    course = request.vars["course"]
    uri = request.vars["page"]
    username = "******"
    email = "anonymous"
    code = None
    ticket = None
    registered_user = False

    if request.vars.code:
        code = request.vars.code
        ticket = request.vars.ticket.split("/")[1]
        uri = request.vars.requested_uri
        error = RestrictedError()
        error.load(request, request.application, os.path.join(path, ticket))
        ticket = error.traceback

    if auth.user:
        username = auth.user.username
        email = auth.user.email
        course = auth.user.course_name
        registered_user = True

    return dict(
        course=course,
        uri=uri,
        username=username,
        email=email,
        code=code,
        ticket=ticket,
        registered_user=registered_user,
    )
예제 #2
0
def reportabug():
    path = os.path.join(request.folder, 'errors')
    course = request.vars['course']
    uri = request.vars['page']
    username = '******'
    email = 'anonymous'
    code = None
    ticket = None
    pagerequest = None
    if request.vars.code:
        code = request.vars.code
        ticket = request.vars.ticket.split('/')[1]
        uri = request.vars.requested_uri
        error = RestrictedError()
        error.load(request, request.application, os.path.join(path, ticket))
        ticket = error.traceback

    if auth.user:
        username = auth.user.username
        email = auth.user.email
        course = auth.user.course_name
    return dict(course=course,
                uri=uri,
                username=username,
                email=email,
                code=code,
                ticket=ticket)
예제 #3
0
def reportabug():
    path = os.path.join(request.folder, 'errors')
    course = request.vars['course']
    uri = request.vars['page']
    username = '******'
    email = 'anonymous'
    code = None
    ticket = None
    registered_user = False

    if request.vars.code:
        code = request.vars.code
        ticket = request.vars.ticket.split('/')[1]
        uri = request.vars.requested_uri
        error = RestrictedError()
        error.load(request, request.application, os.path.join(path, ticket))
        ticket = error.traceback

    if auth.user:
        username = auth.user.username
        email = auth.user.email
        course = auth.user.course_name
        registered_user = True

    return dict(course=course, uri=uri, username=username, email=email, code=code, ticket=ticket,
                registered_user=registered_user)
예제 #4
0
파일: admin.py 프로젝트: shashi/eden
def ticket():
    """ Ticket handler """

    import traceback
    from gluon.restricted import RestrictedError

    if len(request.args) != 2:
        session.error = T("Invalid ticket")
        redirect(URL(r=request))

    app = request.args[0]
    ticket = request.args[1]
    e = RestrictedError()
    e.load(request, app, ticket)

    return dict(app=app, ticket=ticket, traceback=Traceback(e.traceback), code=e.code, layer=e.layer)
예제 #5
0
def ticket():
    """ Ticket handler """

    import traceback
    from gluon.restricted import RestrictedError

    if len(request.args) != 2:
        session.error = T("Invalid ticket")
        redirect(URL(r=request))

    app = request.args[0]
    ticket = request.args[1]
    e = RestrictedError()
    e.load(request, app, ticket)

    return dict(app=app,
                ticket=ticket,
                traceback=s3base.Traceback(e.traceback),
                code=e.code,
                layer=e.layer)
예제 #6
0
파일: admin.py 프로젝트: madcsaba/eden
def ticket():
    """ Ticket viewer """

    if len(request.args) != 2:
        session.error = T("Invalid ticket")
        redirect(URL(r=request))

    app = request.args[0]
    ticket = request.args[1]

    from gluon.restricted import RestrictedError
    e = RestrictedError()
    e.load(request, app, ticket)

    return {"app": app,
            "ticket": ticket,
            "traceback": s3base.Traceback(e.traceback),
            "code": e.code,
            "layer": e.layer,
            }
예제 #7
0
파일: admin.py 프로젝트: nursix/eden
def ticket():
    """ Ticket viewer """

    if len(request.args) != 2:
        session.error = T("Invalid ticket")
        redirect(URL(r=request))

    app = request.args[0]
    ticket = request.args[1]

    from gluon.restricted import RestrictedError
    e = RestrictedError()
    e.load(request, app, ticket)

    return {"app": app,
            "ticket": ticket,
            "traceback": s3base.Traceback(e.traceback),
            "code": e.code,
            "layer": e.layer,
            }
예제 #8
0
파일: tickets2db.py 프로젝트: huiker/web2py
    SQLField('app'),
    SQLField('name'),
    SQLField('date_saved', 'datetime'),
    SQLField('layer'),
    SQLField('traceback', 'text'),
    SQLField('code', 'text'),
)
while 1:
    for file in os.listdir(path):
        filename = os.path.join(path, file)
        if not ALLOW_DUPLICATES:
            key = md5.new(open(filename, 'r').read()).hexdigest()
            if hashes.has_key(key):
                continue
            hashes[key] = 1
        e = RestrictedError()
        e.load(filename)
        t = \
            datetime.datetime.fromtimestamp(os.stat(filename)[stat.ST_MTIME])
        db.ticket.insert(
            app=request.application,
            date_saved=t,
            name=file,
            layer=e.layer,
            traceback=e.traceback,
            code=e.code,
        )
        os.unlink(filename)
    db.commit()
    time.sleep(SLEEP_MINUTES * 60)
예제 #9
0
if settings.globals.debug_notification:
    for file in os.listdir(path):
        filename = os.path.join(path, file)

        if not ALLOW_DUPLICATES:
            file_data = open(filename, 'r').read()
            key = md5_hash(file_data)

            if key in hashes:
                continue

            hashes[key] = 1

        error = RestrictedError()
        error.load(request, request.application, filename)
        logger.debug("REQUEST-APP: %s" % dir(request))

        logger.debug("Sending email...")

        message = '<b>There has been an error on a node.</b><br>'
        message += '<h1>This is the trackback:</h1><br><pre>%s</pre><br><br><br>' % error.traceback
        message += "<h1>this is the environment:</h1><br>"
        try:
            message += "<h2>RESPONSE: </h2><br> %s<br><br>" % error.snapshot['response']
            message += "<h2>LOCALS: </h2><br> %s<br><br>" % error.snapshot['locals']
            message += "<h2>REQUEST: </h2><br> %s<br><br>" % error.snapshot['request']
            message += "<h2>SESSION:</h2><br>  %s<br><br>" % error.snapshot['session']
        except KeyError:
            pass
예제 #10
0
while 1:
    for file_name in os.listdir(path):
        if file_name == 'slack_errors.pickle':
            continue

        if not ALLOW_DUPLICATES:
            key = md5_hash(file_name)
            if key in hashes:
                continue
            hashes[key] = 1

        error = RestrictedError()

        try:
            error.load(request, request.application, file_name)
        except Exception as _:
            continue  # not an exception file?

        url = URL(a='admin',
                  f='ticket',
                  args=[request.application, file],
                  scheme=True)
        payload = json.dumps(
            dict(text="Error in %(app)s.\n%(url)s" %
                 dict(app=request.application, url=url)))

        requests.post(global_settings.slack_hook, data=dict(payload=payload))

    with open(sent_errors_file, 'wb') as f:
        pickle.dump(hashes, f)
예제 #11
0
def process_tickets():
    return "NO! Don't use this."

    def get_table_row(table, row_header):
        # Look for the row with `header' in the first string of
        # the first TD of the row
        for row in table.components:
            #print row.components[0].components[0]
            if row.components[0].components[0] == row_header:
                return row #.components[2].components[0].components[0]
        return None

    def get_beautify_key_value(beautify, key):
        r = get_table_row(beautify.components[0], key)
        if r:
            return r.components[2].components[0]
        return None

    def has_live_get_var(error):
        get_vars = get_beautify_key_value(e.snapshot['request'], 'get_vars')
        if not get_vars: return False
        return get_beautify_key_value(get_vars, 'live')
        
    def find_hitid(error):
        get_vars = get_beautify_key_value(error.snapshot['request'], 'get_vars')
        if not get_vars:
            send_me_mail('Crap, no get_vars in this guy!\n\n %s error')
        hitid = get_beautify_key_value(get_vars, 'hitId')
        if not (hitid and len(hitid.components) == 1):
            send_me_mail('Crap, no hitid in this guy!\n\n %s error')
        return hitid.components[0]
    def is_sandbox(error):
        sandboxp = get_beautify_key_value(e.snapshot['request'], 'sandboxp')
        if not sandboxp or 'components' not in sandboxp or len(components) < 1:
            debug_t('This shouldn\'t happen! in process_tickets()')
            return False
        s = sandboxp.components[0]
        if not (s == 'False' or s == 'True'):
            debug_t('This shouldn\'t happen either! in process_tickets()')
            return false
        return s == 'True'

    if True:
        import os, stat, time
        from gluon.restricted import RestrictedError
        path='applications/utility/errors/'

        last_run = store_get('last_process_tickets_time') or 0.3
        this_run = time.time()

        recent_files = [x for x in os.listdir(path)
                        if os.path.getmtime(path + x) > last_run]

        for file in recent_files:
            debug_t('Trying error file %s' % file)
            e=RestrictedError()
            e.load(request, 'utility', file)

            # Ok, let's see if this was a live one
            if has_live_get_var(e) and not is_sandbox(e):
                debug_t('This error has a live!  Dealing with it now.')
                hitid = find_hitid(e)
                url = ('http://%s:%s/admin/default/ticket/utility/%s'
                       % (server_url, server_port, file))
                send_me_mail("There was an error in your mturk study!!!\nGo check it out at %s"
                             % url)
                try:
                    debug_t('Expiring hit %s' % hitid)
                    result = turk.expire_hit(hitid)
                    # result.toprettyxml().replace('\t', '   ')
                    debug_t('Expired this hit.')
                except TurkAPIError as e:
                    debug_t("Couldn't expire it. Maybe it was already done.  Error was: %s"
                            % e)
        store_set('last_process_tickets_time', this_run)
        db.commit()
예제 #12
0
def process_tickets():
    return "NO! Don't use this."

    def get_table_row(table, row_header):
        # Look for the row with `header' in the first string of
        # the first TD of the row
        for row in table.components:
            #print row.components[0].components[0]
            if row.components[0].components[0] == row_header:
                return row #.components[2].components[0].components[0]
        return None

    def get_beautify_key_value(beautify, key):
        r = get_table_row(beautify.components[0], key)
        if r:
            return r.components[2].components[0]
        return None

    def has_live_get_var(error):
        get_vars = get_beautify_key_value(e.snapshot['request'], 'get_vars')
        if not get_vars: return False
        return get_beautify_key_value(get_vars, 'live')
        
    def find_hitid(error):
        get_vars = get_beautify_key_value(error.snapshot['request'], 'get_vars')
        if not get_vars:
            send_me_mail('Crap, no get_vars in this guy!\n\n %s error')
        hitid = get_beautify_key_value(get_vars, 'hitId')
        if not (hitid and len(hitid.components) == 1):
            send_me_mail('Crap, no hitid in this guy!\n\n %s error')
        return hitid.components[0]
    def is_sandbox(error):
        sandboxp = get_beautify_key_value(e.snapshot['request'], 'sandboxp')
        if not sandboxp or 'components' not in sandboxp or len(components) < 1:
            debug_t('This shouldn\'t happen! in process_tickets()')
            return False
        s = sandboxp.components[0]
        if not (s == 'False' or s == 'True'):
            debug_t('This shouldn\'t happen either! in process_tickets()')
            return false
        return s == 'True'

    if True:
        import os, stat, time
        from gluon.restricted import RestrictedError
        path='applications/utility/errors/'

        last_run = store_get('last_process_tickets_time') or 0.3
        this_run = time.time()

        recent_files = [x for x in os.listdir(path)
                        if os.path.getmtime(path + x) > last_run]

        for file in recent_files:
            debug_t('Trying error file %s' % file)
            e=RestrictedError()
            e.load(request, 'utility', file)

            # Ok, let's see if this was a live one
            if has_live_get_var(e) and not is_sandbox(e):
                debug_t('This error has a live!  Dealing with it now.')
                hitid = find_hitid(e)
                url = ('http://%s:%s/admin/default/ticket/utility/%s'
                       % (server_url, server_port, file))
                send_me_mail("There was an error in your mturk study!!!\nGo check it out at %s"
                             % url)
                try:
                    debug_t('Expiring hit %s' % hitid)
                    result = turk.expire_hit(hitid)
                    # result.toprettyxml().replace('\t', '   ')
                    debug_t('Expired this hit.')
                except TurkAPIError as e:
                    debug_t("Couldn't expire it. Maybe it was already done.  Error was: %s"
                            % e)
        store_set('last_process_tickets_time', this_run)
        db.commit()
예제 #13
0
    SQLField('app'),
    SQLField('name'),
    SQLField('date_saved', 'datetime'),
    SQLField('layer'),
    SQLField('traceback', 'text'),
    SQLField('code', 'text'),
    )
while 1:
    for file in os.listdir(path):
        filename = os.path.join(path, file)
        if not ALLOW_DUPLICATES:
            key = md5.new(open(filename, 'r').read()).hexdigest()
            if hashes.has_key(key):
                continue
            hashes[key] = 1
        e = RestrictedError()
        e.load(filename)
        t = \
            datetime.datetime.fromtimestamp(os.stat(filename)[stat.ST_MTIME])
        db.ticket.insert(
            app=request.application,
            date_saved=t,
            name=file,
            layer=e.layer,
            traceback=e.traceback,
            code=e.code,
            )
        os.unlink(filename)
    db.commit()
    time.sleep(SLEEP_MINUTES * 60)