diff --git a/mediacurator/library/tools.py b/mediacurator/library/tools.py index 4c25705..f355378 100644 --- a/mediacurator/library/tools.py +++ b/mediacurator/library/tools.py @@ -5,12 +5,20 @@ import subprocess import os +import sys import colorama colorama.init() def load_arguments(): + '''Get/load command parameters + + Args: + + Returns: + arguments: A dictionary of lists of the options passed by the user + ''' arguments = { "directories":list(), "files":list(), @@ -44,7 +52,14 @@ def load_arguments(): def detect_ffmpeg(): - '''Returns the version of ffmpeg that is installed or false''' + '''Returns the version of ffmpeg that is installed or false + + Args: + + Returns: + String : The version number of the installed FFMPEG + False : The failure of retreiving the version number + ''' try: txt = subprocess.check_output(['ffmpeg', '-version'], stderr=subprocess.STDOUT).decode() if "ffmpeg version" in txt: @@ -55,7 +70,14 @@ def detect_ffmpeg(): return False def user_confirm(question, color=False): - '''Returns the user answer to a yes or no question''' + '''Returns the user answer to a yes or no question + + Args: + question : A String containing the user question + color : A String containing the prefered color for a question (reg/yellow) + Returns: + Bool : Positive or negative return to the user question + ''' if color == "yellow": print(f"{colorama.Fore.YELLOW}{question} {colorama.Fore.RESET}", end = '') answer = input() @@ -71,19 +93,33 @@ def user_confirm(question, color=False): print("Please answer with yes (Y) or no (N)...") return user_confirm(question) -def deletefile(filename): - '''Delete a file, Returns a boolean''' +def deletefile(filepath): + '''Delete a file, Returns a boolean + + Args: + filepath : A string containing the full filepath + Returns: + Bool : The success of the operation + ''' try: - os.remove(filename) + os.remove(filepath) except OSError: - print(f"{colorama.Fore.RED}Error deleting {filename}{colorama.Fore.RESET}") + print(f"{colorama.Fore.RED}Error deleting {filepath}{colorama.Fore.RESET}") return False - print(f"{colorama.Fore.GREEN}Successfully deleted {filename}{colorama.Fore.RESET}") + print(f"{colorama.Fore.GREEN}Successfully deleted {filepath}{colorama.Fore.RESET}") return True def findfreename(filepath, attempt = 0): - '''Delete a file, Returns a boolean''' + ''' Given a filepath it will try to find a free filename by appending to the name. + First trying as passed in argument, then adding [HEVC] to the end and if all fail [HEVC](#). + + Args: + filepath : A string containing the full filepath + attempt : The number of times we have already tryed + Returns: + filepath : The first free filepath we found + ''' attempt += 1 @@ -93,9 +129,9 @@ def findfreename(filepath, attempt = 0): hevcpath = filename + "[HEVC]" + extension copynumpath = filename + f"[HEVC]({attempt})" + extension - if not os.path.exists(filepath): + if not os.path.exists(filepath) and attempt <= 2: return filepath - elif not os.path.exists(hevcpath): + elif not os.path.exists(hevcpath) and attempt <= 2: return hevcpath elif not os.path.exists(copynumpath): return copynumpath diff --git a/mediacurator/mediacurator.py b/mediacurator/mediacurator.py index 7898066..be64519 100755 --- a/mediacurator/mediacurator.py +++ b/mediacurator/mediacurator.py @@ -29,6 +29,10 @@ colorama.init() def main(): ''' MediaCurator's main function + + Args: + + Returns: ''' print(f"{colorama.Style.BRIGHT}")