Package: pathvar
pathvarVideo Demo:https://youtu.be/THzJUZlqiI0xDescription:My final project forCS50P: "CS50 Introduction to Programming with Python".This tool meant to facilitate the interaction with the system's PATH environment variable (Linux BASH shell only).To get the work done correctly do the following:Read the 'help' instruction wellBe careful about the paths you input (with some options)Separate between multiple paths with a single colon ':'NOTE: This program saves the new modified PATH's value in '/.bash_profile' file,
and if this file not exists creates a new one,
and eventually source the '/.bashrc' and '~/.profile' if any of them exists.Usage:project.py [-h] [-s] [-e] [-a] [-p] [-d] [-q] [--remove-all-paths] [-v]Options:-h, --helpshow this help message and exit-s, --showshows the current value of the 'PATH' (default)-e, --eliminate-duplicateseliminates any duplicates in the value of the 'PATH' (Included with any modifications)-a , --appendappends any number of paths to the current value of the 'PATH' (which are must be given as a
single string separated with ':' between every two paths and without any spaces)-p , --pushpushes any number of paths at the beginning of the current value of 'PATH' (which are must be
given as a single string separated with ':' between every two paths and without any spaces)-d , --deletedeletes from 'PATH' any number of paths (which are must be given as a single string separated
with ':' between every two paths and without any spaces)-q , --querychecks whether the given path is in the current 'PATH'--remove-all-pathsremoves all paths in the current 'PATH' (NOT RECOMMENDED)-v, --versionshow program's version number and exitCode design:The entire program is designed using the Functional Programming Paradigm and all application's logic included in one file: 'project.py'.Code documentation:Contents:pathvar.project moduleadd_args()get_path()is_there_path()main()parse_args_and_modify_path_str()path_duplicates_eliminator()path_remover()print_msg()run_command_verbosely()update_path()pathvar.project modulepathvar.project.add_args(parser_obj: ArgumentParser)Adding CL arguments to and ArgumentParser objectManipulate the inputted ArgumentParser object
by adding the needed command line arguments to it
with all the specifications for each of the arguments
(i.e. argument name, action, help, …).Parametersparser_obj(argparse.ArgumentParser) – parser object for parsing the command line argumentsReturnsNoneReturn typeNonepathvar.project.get_path()A simple function to get the current PATHGet the current PATH environment variable
using the command meant for that
depending on the kind of the operating system that pathvar running on.ReturnsThe value of the PATH variableReturn typestrpathvar.project.is_there_path(current_path: str, given_path: str)Check whether the ‘given_path’ is in ‘current_path’Return True if the ‘given_path’ is in ‘current_path’
Otherwise, return false.Parameterscurrent_path(str) – The value inside the PATH environment variablegiven_paths(str) – The paths that the user want it to be deletedReturnsTrue/False, based on whether the ‘given_path’ is in ‘current_path’Return typeboolpathvar.project.main()pathvar main functionThe Logic of the entire ‘pathvar’ program.ReturnsNothing, just execute the logic of the entire program.Return typeNonepathvar.project.parse_args_and_modify_path_str(parser_obj: ArgumentParser, current_path: str)Parsing the command line argumentsUsing ‘argparse’ library this function will consume an ‘ArgumentParser’ object
in order to parse the arguments and handle the chosen option/s.Parametersparser_obj(argparse.ArgumentParser) – parser object for parsing the command line argumentsReturnsNoneReturn typeNonepathvar.project.path_duplicates_eliminator(s: str)Remove any duplicates in a PATH variableThis function removes any duplicated paths from a PATH variable.
It looks for duplicated paths.Parameterss(str) – The value of the PATH environment variableReturnsThe same input of the PATH value without any duplicatesReturn typestrpathvar.project.path_remover(current_path: str, given_paths: str)Delete the given path/s from the current PATHreturn copy of the ‘current_path’
without and value included in the ‘given_paths’Parameterscurrent_path(str) – The value inside the PATH environment variablegiven_paths(str) – The paths that the user want it to be deletedReturnsA copy from the current path without any given pathReturn typestrpathvar.project.print_msg(title: str, msg: str)Print message to the userThis function will print a message to the user
in form of message title and message bodyParameterstitle(str) – The title of the messagemsg(str) – The body of the messageReturnsNothing, just the print side effectReturn typeNonepathvar.project.run_command_verbosely(cmd: str)Run a given command in subprocessRun the given command in subprocess
and print and ‘stdout’ or ‘stderr’Parameterscmd(str) – Command to runpathvar.project.update_path(new_path_value: str)Run a command to update the PATH variableRun the needed commands for updating the PATH environment variable
based on the current operating system and print any ‘stdout’ or ‘stderr’Parametersnew_path_value(str) – The new value in order to set the PATH variable to itLicense:Copyright (c) 2023 Hussein Mahmoud Kandil - MIT