Example #1
0
 def write(self):
     if not self._read_complete:
         return
     p = self.filename.parent
     if not p.exists():
         p.mkdir(mode=0o700, parents=True)
     self.filename.write_text(jsonfactory.dumps(self.data, indent=2))
Example #2
0
 def save(self, filename=None):
     if filename is not None:
         self.filename = filename
     else:
         filename = self.filename
     filename = os.path.expanduser(filename)
     data = self._get_conf_data()
     if not os.path.exists(os.path.dirname(filename)):
         os.makedirs(os.path.dirname(filename))
     s = jsonfactory.dumps(data, indent=4)
     with open(filename, 'w') as f:
         f.write(s)
Example #3
0
def session_item(session_id):
    context = get_session_context({
        'log_type':'single_session',
        'session_id':ObjectId(session_id),
    })
    results = get_entries(context)
    context.update(dict(
        has_more=False,
        page_num=1,
        total_pages=1,
        per_page=results.count(),
        entry_iter=results,
        query_data=jsonfactory.dumps(context['query']),
    ))
    return render_template('log-collection.html', **context)
Example #4
0
    def save(self, filename=None):
        """Saves the config data to the given filename

        Arguments:
            filename (:obj:`str`, optional): The filename to write config data to.
                If not supplied, the current :attr:`filename` is used.

        Notes:
            If the ``filename`` argument is provided, it will replace the
            existing :attr:`filename` value.

        """
        if filename is not None:
            self.filename = filename
        else:
            filename = self.filename
        filename = os.path.expanduser(filename)
        data = self._get_conf_data()
        if not os.path.exists(os.path.dirname(filename)):
            os.makedirs(os.path.dirname(filename))
        s = jsonfactory.dumps(data, indent=4)
        with open(filename, 'w') as f:
            f.write(s)
Example #5
0
def log_collection(request, context):
    qdata = request.args.get('_QueryGroup_')
    if qdata is not None:
        context['query'] = jsonfactory.loads(qdata)
    results = get_entries(context)
    page_num = int(request.args.get('p', '0'))

    per_page = 50
    total_count = results.count()
    total_pages = total_count // per_page
    start_index = page_num * per_page
    end_index = start_index + per_page
    if end_index >= total_count:
        has_more = False
        end_index = total_count
    else:
        has_more = True
    url_fmt = '{base_url}?p={page}'
    qkwargs = dict(skip=start_index, limit=per_page)
    results = get_entries(context, **qkwargs)
    context.update(dict(
        has_more=has_more,
        page_num=page_num+1,
        per_page=per_page,
        total_pages=total_pages,
        prev_url=url_fmt.format(
            base_url=request.base_url,
            page=page_num-1,
        ),
        next_url=url_fmt.format(
            base_url=request.base_url,
            page=page_num+1,
        ),
        entry_iter=results,
        query_data=jsonfactory.dumps(context['query']),
    ))
    return render_template('log-collection.html', **context)
Example #6
0
def dumps(obj, **kwargs):
    return jsonfactory.dumps(obj, **kwargs)
Example #7
0
def log_request(verb, url, resp_data):
    d = {'verb':verb, 'url':url, 'response':resp_data}
    txt_data = jsonfactory.dumps(d)
    filename = 'request_data.log'
    with open(filename, 'a') as f:
        f.write('{}\n\n'.format(txt_data))
Example #8
0
def dumps(obj, **kwargs):
    return jsonfactory.dumps(obj, **kwargs)