Interacting with PATH variable from Linux BASH command line.
Project description
pathvar
Video Demo: https://youtu.be/THzJUZlqiI0x
Description:
My final project for CS50P: "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 well
- Be 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, --help
- show this help message and exit
- -s, --show
- shows the current value of the 'PATH' (default)
- -e, --eliminate-duplicates
- eliminates any duplicates in the value of the 'PATH' (Included with any modifications)
- -a , --append
- appends 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 , --push
- pushes 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 , --delete
- deletes 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 , --query
- checks whether the given path is in the current 'PATH'
- --remove-all-paths
- removes all paths in the current 'PATH' (NOT RECOMMENDED)
- -v, --version
- show program's version number and exit
Code 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 module
pathvar.project.add_args(parser_obj: ArgumentParser)
Adding CL arguments to and ArgumentParser object
Manipulate 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, …).
-
Parameters
parser_obj (argparse.ArgumentParser) – parser object for parsing the command line arguments
-
Returns
None
-
Return type
None
pathvar.project.get_path()
A simple function to get the current PATH
Get the current PATH environment variable using the command meant for that depending on the kind of the operating system that pathvar running on.
-
Returns
The value of the PATH variable
-
Return type
str
pathvar.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.
-
Parameters
-
current_path (str) – The value inside the PATH environment variable
-
given_paths (str) – The paths that the user want it to be deleted
-
-
Returns
True/False, based on whether the ‘given_path’ is in ‘current_path’
-
Return type
bool
pathvar.project.main()
pathvar main function
The Logic of the entire ‘pathvar’ program.
-
Returns
Nothing, just execute the logic of the entire program.
-
Return type
None
pathvar.project.parse_args_and_modify_path_str(parser_obj: ArgumentParser, current_path: str)
Parsing the command line arguments
Using ‘argparse’ library this function will consume an ‘ArgumentParser’ object in order to parse the arguments and handle the chosen option/s.
-
Parameters
parser_obj (argparse.ArgumentParser) – parser object for parsing the command line arguments
-
Returns
None
-
Return type
None
pathvar.project.path_duplicates_eliminator(s: str)
Remove any duplicates in a PATH variable
This function removes any duplicated paths from a PATH variable. It looks for duplicated paths.
-
Parameters
s (str) – The value of the PATH environment variable
-
Returns
The same input of the PATH value without any duplicates
-
Return type
str
pathvar.project.path_remover(current_path: str, given_paths: str)
Delete the given path/s from the current PATH
return copy of the ‘current_path’ without and value included in the ‘given_paths’
-
Parameters
-
current_path (str) – The value inside the PATH environment variable
-
given_paths (str) – The paths that the user want it to be deleted
-
-
Returns
A copy from the current path without any given path
-
Return type
str
pathvar.project.print_msg(title: str, msg: str)
Print message to the user
This function will print a message to the user in form of message title and message body
-
Parameters
-
title (str) – The title of the message
-
msg (str) – The body of the message
-
-
Returns
Nothing, just the print side effect
-
Return type
None
pathvar.project.run_command_verbosely(cmd: str)
Run a given command in subprocess
Run the given command in subprocess and print and ‘stdout’ or ‘stderr’
-
Parameters
cmd (str) – Command to run
pathvar.project.update_path(new_path_value: str)
Run a command to update the PATH variable
Run the needed commands for updating the PATH environment variable based on the current operating system and print any ‘stdout’ or ‘stderr’
-
Parameters
new_path_value (str) – The new value in order to set the PATH variable to it
License:
Copyright (c) 2023 Hussein Mahmoud Kandil - MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pathvar-1.0.1.tar.gz
.
File metadata
- Download URL: pathvar-1.0.1.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 350b6c27779457fda5c2c155c46ac901d26e6a7467854108bda5b0fd0a3c6ac4 |
|
MD5 | e30dd2e73175ede71add9aad17f1422f |
|
BLAKE2b-256 | 780a8b8657030d8b2967b9ca880cd28c2ddccfdcf39c7ed77d24b253a4144e7e |
File details
Details for the file pathvar-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: pathvar-1.0.1-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d8317ba51e654fdd2567e48589780bffb484a92d83a59ade15f96098f1f7105 |
|
MD5 | a23f26a3a4cdf186670bf24808d83f96 |
|
BLAKE2b-256 | bd25a4261395da298b56582c7ac3fd075ee03febfa2517410e539077b021de8f |