- Python 97.8%
- Shell 1.6%
- Dockerfile 0.6%
|
|
||
|---|---|---|
| .forgejo/workflows | ||
| docker | ||
| mylib | ||
| tests | ||
| .gitignore | ||
| .pre-commit-config.yaml | ||
| .pre-commit-pylint | ||
| .pre-commit-pytest | ||
| .pylintrc | ||
| build.sh | ||
| README.md | ||
| setup.cfg | ||
| setup.py | ||
| tests.sh | ||
Python MyLib
Just a set of helpers small libs to make common tasks easier in my scripts development.
Installation
Select extras you needs:
- config : manage project's configuration
- email : forge and send email
- ldap : easily access to an LDAP directory
- mysql : easily requesting MySQL database
- pbar : progress bar helper
- pgsql : easily requesting PostgreSQL database
- oracle : easily requesting Oracle database
- report : report helpers
- sftp : SFTP helpers
- all : install all modules dependencies
- dev : install development dependencies
Dependencies
To reduce the number of dependencies to build & install inside your virtual environment, it's recommend to create it with the --system-site-packages argument and pre-install the following packages from Debian repository :
- for config extra:
apt install python3-argcomplete python3-keyring python3-systemd - for email extra:
apt install python3-magic python3-mako - for ldap extra:
apt install python3-ldap python3-dateutil python3-tz - for pbar extra:
apt install python3-progressbar - for pgsql extra:
apt install python3-psycopg2 - for report extra:
apt install python3-xlsxwriter - for sftp extra:
apt install python3-paramiko
Otherwise, the following build dependencies must be installed:
apt install \
build-essential \
python3 \
python3-dev
# For LDAP:
apt install libldap2-dev libsasl2-dev
# For Config:
apt install pkg-config libsystemd-dev
# For PgSQL:
apt install libpq-dev
# For MySQL:
apt install libmariadb-dev
Using pip
Just run python3 -m pip install "git+https://gitea.zionetrix.net/bn8/python-mylib.git[config,pbar]"
From sources
Just run python3 -m pip install ".[config,pbar]" from sources directory.
Note: This project could previously use as independent python files (not as module). This old version is archived in legacy git branch (not maintained).
Include libs
FIXME: This section is obsolete and needs to be updated. Please check the mylib directory to see which libraries are now provided.
- mylib.email.EmailClient: An email client to forge (eventually using template) and send email via a SMTP server
- mylib.ldap.LdapServer: A small lib to make requesting LDAP server easier. It's also provide some helper functions to deal with LDAP date string.
- mylib.mysql.MyDB: An extra small lib to remember me how to interact with MySQL/MariaDB database
- mylib.pgsql.PgDB: An small lib to remember me how to interact with PostgreSQL database. Warning: The insert/update/delete/select methods demonstrate how to forge raw SQL request, but it's a bad idea: Prefer using prepared query.
- mylib.opening_hours: A set of helper functions to deal with french opening hours (including normal opening hours, exceptional closure and nonworking public holidays).
- mylib.pbar.Pbar: A small lib for progress bar
- mylib.report.Report: A small lib to implement logging based email report send at exit
To know how to use these libs, you can take a look on mylib.scripts content or in tests directory.
Code Style
pylint is used to check for errors and enforces a coding standard, using those parameters:
pylint --extension-pkg-whitelist=cx_Oracle
flake8 is also used to check for errors and enforces a coding standard, using those parameters:
flake8 --max-line-length=100
black is used to format the code, using those parameters:
black --target-version py37 --line-length 100
isort is used to format the imports, using those parameter:
isort --profile black --line-length 100
pyupgrade is used to automatically upgrade syntax, using those parameters:
pyupgrade --keep-percent-format --py37-plus
Note: There is .pre-commit-config.yaml to use pre-commit to automatically run these tools before commits. After cloning the repository, execute pre-commit install to install the git hook.
Copyright
Copyright (c) 2013-2021 Benjamin Renard brenard@zionetrix.net
License
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.