Skip to content

Commit

Permalink
New version: 1.3.0
Browse files Browse the repository at this point in the history
Add LogFile and NoSQLManager class.
Add __bool__ and __repr__ method on File and Connection abstract
classes.
Fix documentation API section. Fix tests package.
Fix CircleCi docker image
  • Loading branch information
MatteoGuadrini committed Apr 15, 2022
2 parents a2a2676 + 7fdcece commit d16271b
Show file tree
Hide file tree
Showing 18 changed files with 242 additions and 68 deletions.
13 changes: 7 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
version: 2.1

orbs:
python: circleci/python@0.2.1

jobs:
build-and-test:
executor: python/default
docker:
- image: cimg/python:3.10.4
steps:
- checkout
- run: sudo python setup.py install
- run: sudo apt-get update -q
- run: sudo apt-get install -q -y python3-pip
- run: sudo pip install Cython
- run: sudo python3 setup.py install
- run: sudo chmod -R 777 /tmp
- run: python -m unittest discover tests
- run: sudo python3 -m unittest discover tests


workflows:
Expand Down
10 changes: 10 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Release notes

## 1.3.0
Apr 15, 2022

- Added **NoSQLManager** class; this class extend _Manager_ class on the [nosqlapi](https://github.com/MatteoGuadrini/nosqlapi) package
- Added **LogFile** class; this class load a log file and _read_ method accept regular expression
- Added **\__bool\__** and **\__repr\__** method on _File_ and _Connection_ abstract classes
- Fix documentation API section
- Fix tests package
- Fix CircleCi docker image

## 1.2.0
Aug 5, 2021

Expand Down
4 changes: 2 additions & 2 deletions __info__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# created by: matteo.guadrini
# __info__
#
# Copyright (C) 2021 Matteo Guadrini <matteo.guadrini@hotmail.it>
# Copyright (C) 2022 Matteo Guadrini <matteo.guadrini@hotmail.it>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -22,7 +22,7 @@

"""Information variable used by modules on this package."""

__version__ = '1.2.1'
__version__ = '1.3.0'
__author__ = 'Matteo Guadrini'
__email__ = 'matteo.guadrini@hotmail.it'
__homepage__ = 'https://github.com/MatteoGuadrini/pyreports'
Binary file added assets/.DS_Store
Binary file not shown.
Binary file added assets/css/.DS_Store
Binary file not shown.
Binary file added assets/js/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/source/dev/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,4 @@ Here we will see how to create your own ``*Connection`` class to access a specif
pyreports.io.DBTYPE['db2'] = DB2Connection
# Create my DatabaseManager object
mydb2 = pyreports.manager(dsn='sample', uid='db2inst1', pwd='ibmdb2')
mydb2 = pyreports.manager('db2', dsn='sample', uid='db2inst1', pwd='ibmdb2')
28 changes: 27 additions & 1 deletion docs/source/managers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Each type of manager is managed by micro types; Below is the complete list:
#. xlsx (Microsoft Excel file)
#. LDAP
#. ldap (Active Directory Server, OpenLDAP, FreeIPA, etc.)
#. NoSQL
#. nosql (MongoDB, CouchDB, RavenDB, Redis, Neo4j, Cassandra, etc.)

.. note::
The connection arguments of a ``DatabaseManager`` vary according to the type of database being accessed.
Expand All @@ -52,6 +54,9 @@ Each type of manager is managed by micro types; Below is the complete list:
# LdapManager object
ldap = pyreports.manager('ldap', server='ldap.local', username='user', password='password', ssl=False, tls=True)
# NoSQLManager object (nosql api compliant https://nosqlapi.rtfd.io/)
nosql = pyreports.manager('nosql', MongoDBConnection, host='mongo1.local', database='test', user='dba', password='dba0000')
Managers at work
****************

Expand Down Expand Up @@ -155,4 +160,25 @@ LdapManager
ldap.unbind()
.. warning::
*LdapManager* should only be used for inputs. An ldap manager has no write methods.
*LdapManager* should only be used for inputs. An ldap manager has no write methods.

NoSQLManager
------------

**NoSQLManager** is an object that allows you to interface and get data from a NoSQL database server.

.. code-block:: python
import pyreports
# LdapManager object
nosql = pyreports.manager('nosql', MongoDBConnection, host='mongo1.local', database='test', user='dba', password='dba0000')
# Get data
nosql.get('doc1') # Dataset object
# Find data
nosql.find('{"name": "Matteo"}') # Dataset object
.. note::
*NoSQLManager* object accept connection that must be compliant of `nosqlapi <https://nosqlapi.rtfd.io/>`_.
25 changes: 8 additions & 17 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ <h2 class="title">Features</h2>
<ul class="feature-list list-unstyled">
<li><i class="fas fa-check"></i> Write for Python 3.6 and high</li>
<li><i class="fas fa-check"></i> Each database connection is DBAPI 2.0 compliant</li>
<li><i class="fas fa-check"></i> Each NoSQL database connection is <a class="list-inline-item" href="https://nosqlapi.rtfd.io/">nosqlapi</a> compliant</li>
<li><i class="fas fa-check"></i> Work with <a class="list-inline-item" href="https://tablib.readthedocs.io/en/stable/api/#dataset-object">Dataset objects</a></li>
<li><i class="fas fa-check"></i> All objects are extensible</li>
<li><i class="fas fa-check"></i> Functions that support data modification</li>
Expand Down Expand Up @@ -213,31 +214,21 @@ <h3 class="sub-title text-center">Advanced usage</h3>
import re

# Get apache log data: this is a FileManager object
apache_log = pyreports.manager('file', '/var/log/httpd/error.log').read()
# apache log format: regex
regex = '([(\d\.)]+) - - \[(.*?)\] "(.*?)" (\d+) - "(.*?)" "(.*?)"'

# Function than receive Dataset and return a new Dataset
def format_dataset_log(data_input):
data = tablib.Dataset(headers=['ip', 'date', 'operation', 'code', 'client'])
for row in data_input:
log_parts = re.match(regex, row[0]).groups()
new_row = list(log_parts[:4])
new_row.append(log_parts[5])
data.append(new_row)
return data
apache_log = pyreports.manager('log', '/var/log/httpd/error.log')
# Read log based on regexp
data_log = apache_log.read('([(\d\.)]+) - - \[(.*?)\] "(.*?)" (\d+) - "(.*?)" "(.*?)"',
headers=['ip', 'date', 'operation', 'url', 'code', 'client'])

# Create a collection of Report objects
all_apache_error = pyreports.ReportBook(title='Apache error on my site')

# Create a Report object based on error code
apache_error_log = format_dataset_log(apache_log)
all_error = set(apache_error_log['code'])
all_error = set(data_log['code'])
for code in all_error:
all_apache_error.add(pyreports.Report(apache_error_log, filters=[code], title=f'Error {code}'))
all_apache_error.add(pyreports.Report(data_log, filters=[code], title=f'Error {code}'))

# Count all error code
counter = pyreports.counter(apache_error_log, 'code')
counter = pyreports.counter(data_log, 'code')
# Append new Report on ReportBook with error code counters
error_counter = tablib.Dataset(counter.values(), headers=counter)
all_apache_error.add(pyreports.Report(error_counter))
Expand Down
2 changes: 1 addition & 1 deletion pyreports/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# created by: matteo.guadrini
# __init__.py -- pyreports
#
# Copyright (C) 2021 Matteo Guadrini <matteo.guadrini@hotmail.it>
# Copyright (C) 2022 Matteo Guadrini <matteo.guadrini@hotmail.it>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion pyreports/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# created by: matteo.guadrini
# core -- pyreports
#
# Copyright (C) 2021 Matteo Guadrini <matteo.guadrini@hotmail.it>
# Copyright (C) 2022 Matteo Guadrini <matteo.guadrini@hotmail.it>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion pyreports/datatools.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# created by: matteo.guadrini
# datatools -- pyreports
#
# Copyright (C) 2021 Matteo Guadrini <matteo.guadrini@hotmail.it>
# Copyright (C) 2022 Matteo Guadrini <matteo.guadrini@hotmail.it>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion pyreports/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# created by: matteo.guadrini
# exception.py -- pyreports
#
# Copyright (C) 2021 Matteo Guadrini <matteo.guadrini@hotmail.it>
# Copyright (C) 2022 Matteo Guadrini <matteo.guadrini@hotmail.it>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down
Loading

0 comments on commit d16271b

Please sign in to comment.