From 20f0d08c3e18267bf345313b8a29d1c6ca95688d Mon Sep 17 00:00:00 2001 From: Mauricio Baeza Date: Mon, 25 Jan 2021 22:20:28 -0600 Subject: [PATCH] Update system --- .gitignore | 3 +++ CHANGELOG.md | 4 ++++ VERSION | 1 + source/app.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+) create mode 100644 CHANGELOG.md create mode 100644 VERSION create mode 100755 source/app.py diff --git a/.gitignore b/.gitignore index 13d1490..d684f1c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ # ---> Python + +conf.py + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..8695bbb --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,4 @@ + +0.1.0 [25-Ene-2021] +--------------------- + - Script para actualizar Empresa Libre diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..6e8bf73 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.1.0 diff --git a/source/app.py b/source/app.py new file mode 100755 index 0000000..4c4773c --- /dev/null +++ b/source/app.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 + +import argparse +import logging +import shlex +import subprocess + + +LOG_FORMAT = '%(asctime)s - %(levelname)s - %(message)s' +LOG_DATE = '%d/%m/%Y %H:%M:%S' +logging.addLevelName(logging.ERROR, '\033[1;41mERROR\033[1;0m') +logging.addLevelName(logging.DEBUG, '\x1b[33mDEBUG\033[1;0m') +logging.addLevelName(logging.INFO, '\x1b[32mINFO\033[1;0m') +logging.basicConfig(level=logging.DEBUG, format=LOG_FORMAT, datefmt=LOG_DATE) +log = logging.getLogger(__name__) + + +PATH_SISTEMA = '/opt/empresa-libre' + + +def _call(args): + cmd = shlex.split(args) + result = subprocess.run(cmd, stdout=subprocess.PIPE).stdout.decode() + return result + + +def _actualizar(): + confirm = input('¿Estas seguro de actualizar (escribe si) ? ') + if confirm != 'si': + msg = 'Proceso de actualización cancelado' + log.info(msg) + return + + args = f'git -C {PATH_SISTEMA} pull origin master' + _call(args) + + msg = 'Sistema actualizado correctamente' + log.info(msg) + return + + +def main(args): + + if args.actualizar: + _actualizar() + return + + return + + +def _process_command_line_arguments(): + parser = argparse.ArgumentParser( + description='Empresa Libre Util') + parser.add_argument('-a', '--actualizar', dest='actualizar', + action='store_true', default=False, required=False) + return parser.parse_args() + + +if __name__ == '__main__': + args = _process_command_line_arguments() + main(args)