Several Updates
Created by: realmelangez
Several Updates
1. Automatically Installing Missing Dependencies
Since the requests
module isn't included in the Python Standard Library but a dependency thereof, I added some lines of code as follows to check whether the user has had requests
installed or not and install it if they hasn't.
required = {'requests'}
installed = {pkg.key for pkg in pkg_resources.working_set}
missing = required - installed
if missing:
python = sys.executable
subprocess.check_call(
[python, '-m', 'pip', 'install', *missing],
stdout=subprocess.DEVNULL
)
2. Supporting Linux-Based Operating Systems
File paths are different between Windows and Linux systems for the former uses backslashes (\) and the latter use forward slashes (/) when displaying them.
Single backslashes are not allowed in python for they might be confused with '\n's or '\t's while forward slashes are allowed for both Windows and Linux systems. Therefore, the simplest way to make the program Linux-supporting is to switch the '\\'s in the original to '/'s as in os.remove(f"{exedir}/{file}")
.
However, considering that the os.path.realpath(sys.argv[0])
function may return a double-backslash-separated file path, I added
if os.name == 'nt':
arg = '\\'
elif os.name == 'posix':
arg = '/'
in front of
exedir = os.path.realpath(sys.argv[0])
dirct = exedir.split(arg)
to make sure the gotten file path is correctly separated and stored into the list dirct
.
At the mean time, some OS commands varies from Windows to Linux, too. (For instance, the command for clearing the terminal window which is used frequently in the program.)
if os.name == 'nt':
os.system('cls')
elif os.name == 'posix':
os.system('clear')
3. Optimized the Coding and Fixed a Hilarious Bug
In the original code, after asking the user to type in, if statements like if inp == 'N' or inp == 'n':
is used to check whether the answer matches the choices. To increase the conciseness and the readability of the code, if inp.lower() == 'n':
would be much better.
What is hilarious is that, after asking the user whether to skip the guide at the first time, the original code regards 'Y' as 'do not skip' and 'N' as 'skip'. 足以说明阿炳事屑(bushi