Add initial scripts and skeleton
This commit is contained in:
parent
599df44d89
commit
a700ab99ea
10 changed files with 264 additions and 5 deletions
4
defaults
4
defaults
|
@ -1,6 +1,8 @@
|
||||||
|
#!/bin/bash
|
||||||
author="Antonio J. Delgado"
|
author="Antonio J. Delgado"
|
||||||
authoring_date=$(date +%Y)
|
authoring_date=$(date +%Y)
|
||||||
project_name="Project Name"
|
project_name="Project Name"
|
||||||
project_codename="project-codename"
|
project_codename="project-codename"
|
||||||
version=0.0.1
|
version=0.0.1
|
||||||
deployment_path="${HOME}/repos/"
|
deployment_path="${HOME}/repos/"
|
||||||
|
description=""
|
|
@ -1,11 +1,15 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
-e defaults && . defaults
|
# shellcheck disable=SC1090
|
||||||
|
if [ -e defaults ]
|
||||||
|
then
|
||||||
|
. "$(dirname "${0}")/defaults"
|
||||||
|
fi
|
||||||
while [ $# -gt 0 ]
|
while [ $# -gt 0 ]
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
"--author")
|
"--author")
|
||||||
shift
|
shift
|
||||||
DESTINATION="${1}"
|
author="${1}"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
"--authoring-date")
|
"--authoring-date")
|
||||||
|
@ -32,10 +36,23 @@ do
|
||||||
deployment_path="${1}"
|
deployment_path="${1}"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
echo "Ignoring unknwon parameter '${1}'"
|
echo "Ignoring unknwon parameter '${1}'"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
destination_path="${deployment_path}/${project_codename}"
|
||||||
|
mkdir "${destination_path}"
|
||||||
|
script_path=$(dirname "${0}")
|
||||||
|
cp "${script_path}/skeleton" "${destination_path}" -rfp
|
||||||
|
mv "${destination_path}/project_codename.py" "${destination_path}/${project_codename}.py"
|
||||||
|
while read -r file
|
||||||
|
do
|
||||||
|
sed -i "s/%project_codename%/${project_codename}/g" "${file}"
|
||||||
|
sed -i "s/%author%/${author}/g" "${file}"
|
||||||
|
sed -i "s/%authoring_date%/${authoring_date}/g" "${file}"
|
||||||
|
sed -i "s/%project_name%/${project_name}/g" "${file}"
|
||||||
|
sed -i "s/%version%/${version}/g" "${file}"
|
||||||
|
done <<< "$(ls "${destination_path}/")"
|
138
skeleton/.gitignore
vendored
Normal file
138
skeleton/.gitignore
vendored
Normal file
|
@ -0,0 +1,138 @@
|
||||||
|
Byte-compiled / optimized / DLL files
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
|
||||||
|
# C extensions
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Distribution / packaging
|
||||||
|
.Python
|
||||||
|
build/
|
||||||
|
develop-eggs/
|
||||||
|
dist/
|
||||||
|
downloads/
|
||||||
|
eggs/
|
||||||
|
.eggs/
|
||||||
|
lib/
|
||||||
|
lib64/
|
||||||
|
parts/
|
||||||
|
sdist/
|
||||||
|
var/
|
||||||
|
wheels/
|
||||||
|
share/python-wheels/
|
||||||
|
*.egg-info/
|
||||||
|
.installed.cfg
|
||||||
|
*.egg
|
||||||
|
MANIFEST
|
||||||
|
|
||||||
|
# PyInstaller
|
||||||
|
# Usually these files are written by a python script from a template
|
||||||
|
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||||
|
*.manifest
|
||||||
|
*.spec
|
||||||
|
|
||||||
|
# Installer logs
|
||||||
|
pip-log.txt
|
||||||
|
pip-delete-this-directory.txt
|
||||||
|
|
||||||
|
# Unit test / coverage reports
|
||||||
|
htmlcov/
|
||||||
|
.tox/
|
||||||
|
.nox/
|
||||||
|
.coverage
|
||||||
|
.coverage.*
|
||||||
|
.cache
|
||||||
|
nosetests.xml
|
||||||
|
coverage.xml
|
||||||
|
*.cover
|
||||||
|
*.py,cover
|
||||||
|
.hypothesis/
|
||||||
|
.pytest_cache/
|
||||||
|
cover/
|
||||||
|
|
||||||
|
# Translations
|
||||||
|
*.mo
|
||||||
|
*.pot
|
||||||
|
|
||||||
|
# Django stuff:
|
||||||
|
*.log
|
||||||
|
local_settings.py
|
||||||
|
db.sqlite3
|
||||||
|
db.sqlite3-journal
|
||||||
|
|
||||||
|
# Flask stuff:
|
||||||
|
instance/
|
||||||
|
.webassets-cache
|
||||||
|
|
||||||
|
# Scrapy stuff:
|
||||||
|
.scrapy
|
||||||
|
|
||||||
|
# Sphinx documentation
|
||||||
|
docs/_build/
|
||||||
|
|
||||||
|
# PyBuilder
|
||||||
|
.pybuilder/
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Jupyter Notebook
|
||||||
|
.ipynb_checkpoints
|
||||||
|
|
||||||
|
# IPython
|
||||||
|
profile_default/
|
||||||
|
ipython_config.py
|
||||||
|
|
||||||
|
# pyenv
|
||||||
|
# For a library or package, you might want to ignore these files since the code is
|
||||||
|
# intended to run in multiple environments; otherwise, check them in:
|
||||||
|
# .python-version
|
||||||
|
|
||||||
|
# pipenv
|
||||||
|
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||||
|
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||||
|
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||||
|
# install all needed dependencies.
|
||||||
|
#Pipfile.lock
|
||||||
|
|
||||||
|
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
||||||
|
__pypackages__/
|
||||||
|
|
||||||
|
# Celery stuff
|
||||||
|
celerybeat-schedule
|
||||||
|
celerybeat.pid
|
||||||
|
|
||||||
|
# SageMath parsed files
|
||||||
|
*.sage.py
|
||||||
|
|
||||||
|
# Environments
|
||||||
|
.env
|
||||||
|
.venv
|
||||||
|
env/
|
||||||
|
venv/
|
||||||
|
ENV/
|
||||||
|
env.bak/
|
||||||
|
venv.bak/
|
||||||
|
|
||||||
|
# Spyder project settings
|
||||||
|
.spyderproject
|
||||||
|
.spyproject
|
||||||
|
|
||||||
|
# Rope project settings
|
||||||
|
.ropeproject
|
||||||
|
|
||||||
|
# mkdocs documentation
|
||||||
|
/site
|
||||||
|
|
||||||
|
# mypy
|
||||||
|
.mypy_cache/
|
||||||
|
.dmypy.json
|
||||||
|
dmypy.json
|
||||||
|
|
||||||
|
# Pyre type checker
|
||||||
|
.pyre/
|
||||||
|
|
||||||
|
# pytype static type analyzer
|
||||||
|
.pytype/
|
||||||
|
|
||||||
|
# Cython debug symbols
|
||||||
|
cython_debug/
|
17
skeleton/README.md
Normal file
17
skeleton/README.md
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
# %project_codename%
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
### Linux
|
||||||
|
|
||||||
|
`sudo python3 setup.py install`
|
||||||
|
|
||||||
|
### Windows (from PowerShell)
|
||||||
|
|
||||||
|
`& $(where.exe python).split()[0] setup.py install`
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
`%project_codename%.py [--debug-level|-d CRITICAL|ERROR|WARNING|INFO|DEBUG|NOTSET] # Other parameters`
|
0
skeleton/__init__.py
Normal file
0
skeleton/__init__.py
Normal file
69
skeleton/project_codename.py
Normal file
69
skeleton/project_codename.py
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- encoding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# This script is licensed under GNU GPL version 2.0 or above
|
||||||
|
# (c) %authoring_date% %author%
|
||||||
|
# %description%
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import logging
|
||||||
|
import click
|
||||||
|
import click_config_file
|
||||||
|
from logging.handlers import SysLogHandler
|
||||||
|
|
||||||
|
class %project_codename%:
|
||||||
|
|
||||||
|
def _init_(self, debug_level, log_file):
|
||||||
|
''' Initial function called when object is created '''
|
||||||
|
self.config = dict()
|
||||||
|
self.config['debug_level'] = debug_level
|
||||||
|
self._init_log()
|
||||||
|
|
||||||
|
def _init_log(self):
|
||||||
|
''' Initialize log object '''
|
||||||
|
self._log = logging.getLogger("%project_codename%")
|
||||||
|
self._log.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
sysloghandler = SysLogHandler()
|
||||||
|
sysloghandler.setLevel(logging.DEBUG)
|
||||||
|
self._log.addHandler(sysloghandler)
|
||||||
|
|
||||||
|
streamhandler = logging.StreamHandler(sys.stdout)
|
||||||
|
streamhandler.setLevel(logging.getLevelName(self.config.get("debug_level", 'INFO')))
|
||||||
|
self._log.addHandler(streamhandler)
|
||||||
|
|
||||||
|
if 'log_file' in self.config:
|
||||||
|
log_file = self.config['log_file']
|
||||||
|
else:
|
||||||
|
home_folder = os.environ.get('HOME', os.environ.get('USERPROFILE', ''))
|
||||||
|
log_folder = os.path.join(home_folder, "log")
|
||||||
|
log_file = os.path.join(log_folder, "%project_codename%.log")
|
||||||
|
|
||||||
|
if not os.path.exists(os.path.dirname(log_file)):
|
||||||
|
os.path.mkdir(os.path.dirname(log_file))
|
||||||
|
|
||||||
|
filehandler = logging.handlers.RotatingFileHandler(log_file, maxBytes=102400000)
|
||||||
|
# create formatter
|
||||||
|
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||||
|
filehandler.setFormatter(formatter)
|
||||||
|
filehandler.setLevel(logging.DEBUG)
|
||||||
|
self._log.addHandler(filehandler)
|
||||||
|
return True
|
||||||
|
|
||||||
|
@click.command()
|
||||||
|
@click.option("--debug-level", "-d", default="INFO",
|
||||||
|
type=click.Choice(
|
||||||
|
["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", "NOTSET"],
|
||||||
|
case_sensitive=False,
|
||||||
|
), help='Set the debug level for the standard output.')
|
||||||
|
@click.option('--log-file', '-l', help="File to store all debug messages.")
|
||||||
|
#@click.option("--dummy","-n" is_flag=True, help="Don't do anything, just show what would be done.") # Don't forget to add dummy to parameters of main function
|
||||||
|
@click_config_file.configuration_option()
|
||||||
|
def main(debug_level, log_file):
|
||||||
|
object = %project_codename%(debug_level, log_file)
|
||||||
|
object._log.info('Initialized %project_codename%')
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
3
skeleton/pyproject.toml
Normal file
3
skeleton/pyproject.toml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
[build-system]
|
||||||
|
requires = ["setuptools", "wheel"]
|
||||||
|
build-backend = "setuptools.build_meta"
|
2
skeleton/requirements.txt
Normal file
2
skeleton/requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
click
|
||||||
|
click_config_file
|
9
skeleton/setup.cfg
Normal file
9
skeleton/setup.cfg
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
[metadata]
|
||||||
|
name = %project_codename%
|
||||||
|
version = %version%
|
||||||
|
|
||||||
|
[options]
|
||||||
|
packages = %project_codename%
|
||||||
|
install_requires =
|
||||||
|
requests
|
||||||
|
importlib; python_version == "3.6"
|
2
skeleton/setup.py
Normal file
2
skeleton/setup.py
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
import setuptools
|
||||||
|
setuptools.setup()
|
Loading…
Reference in a new issue