diff --git a/.gitignore b/.gitignore index b6e4761..a3546d7 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,8 @@ dmypy.json # Pyre type checker .pyre/ + +# Pycharm config folder +.idea/ +# VsCode config folder +.vscode/ \ No newline at end of file diff --git a/app.py b/app.py new file mode 100644 index 0000000..b8bd888 --- /dev/null +++ b/app.py @@ -0,0 +1,3 @@ + +if __name__ == '__main__': + print('Running main') diff --git a/bin/__init__.py b/bin/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bin/docker/Dockerfile b/bin/docker/Dockerfile new file mode 100644 index 0000000..f3f7cd8 --- /dev/null +++ b/bin/docker/Dockerfile @@ -0,0 +1,18 @@ +# syntax=docker/dockerfile:1 + +FROM python:3.9-slim-buster + +WORKDIR /home + +# upgrade pip. +RUN python -m pip3 install --upgrade pip + +# install all the packages. +COPY ./requirements.txt requirements.txt +RUN pip3 install -r requirements.txt + +# copy project files to dir. +COPY ../../ ./app/secretary-app/ + +# running the app +RUN python ./app/secretary-app/app.py diff --git a/bin/docker/requirements.txt b/bin/docker/requirements.txt new file mode 100644 index 0000000..8e86308 --- /dev/null +++ b/bin/docker/requirements.txt @@ -0,0 +1,2 @@ +requests==2.27.1 +colorama==0.4.4 diff --git a/bin/handlers/__init__.py b/bin/handlers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bin/handlers/files_handler.py b/bin/handlers/files_handler.py new file mode 100644 index 0000000..eae58a9 --- /dev/null +++ b/bin/handlers/files_handler.py @@ -0,0 +1,39 @@ +from os import path, remove, makedirs + + +class FileHandler: + @staticmethod + def create_file(file_path: str, contents: str): + """ + Creates a file and writes to it + Use this if you want to update the file if it has changes in between + :param file_path: File path where the file needs to be created or exits with file name and extension + :param contents: content that is to populated/written in the file + :return: None + """ + makedirs(path.dirname(file_path), exist_ok=True) + with open(file_path, 'w') as _file: + _file.write(contents) + + @staticmethod + def update_file(file_path: str, contents: str): + """ + Updates the file by adding from last line of the file + :param file_path: File path where the file needs to be created or exits with file name and extension + :param contents: content that is to populated/appended from the end of the file file + :return: None + """ + makedirs(path.dirname(file_path), exist_ok=True) + with open(file_path, 'a') as _file: + _file.write(contents) + + @staticmethod + def delete_file(file_path: str): + """ + Deletes the file in the specified path + :param file_path: File path where the file needs to be created or exits with file name and extension + :return: None + """ + + if path.exists(file_path): + remove(file_path) diff --git a/bin/output.py b/bin/output.py new file mode 100644 index 0000000..2ced0b6 --- /dev/null +++ b/bin/output.py @@ -0,0 +1,49 @@ +import subprocess +from time import sleep + + +class Output: + _completed_steps: int + _close: bool + _total_steps: int + + def __init__(self, total_steps=50): + self._close = False + self._completed_steps = 0 + self._total_steps = total_steps + + def progress_output(self): + _length: int = 50 + + complete: int = int((self._completed_steps / self._total_steps) * _length) + progress_anim: str = '[' + for i in range(1, _length): + if i <= complete: + progress_anim += '█' + else: + progress_anim += '-' + + progress_anim += '] {}% completed'.format(round((self._completed_steps / self._total_steps) * 100, 2)) + print(progress_anim) + + def set_progress(self, steps_completed): + self._completed_steps = steps_completed + self.progress_output() + + def end(self): + self._close = True + + +if __name__ == '__main__': + out = Output(75) + + out.progress_output() + sleep(2) + out.set_progress(5) + sleep(1) + out.set_progress(30) + sleep(1) + out.set_progress(62) + sleep(1) + out.set_progress(75) + sleep(1) diff --git a/bin/utils.py b/bin/utils.py new file mode 100644 index 0000000..b1ab97a --- /dev/null +++ b/bin/utils.py @@ -0,0 +1,8 @@ +from bin.handlers.response_handler import ResponseHandlers, Response +from shlex import split + + +def install_package(package): + args = split('pip3 install {} --retries'.format(package)) + _r = ResponseHandlers.shell_response(command=args, output=False) + return Response.status_code diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/initalise.py b/src/initalise.py new file mode 100644 index 0000000..c766ec5 --- /dev/null +++ b/src/initalise.py @@ -0,0 +1,23 @@ +import argparse +import subprocess +from bin.handlers.exception_handler import Exception_Handler, ExceptionType + +from bin.utils import install_package + + +class initialise: + exec_handler = Exception_Handler() + + def check_requests_package(self): + try: + import requests + except ImportError as err: + check = install_package(requests) + if check is 0: + pass + else: + self.exec_handler.handle(exception_type=ExceptionType.CLOSE, message='[E] Unable to install package: ' + 'requests') + + def check_git(self): + pass diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/bin/__init__.py b/tests/bin/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/bin/handlers/__init__.py b/tests/bin/handlers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/bin/handlers/test_files_handler.py b/tests/bin/handlers/test_files_handler.py new file mode 100644 index 0000000..bfce0a5 --- /dev/null +++ b/tests/bin/handlers/test_files_handler.py @@ -0,0 +1,70 @@ +from unittest import TestCase, main +from os import path +from bin.handlers.files_handler import FileHandler + + +class TestFileHandler(TestCase): + fileHandler = FileHandler() + + test_content: str = ('Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget \n' + 'dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, ' + 'nascetur ridiculus mus. Donec \n ' + 'quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis ' + 'enim. Donec pede justo, \n ' + ' fringilla vel, aliquet nec, vulputate eget, arcu. \n' + '\n' + 'In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede ' + 'mollis pretium. Integer \n ' + 'tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. ' + 'Aenean leo ligula, \n ' + 'porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, ' + 'viverra quis, feugiat a, tellus.') + + test_append_content: str = ( + '\nPhasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. \n' + 'Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas ' + '\n ' + 'tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. ' + 'Nam \n ' + 'quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. ' + 'Donec \n ' + 'vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus ' + 'tincidunt. \n ' + 'Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum ' + '\n ' + ' sodales, augue velit cursus nunc,') + + test_file_path: str = './res/test_text.txt' + + def test_create_file(self): + print('Testing file creation...') + self.fileHandler.create_file(self.test_file_path, self.test_content) + self.assertEqual(path.exists(self.test_file_path), True) + + def test_create_file_integrity(self): + self.fileHandler.create_file(self.test_file_path, self.test_content) + self.assertEqual(path.exists(self.test_file_path), True) + + actual_file = open(self.test_file_path, 'r') + actual_content = actual_file.read() + actual_file.close() + + self.assertEqual(self.test_content, actual_content) + + def test_update_file(self): + self.fileHandler.create_file(self.test_file_path, self.test_content) + self.assertEqual(path.exists(self.test_file_path), True) + + self.fileHandler.update_file(self.test_file_path, self.test_append_content) + actual_file = open(self.test_file_path, 'r') + actual_content = actual_file.read() + + self.assertEqual(self.test_content + self.test_append_content, actual_content) + + def test_delete_file(self): + self.fileHandler.delete_file(self.test_file_path) + self.assertEqual(path.exists(self.test_file_path), False) + + +if __name__ == '__main__': + main() diff --git a/tests/bin/output_test.py b/tests/bin/output_test.py new file mode 100644 index 0000000..1f06955 --- /dev/null +++ b/tests/bin/output_test.py @@ -0,0 +1,37 @@ +from unittest import TestCase, main +from io import StringIO +from unittest.mock import patch + +from bin.output import Output + + +class unittests(TestCase): + out = Output(75) + + __step_1: str = '[-------------------------------------------------] 0.0% completed\n' + __step_2: str = '[███----------------------------------------------] 6.67% completed\n' + __step_3: str = '[████████████████████-----------------------------] 40.0% completed\n' + __step_4: str = '[█████████████████████████████████████████--------] 82.67% completed\n' + __step_5: str = '[█████████████████████████████████████████████████] 100.0% completed\n' + + def test_output(self): + with patch('sys.stdout', new=StringIO()) as actual_output: + self.out.progress_output() + self.assertEqual(self.__step_1, actual_output.getvalue()) + + with patch('sys.stdout', new=StringIO()) as actual_output: + self.out.set_progress(5) + self.assertEqual(self.__step_2, actual_output.getvalue()) + with patch('sys.stdout', new=StringIO()) as actual_output: + self.out.set_progress(30) + self.assertEqual(self.__step_3, actual_output.getvalue()) + with patch('sys.stdout', new=StringIO()) as actual_output: + self.out.set_progress(62) + self.assertEqual(self.__step_4, actual_output.getvalue()) + with patch('sys.stdout', new=StringIO()) as actual_output: + self.out.set_progress(75) + self.assertEqual(self.__step_5, actual_output.getvalue()) + + +if __name__ == '__main__': + main()