-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merging to add docker file for Artifact Registry build (#3)
* added .idea and .vscode folder * added animated progress function Prints animated progress bar as per the completed steps * tests to check animated progress bar function added Smoke test with comparison of output tests added in conjuncture * File handler created * tests for files handler class and its method added passing all runs * __init__.py files * updated file path Now starts from the current directory * Create utils.py * updated .idea and .vscode as folders * src package initalised * Initialization steps to run on environment changes or updates * app entrypoint * added files to create a container
- Loading branch information
1 parent
3d68535
commit 1f74232
Showing
16 changed files
with
254 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,3 +127,8 @@ dmypy.json | |
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# Pycharm config folder | ||
.idea/ | ||
# VsCode config folder | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
if __name__ == '__main__': | ||
print('Running main') |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
requests==2.27.1 | ||
colorama==0.4.4 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |