From 012055198bbdefa7b1d5d16472419ec1f8be80db Mon Sep 17 00:00:00 2001 From: Cedric Date: Tue, 28 May 2024 02:30:57 +0800 Subject: [PATCH 01/13] doc: adjust Scope more specific to this project --- CODE_OF_CONDUCT.md | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 4254f59..c17dbf9 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,6 +1,9 @@ # Code of Conduct -## v1 - Drafted by Izaac Saleh & Sukhwan Ko +## Versions + +- v2 - Drafted by Sukhwan Ko +- v1 - Drafted by Izaac Saleh & Sukhwan Ko ## Our Pledge @@ -55,16 +58,23 @@ any moderations they deem appropriate. --- -- Our online platform (website, forum, chatroom etc.) -- Code repository (including comments, pull requests, issue reports etc.) -- Project-related communication channels such as: - - Email - - Slack - - Microsoft Teams - - Discord - - Asana - - etc. -- In-person events(Conferences, meetups etc.) +**Our online platform** + +- **Website**: The Code of Conduct applies to all comments, posts, and messages left on the website, including those in forums, discussion boards, or comment sections. +- **Forum**: The same rules apply to all discussions, threads, and topics within the forum, including those that are public or private. +- **Chatroom**: The Code of Conduct covers all conversations, messages, and files shared in chatroom, whether they're public or invited-only. + +**Code repository** + +- **Comments**: The Code applies to all comments left on code snippets, commits, or pull requests, as well as any replies or discussions that might arise. +- **Pull requests:** The same rules apply to all pull requests, including those for new features, bug fixes, or refactoring code. +- **Issue reports**: The Code of conduct covers all issue reports, whether they're related to bugs, feature requests, or documentation updates. + +**Project-related communication channels** + +- **Email**: The Code applies to all emails sent to the project's email list, including these that are public or private. +- **Microsoft Teams:** The Code of Conduct covers all discussions, meetings, and file shared within the project's Microsoft Teams space. +- **Discord(main):** The same rules apply to all voice or text chats, channels, and servers used by the project on Discord. ## Enforcement From c33a88e488de53b315426e20781d4eea1f103fe5 Mon Sep 17 00:00:00 2001 From: Cedric Date: Tue, 28 May 2024 02:33:12 +0800 Subject: [PATCH 02/13] doc: updated Enforcement in code of conduct --- CODE_OF_CONDUCT.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index c17dbf9..809fa5a 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -80,7 +80,7 @@ any moderations they deem appropriate. --- -Community leaders will take action to address violations of the Code of Conduct. The specific consequences will depend on the severity of the violation. +Our Community Leaders are responsible for clarifying and enforcing the standards of acceptable behaviour and are expected to lead by example. If a breach of the Code of Conduct is found to have occurred, Community Leaders are charged with taking appropriate but fair corrective action. Community Leaders have the responsibility, and maintain the right, to remove, edit, or reject comments, commits, code, issues, and other contributions that are not in alignment with this Code of Conduct. They will communicate the reasons for any moderation they deem appropriate. ## Enforcement Guidelines From e73b116ca4749feade2f56dcfd6a26fa46c97d99 Mon Sep 17 00:00:00 2001 From: Cedric Date: Tue, 28 May 2024 02:37:47 +0800 Subject: [PATCH 03/13] doc: updated Enforcement guidlines in code of conduct --- CODE_OF_CONDUCT.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 809fa5a..e1c988e 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -110,6 +110,32 @@ Our Community Leaders are responsible for clarifying and enforcing the standards - **Consequence:** A permanent ban from any sort of public interaction within the community. +5. Additional Guidelines + +- Initial Response: Upon receiving a report of potential Code of Conduct violation, our Community Leaders will acknowledge receipt and promptly investigate. + - Investigation Process: + - Gather information from all parties involved. + - Review relevant records and communications. + - Investigate in a fair and impartial manner. + - Communication During Investigation: + - Maintain open communication with all parties involved. + - Provide updates on the progress and outcome of the investigation. + - Decision-Making: + - Community Leaders will make decisions based on the findings and evidence gathered during the investigation. + - Consequences for Repeat Offenders: + - For repeat offenders, consequences may be escalated or combined (e.g., temporary ban and loss of privileges). + - Appeals Process: + - Establish a clear appeals process for individuals affected by enforcement decisions. + - Ensure that appeals are heard in a fair and impartial manner. + +6. Resolving Disputes + +- Dispute Resolution Committee: Establish a committee composed of community leaders to resolve disputes related to Code of Conduct violations. +- Dispute Resolution Process: + - Identify the nature of the dispute. + - Gather information from all parties involved. + - Make a fair and impartial decision. + ## Attribution This Code of Conduct is adapted from the GITHUB documents template for "code of conduct" found when adding a file of the From 2e97b774f95ad51b2bf85b54dd832f49ecb60d36 Mon Sep 17 00:00:00 2001 From: Cedric Date: Tue, 28 May 2024 09:59:33 +0800 Subject: [PATCH 04/13] fix: macOS port conflict resolution macOS often conflicts with port number 5000. Therefore, if the system is running on macOS, it may automatically open port 5001 to avoid conflicts. --- app/app.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/app.py b/app/app.py index d060138..08700e3 100644 --- a/app/app.py +++ b/app/app.py @@ -1,3 +1,4 @@ +import sys import os.path import logging import shutil @@ -275,6 +276,8 @@ def update_tesseract_path(): if __name__ == "__main__": host = "localhost" port = 5000 + if sys.platform.lower() in ['darwin', 'linux']: + port = 5002 logging.basicConfig(filename="app.log", filemode="w", level=logging.DEBUG, format="%(levelname)s - %(message)s") print("[*] Starting OcrRoo Server") print(f"[*] OcrRoo Server running on http://{host}:{port}/") From f78e6636f10d21bfdbbfe6c1df9ccacbfcce6e03 Mon Sep 17 00:00:00 2001 From: Cedric Date: Tue, 28 May 2024 11:06:09 +0800 Subject: [PATCH 05/13] Fix: FileNotFoundError: Adjust access path to access config.example.ini file It is encountering a FileNotFoundError when running app.py in Visual Studio Code on my Mac. The issue was resolved by adding both the current and parent directories to the project path." --- app/app.py | 11 ++++++----- app/utils.py | 8 +++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/app.py b/app/app.py index 08700e3..13789e5 100644 --- a/app/app.py +++ b/app/app.py @@ -1,5 +1,7 @@ +import os import sys import os.path +sys.path.append(os.path.dirname(os.path.abspath(os.path.dirname(__file__)))) import logging import shutil from typing import Optional @@ -231,9 +233,9 @@ def update_settings(): def reset_settings(): print("Current working directory:", os.getcwd()) # Delete the existing config.ini file - if os.path.exists('config.ini'): - os.remove('config.ini') - shutil.copy('config.example.ini', 'config.ini') + if os.path.exists('app/config.ini'): + os.remove('app/config.ini') + shutil.copy('app/config.example.ini', 'app/config.ini') current_settings = utils.get_current_settings() return render_template('settings.html', current_settings=current_settings) @@ -272,7 +274,6 @@ def update_tesseract_path(): message = 'Could not find tesseract executable. Please enter the path manually.' return render_template('settings.html', current_settings=current_settings, message=message) - if __name__ == "__main__": host = "localhost" port = 5000 @@ -281,6 +282,6 @@ def update_tesseract_path(): logging.basicConfig(filename="app.log", filemode="w", level=logging.DEBUG, format="%(levelname)s - %(message)s") print("[*] Starting OcrRoo Server") print(f"[*] OcrRoo Server running on http://{host}:{port}/") - app.run(host=host, port=port) + app.run(host=host, port=port, debug=True) else: logging.basicConfig(level=logging.DEBUG, format="%(levelname)s - %(message)s") diff --git a/app/utils.py b/app/utils.py index 76a8506..3435d89 100644 --- a/app/utils.py +++ b/app/utils.py @@ -1,3 +1,5 @@ +import sys, os.path +sys.path.append(os.path.dirname(os.path.abspath(os.path.dirname(__file__)))) import hashlib import json import os.path @@ -27,9 +29,9 @@ def config(section: str = None, option: str = None) -> Union[ConfigParser, str]: if (section is None) != (option is None): raise SyntaxError("section AND option parameters OR no parameters must be passed to function config()") parser = ConfigParser() - if not os.path.exists("config.ini"): - shutil.copy("config.example.ini", "config.ini") - parser.read("config.ini") + if not os.path.exists("app/config.ini"): + shutil.copy("app/config.example.ini", "app/config.ini") + parser.read("app/config.ini") if parser.get("AppSettings", "openai_api_key") != "your_openai_api_key_here": openai.api_key = parser.get("AppSettings", "openai_api_key") # TODO: This only needs to be set once, unsure if calling this will cause any performance issues same for From 94622e530a89fbd1ebc769ad799e432c01a6838a Mon Sep 17 00:00:00 2001 From: Cedric Date: Tue, 28 May 2024 11:22:30 +0800 Subject: [PATCH 06/13] chore: create function for check platform for testing purpose --- app/app.py | 6 ++++-- app/utils.py | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/app.py b/app/app.py index 13789e5..1986333 100644 --- a/app/app.py +++ b/app/app.py @@ -277,8 +277,10 @@ def update_tesseract_path(): if __name__ == "__main__": host = "localhost" port = 5000 - if sys.platform.lower() in ['darwin', 'linux']: - port = 5002 + if utils.update_port() == True: + port = 5002 + else: + port = port logging.basicConfig(filename="app.log", filemode="w", level=logging.DEBUG, format="%(levelname)s - %(message)s") print("[*] Starting OcrRoo Server") print(f"[*] OcrRoo Server running on http://{host}:{port}/") diff --git a/app/utils.py b/app/utils.py index 3435d89..61c3bc5 100644 --- a/app/utils.py +++ b/app/utils.py @@ -532,3 +532,8 @@ def extract_form_values(request): 'use_youtube_downloader': youtube_downloader_enabled, } } + +def update_port() -> bool : + if sys.platform.lower() in ['darwin', 'linux']: + return True + return False \ No newline at end of file From 73a9a5490fba6b7f954e3a2655f18370a368a253 Mon Sep 17 00:00:00 2001 From: Cedric Date: Tue, 28 May 2024 11:34:21 +0800 Subject: [PATCH 07/13] feat: platform-speific port setting tests This commit adds two new test cases to ensure that the port number is correcly set based on whether the system is running macOS or Linux --- tests/test_utils.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 16dc7d7..09b06c9 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -8,7 +8,7 @@ Note: These tests use the pytest-mock plugin to replace calls to external resources with mock objects, ensuring that tests remain fast and do not modify external state. """ -import os +import os, sys from app import utils @@ -140,3 +140,16 @@ def test_file_already_exists_false(mocker): def test_file_already_exists_no_user_data(mocker): mocker.patch("app.utils.read_user_data", return_value=None) assert not utils.file_already_exists("4aj3sdl5a4k2sjd091u091j") + + +def test_set_port_for_macos(): + port = 5000 + if sys.platform.lower() == "darwin": + port = 5002 + assert not port == 5000 + +def test_set_port_for_linux(): + port = 5000 + if sys.platform.lower() == "linux": + port = 5002 + assert not port == 5000 \ No newline at end of file From a9991e4109925362a211fc563112f15ccbcf57c5 Mon Sep 17 00:00:00 2001 From: Cedric Date: Wed, 29 May 2024 01:55:22 +0800 Subject: [PATCH 08/13] chore: save config.ini into absolute path --- app/utils.py | 2 +- "data\\userdata.json" | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 "data\\userdata.json" diff --git a/app/utils.py b/app/utils.py index 61c3bc5..b4bea57 100644 --- a/app/utils.py +++ b/app/utils.py @@ -467,7 +467,7 @@ def update_configuration(new_values_dict) -> None: value = str(value) config_file.set(section, key, value) # save the file - with open('config.ini', 'w') as config_file_save: + with open('app/config.ini', 'w') as config_file_save: config_file.write(config_file_save) diff --git "a/data\\userdata.json" "b/data\\userdata.json" new file mode 100644 index 0000000..65d6e9b --- /dev/null +++ "b/data\\userdata.json" @@ -0,0 +1 @@ +{"all_videos": []} \ No newline at end of file From 4c2b64030a52717ded2fec174b8ef45108727c26 Mon Sep 17 00:00:00 2001 From: Cedric Date: Wed, 29 May 2024 10:13:59 +0800 Subject: [PATCH 09/13] fix: userdata.json to absolute path' --- app/utils.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/utils.py b/app/utils.py index b4bea57..880fe5b 100644 --- a/app/utils.py +++ b/app/utils.py @@ -84,15 +84,15 @@ def read_user_data() -> json: Reads the users data from json file :return: Returns user data as json """ - if not os.path.exists("data\\userdata.json"): - if not os.path.exists("data\\"): - os.makedirs("data\\") - with open("data\\userdata.json", "w") as user_data: + if not os.path.exists("app/data/userdata.json"): + if not os.path.exists("app/data/"): + os.makedirs("app/data/") + with open("app/data/userdata.json", "w") as user_data: user_data.write(json.dumps({"all_videos": []})) pass return None try: - with open("data\\userdata.json", "r") as user_data_json: + with open("app/data/userdata.json", "r") as user_data_json: data = json.load(user_data_json) return data except JSONDecodeError: @@ -268,7 +268,7 @@ def update_user_video_data(filename: str, progress: Optional[float] = None, capt record["progress"] = round(progress) if capture is not None: record["captures"].append(capture) - with open("data/userdata.json", "w") as json_data: + with open("app/data/userdata.json", "w") as json_data: json.dump(user_data, json_data, indent=4) @@ -312,7 +312,7 @@ def add_video_to_user_data(filename: str, video_title: str, video_hash: str, you new_video["youtube_url"] = youtube_url video_capture.release() user_data["all_videos"].append(new_video) - with open("data/userdata.json", "w") as json_data: + with open("app/data/userdata.json", "w") as json_data: json.dump(user_data, json_data, indent=4) @@ -446,7 +446,7 @@ def delete_video_from_userdata(filename: str) -> None: if current_video["filename"] == filename: all_videos.remove(current_video) break - with open("data/userdata.json", "w") as json_data: + with open("app/data/userdata.json", "w") as json_data: json.dump(user_data, json_data, indent=4) From cf001a1ace3c97ca40a4ae8aa024189381a39139 Mon Sep 17 00:00:00 2001 From: Cedric Date: Wed, 29 May 2024 10:23:13 +0800 Subject: [PATCH 10/13] fix: thumbnail cannot load it --- app/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/utils.py b/app/utils.py index 880fe5b..aec5915 100644 --- a/app/utils.py +++ b/app/utils.py @@ -296,9 +296,9 @@ def add_video_to_user_data(filename: str, video_title: str, video_hash: str, you return thumbnail = str(int(time.time())) + ".png" # Check if img dir exists if not create - if not os.path.exists("static/img"): - os.makedirs("static/img") - cv2.imwrite(f"static/img/{thumbnail}", frame) + if not os.path.exists("app/static/img"): + os.makedirs("app/static/img") + cv2.imwrite(f"app/static/img/{thumbnail}", frame) new_video = { "video_hash": video_hash, "filename": filename, From 81883678515dd435271539548f682b32a0707e27 Mon Sep 17 00:00:00 2001 From: Cedric Date: Wed, 29 May 2024 22:55:01 +0800 Subject: [PATCH 11/13] fix: test_utils combined 2 test case into 1 --- "data\\userdata.json" | 1 - tests/test_utils.py | 8 +------- 2 files changed, 1 insertion(+), 8 deletions(-) delete mode 100644 "data\\userdata.json" diff --git "a/data\\userdata.json" "b/data\\userdata.json" deleted file mode 100644 index 65d6e9b..0000000 --- "a/data\\userdata.json" +++ /dev/null @@ -1 +0,0 @@ -{"all_videos": []} \ No newline at end of file diff --git a/tests/test_utils.py b/tests/test_utils.py index 09b06c9..fb950e7 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -144,12 +144,6 @@ def test_file_already_exists_no_user_data(mocker): def test_set_port_for_macos(): port = 5000 - if sys.platform.lower() == "darwin": - port = 5002 - assert not port == 5000 - -def test_set_port_for_linux(): - port = 5000 - if sys.platform.lower() == "linux": + if sys.platform.lower() in ["darwin", 'linux']: port = 5002 assert not port == 5000 \ No newline at end of file From ae5b736a7b2c2349635b2dd77c6cdd4a88dfc9f4 Mon Sep 17 00:00:00 2001 From: Cedric Date: Wed, 29 May 2024 23:21:54 +0800 Subject: [PATCH 12/13] chore: adjust line of code --- app/app.py | 7 ++++--- app/utils.py | 15 +++++++++++---- tests/test_utils.py | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/app.py b/app/app.py index 1986333..5895cb9 100644 --- a/app/app.py +++ b/app/app.py @@ -1,7 +1,6 @@ import os import sys import os.path -sys.path.append(os.path.dirname(os.path.abspath(os.path.dirname(__file__)))) import logging import shutil from typing import Optional @@ -12,6 +11,8 @@ import html import glob +sys.path.append(os.path.dirname(os.path.abspath(os.path.dirname(__file__)))) + # Initialise flask app app = Flask(__name__, static_url_path='/static', static_folder='static') # Current video @@ -274,10 +275,10 @@ def update_tesseract_path(): message = 'Could not find tesseract executable. Please enter the path manually.' return render_template('settings.html', current_settings=current_settings, message=message) -if __name__ == "__main__": +if __name__ == "__main__": host = "localhost" port = 5000 - if utils.update_port() == True: + if utils.update_port(): port = 5002 else: port = port diff --git a/app/utils.py b/app/utils.py index aec5915..e58f176 100644 --- a/app/utils.py +++ b/app/utils.py @@ -1,5 +1,5 @@ -import sys, os.path -sys.path.append(os.path.dirname(os.path.abspath(os.path.dirname(__file__)))) +import sys +import os.path import hashlib import json import os.path @@ -16,6 +16,7 @@ from pytube.exceptions import RegexMatchError from configparser import ConfigParser +sys.path.append(os.path.dirname(os.path.abspath(os.path.dirname(__file__)))) def config(section: str = None, option: str = None) -> Union[ConfigParser, str]: """ @@ -533,7 +534,13 @@ def extract_form_values(request): } } -def update_port() -> bool : - if sys.platform.lower() in ['darwin', 'linux']: +def update_port()->bool: + """ + Checks if the current platform is a Unix-based system (like Darwin or Linux). If so, returns True. + + Returns: + bool - True if running on a Unix-based system, False otherwise + """ + if sys.platform.lower() in ['darwin', 'linux']: return True return False \ No newline at end of file diff --git a/tests/test_utils.py b/tests/test_utils.py index fb950e7..52cf0e0 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -142,7 +142,7 @@ def test_file_already_exists_no_user_data(mocker): assert not utils.file_already_exists("4aj3sdl5a4k2sjd091u091j") -def test_set_port_for_macos(): +def test_set_port_for_macos(): port = 5000 if sys.platform.lower() in ["darwin", 'linux']: port = 5002 From 2df29fb9640c1b0bf7caf65a93cf793c22273b87 Mon Sep 17 00:00:00 2001 From: Cedric Date: Thu, 30 May 2024 22:49:34 +0800 Subject: [PATCH 13/13] chore: tidy up the code lint with flake8 --- app/app.py | 9 +++++---- app/utils.py | 11 +++++------ tests/test_utils.py | 8 ++++---- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/app.py b/app/app.py index 5895cb9..4eb555e 100644 --- a/app/app.py +++ b/app/app.py @@ -275,12 +275,13 @@ def update_tesseract_path(): message = 'Could not find tesseract executable. Please enter the path manually.' return render_template('settings.html', current_settings=current_settings, message=message) -if __name__ == "__main__": + +if __name__ == "__main__": host = "localhost" port = 5000 - if utils.update_port(): - port = 5002 - else: + if utils.update_port(): + port = 5002 + else: port = port logging.basicConfig(filename="app.log", filemode="w", level=logging.DEBUG, format="%(levelname)s - %(message)s") print("[*] Starting OcrRoo Server") diff --git a/app/utils.py b/app/utils.py index e58f176..b3f214c 100644 --- a/app/utils.py +++ b/app/utils.py @@ -2,7 +2,6 @@ import os.path import hashlib import json -import os.path import shutil import subprocess import logging @@ -18,6 +17,7 @@ sys.path.append(os.path.dirname(os.path.abspath(os.path.dirname(__file__)))) + def config(section: str = None, option: str = None) -> Union[ConfigParser, str]: """ Loads config variables from file and returns either specified variable or parser object. If attempting to @@ -534,13 +534,12 @@ def extract_form_values(request): } } -def update_port()->bool: + +def update_port() -> bool: """ Checks if the current platform is a Unix-based system (like Darwin or Linux). If so, returns True. - - Returns: - bool - True if running on a Unix-based system, False otherwise + :return: bool - True if running on a Unix-based system, False otherwise """ if sys.platform.lower() in ['darwin', 'linux']: return True - return False \ No newline at end of file + return False diff --git a/tests/test_utils.py b/tests/test_utils.py index 52cf0e0..79c14e1 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -8,8 +8,8 @@ Note: These tests use the pytest-mock plugin to replace calls to external resources with mock objects, ensuring that tests remain fast and do not modify external state. """ -import os, sys - +import os +import sys from app import utils @@ -142,8 +142,8 @@ def test_file_already_exists_no_user_data(mocker): assert not utils.file_already_exists("4aj3sdl5a4k2sjd091u091j") -def test_set_port_for_macos(): +def test_set_port_for_macos(): port = 5000 if sys.platform.lower() in ["darwin", 'linux']: port = 5002 - assert not port == 5000 \ No newline at end of file + assert not port == 5000