poikilos
2 years ago
27 changed files with 1532 additions and 1169 deletions
@ -1,144 +1,154 @@ |
|||||
#!/usr/bin/env python3 |
#!/usr/bin/env python3 |
||||
import os |
import os |
||||
import shutil |
import shutil |
||||
|
import sys |
||||
actions = {"-- Up-to-date: ": "move", "-- Installing: ": "move"} |
actions = {"-- Up-to-date: ": "move", "-- Installing: ": "move"} |
||||
changes = { |
changes = { |
||||
"/usr/local/./": "/usr/local/share/minetest/" |
"/usr/local/./": "/usr/local/share/minetest/" |
||||
} |
} |
||||
count = 0 |
|
||||
command_count = 0 |
|
||||
in_path = "bad_mt5_make_install_output.txt" |
def main(): |
||||
outs_path = os.path.dirname(os.path.realpath(__file__)) |
count = 0 |
||||
out_path = os.path.join(outs_path, "install-fix-minetest5-share.sh") |
command_count = 0 |
||||
file_commands = [] |
in_path = "bad_mt5_make_install_output.txt" |
||||
rmd_cmds = [] |
outs_path = os.path.dirname(os.path.realpath(__file__)) |
||||
mkdir_commands = [] |
out_path = os.path.join(outs_path, "install-fix-minetest5-share.sh") |
||||
made_dirs = [] |
file_commands = [] |
||||
mtg_mod_dirs = ["games//minetest_game/mods", "games/minetest_game/mods"] |
rmd_cmds = [] |
||||
with open(in_path) as ins: |
mkdir_commands = [] |
||||
with open(out_path, 'w') as outs: |
made_dirs = [] |
||||
outs.write("#!/bin/sh\n") |
mtg_mod_dirs = ["games//minetest_game/mods", "games/minetest_game/mods"] |
||||
count += 1 |
with open(in_path) as ins: |
||||
for line_orig in ins: |
with open(out_path, 'w') as outs: |
||||
line = line_orig.strip() |
outs.write("#!/bin/sh\n") |
||||
action = None |
count += 1 |
||||
old_path = None |
for line_orig in ins: |
||||
for k, try_action in actions.items(): |
line = line_orig.strip() |
||||
if line.startswith(k): |
action = None |
||||
action = try_action |
old_path = None |
||||
old_path = line[len(k):].strip() |
for k, try_action in actions.items(): |
||||
break |
if line.startswith(k): |
||||
if action == "move": |
action = try_action |
||||
found = None |
old_path = line[len(k):].strip() |
||||
for old, new in changes.items(): |
break |
||||
if old_path.startswith(old): |
if action == "move": |
||||
found = old |
found = None |
||||
new_path = new + old_path[len(old):] |
for old, new in changes.items(): |
||||
if not os.path.exists(old_path): |
if old_path.startswith(old): |
||||
if not os.path.exists(new_path): |
found = old |
||||
# raise ValueError( |
new_path = new + old_path[len(old):] |
||||
# "The program is not installed" |
if not os.path.exists(old_path): |
||||
# " (missing '{}')".format(old_path) |
if not os.path.exists(new_path): |
||||
# ) |
# raise ValueError( |
||||
outs.write( |
# "The program is not installed" |
||||
'# WARNING: expected "{}" (there is' |
# " (missing '{}')".format(old_path) |
||||
' no destination "{}" either)' |
# ) |
||||
''.format(old_path, new_path) |
outs.write( |
||||
) |
'# WARNING: expected "{}" (there is' |
||||
else: |
' no destination "{}" either)' |
||||
outs.write( |
''.format(old_path, new_path) |
||||
'# Already moved (no source "{}"' |
|
||||
' for destination "{}")' |
|
||||
''.format(old_path, new_path) |
|
||||
) |
|
||||
else: |
|
||||
if os.path.isfile(old_path): |
|
||||
parent = os.path.split(new_path)[0] |
|
||||
if parent not in made_dirs: |
|
||||
made_dirs.append(parent) |
|
||||
cmd = 'mkdir -p "{}"'.format( |
|
||||
parent.replace("//", "/") |
|
||||
) |
) |
||||
mkdir_commands.append(cmd) |
else: |
||||
# AFTER all directories BEFORE all files |
outs.write( |
||||
options = "" |
'# Already moved (no source "{}"' |
||||
if os.path.isfile(new_path): |
' for destination "{}")' |
||||
options = "-f" |
''.format(old_path, new_path) |
||||
if len(options) > 0: |
|
||||
options = " " + options.strip() |
|
||||
cmd = ( |
|
||||
'mv' + options |
|
||||
+ ' "{}" "{}"'.format( |
|
||||
old_path.replace("//", "/"), |
|
||||
new_path.replace("//", "/") |
|
||||
) |
) |
||||
) |
|
||||
# outs.write(cmd + "\n") |
|
||||
# AFTER all directories |
|
||||
file_commands.append(cmd) |
|
||||
else: |
else: |
||||
# old_path == old_path.replace("//","/") |
if os.path.isfile(old_path): |
||||
# Manually fix: |
parent = os.path.split(new_path)[0] |
||||
|
if parent not in made_dirs: |
||||
|
made_dirs.append(parent) |
||||
|
cmd = 'mkdir -p "{}"'.format( |
||||
|
parent.replace("//", "/") |
||||
|
) |
||||
|
mkdir_commands.append(cmd) |
||||
|
# AFTER all directories BEFORE all files |
||||
|
options = "" |
||||
|
if os.path.isfile(new_path): |
||||
|
options = "-f" |
||||
|
if len(options) > 0: |
||||
|
options = " " + options.strip() |
||||
|
cmd = ( |
||||
|
'mv' + options |
||||
|
+ ' "{}" "{}"'.format( |
||||
|
old_path.replace("//", "/"), |
||||
|
new_path.replace("//", "/") |
||||
|
) |
||||
|
) |
||||
|
# outs.write(cmd + "\n") |
||||
|
# AFTER all directories |
||||
|
file_commands.append(cmd) |
||||
|
else: |
||||
|
# old_path == old_path.replace("//","/") |
||||
|
# Manually fix: |
||||
|
|
||||
# rmdir: failed to remove '/usr/local/ |
# rmdir: failed to remove '/usr/local/ |
||||
# ./games//minetest_game/mods': |
# ./games//minetest_game/mods': |
||||
# Directory not empty |
# Directory not empty |
||||
|
|
||||
# rmdir: failed to remove '/usr/local/ |
# rmdir: failed to remove '/usr/local/ |
||||
# ./games//minetest_game': |
# ./games//minetest_game': |
||||
# Directory not empty |
# Directory not empty |
||||
|
|
||||
# due to /usr/local/./games// |
# due to /usr/local/./games// |
||||
# minetest_game/mods/game_commands: |
# minetest_game/mods/game_commands: |
||||
orphan_mods = ["game_commands"] |
orphan_mods = ["game_commands"] |
||||
removed_orphan_mods = [] |
removed_orphan_mods = [] |
||||
|
|
||||
for mod_rel in orphan_mods: |
for mod_rel in orphan_mods: |
||||
for mtg_rel in mtg_mod_dirs: |
for mtg_rel in mtg_mod_dirs: |
||||
f_rel = found + mtg_rel |
f_rel = found + mtg_rel |
||||
# such as ("/usr/local/./" |
# such as ("/usr/local/./" |
||||
# + "games//minetest_game/mods") |
# + "games//minetest_game/mods") |
||||
if old_path.startswith(f_rel): |
if old_path.startswith(f_rel): |
||||
# if mod_rel not in |
# if mod_rel not in |
||||
# removed_orphan_mods: |
# removed_orphan_mods: |
||||
try_path = (found + mtg_rel |
try_path = (found + mtg_rel |
||||
+ "/" + mod_rel) |
+ "/" + mod_rel) |
||||
if os.path.isdir(try_path): |
if os.path.isdir(try_path): |
||||
cmd = ( |
cmd = ( |
||||
'rmdir "{}"'.format( |
'rmdir "{}"'.format( |
||||
try_path |
try_path |
||||
|
) |
||||
) |
) |
||||
) |
# queue for last stage: |
||||
# queue for last stage: |
if cmd not in rmd_cmds: |
||||
if cmd not in rmd_cmds: |
rmd_cmds.append(cmd) |
||||
rmd_cmds.append(cmd) |
# removed_orphan_mods. |
||||
# removed_orphan_mods. |
# append(mod_rel) |
||||
# append(mod_rel) |
break |
||||
break |
|
||||
|
|
||||
cmd = 'rmdir "{}"'.format(old_path) |
cmd = 'rmdir "{}"'.format(old_path) |
||||
rmd_cmds.append(cmd) # AFTER everything |
rmd_cmds.append(cmd) # AFTER everything |
||||
break |
break |
||||
if found is None: |
if found is None: |
||||
outs.write("# WARNING: The destination path is" |
outs.write("# WARNING: The destination path is" |
||||
" unknown: ") |
" unknown: ") |
||||
outs.write('# mv "{}" "{}"'.format(old_path, |
outs.write('# mv "{}" "{}"'.format(old_path, |
||||
old_path)) |
old_path)) |
||||
else: |
else: |
||||
outs.write("# " + line + "\n") |
outs.write("# " + line + "\n") |
||||
|
count += 1 |
||||
|
for cmd in sorted(mkdir_commands, key=len): |
||||
|
outs.write(cmd + "\n") |
||||
count += 1 |
count += 1 |
||||
for cmd in sorted(mkdir_commands, key=len): |
command_count += 1 |
||||
outs.write(cmd + "\n") |
for cmd in file_commands: |
||||
count += 1 |
outs.write(cmd + "\n") |
||||
command_count += 1 |
count += 1 |
||||
for cmd in file_commands: |
command_count += 1 |
||||
outs.write(cmd + "\n") |
for cmd in sorted(rmd_cmds, key=len, reverse=True): |
||||
count += 1 |
outs.write(cmd + "\n") |
||||
command_count += 1 |
count += 1 |
||||
for cmd in sorted(rmd_cmds, key=len, reverse=True): |
command_count += 1 |
||||
outs.write(cmd + "\n") |
|
||||
count += 1 |
print('Added {} line(s) to "{}" (including {} command(s))' |
||||
command_count += 1 |
''.format(count, out_path, command_count)) |
||||
|
|
||||
|
return 0 |
||||
|
|
||||
|
|
||||
print('Added {} line(s) to "{}" (including {} command(s))' |
if __name__ == "__main__": |
||||
''.format(count, out_path, command_count)) |
sys.exit(main()) |
||||
|
@ -0,0 +1,103 @@ |
|||||
|
#!/usr/bin/env python |
||||
|
''' |
||||
|
This module assists with building games from other games, mods, and |
||||
|
patches. |
||||
|
''' |
||||
|
from __future__ import print_function |
||||
|
|
||||
|
import sys |
||||
|
import platform |
||||
|
import os |
||||
|
|
||||
|
profile = None |
||||
|
if platform.system() == "Windows": |
||||
|
profile = os.environ.get('USERPROFILE') |
||||
|
else: |
||||
|
profile = os.environ.get('HOME') |
||||
|
|
||||
|
verbosity = 0 |
||||
|
max_verbosity = 2 |
||||
|
|
||||
|
|
||||
|
def echo0(*args, **kwargs): |
||||
|
print(*args, file=sys.stderr, **kwargs) |
||||
|
|
||||
|
|
||||
|
def echo1(*args, **kwargs): |
||||
|
if verbosity < 1: |
||||
|
return False |
||||
|
print(*args, file=sys.stderr, **kwargs) |
||||
|
return True |
||||
|
|
||||
|
|
||||
|
def echo2(*args, **kwargs): |
||||
|
if verbosity < 2: |
||||
|
return False |
||||
|
print(*args, file=sys.stderr, **kwargs) |
||||
|
return True |
||||
|
|
||||
|
|
||||
|
def get_verbosity(): |
||||
|
return verbosity |
||||
|
|
||||
|
|
||||
|
def set_verbosity(level): |
||||
|
if level is True: |
||||
|
verbosity = 1 |
||||
|
elif level is False: |
||||
|
verbosity = 0 |
||||
|
elif level in range(max_verbosity+1): |
||||
|
verbosity = level |
||||
|
raise ValueError( |
||||
|
"verbosity must be {} at maximum.".format(max_verbosity) |
||||
|
) |
||||
|
|
||||
|
|
||||
|
try: |
||||
|
import mtanalyze |
||||
|
except ModuleNotFoundError as ex: |
||||
|
# tryMTA = os.path.join(profile, "git", "mtanalyze") |
||||
|
moduleDir = os.path.dirname(os.path.realpath(__file__)) |
||||
|
REPO_DIR = os.path.dirname(moduleDir) |
||||
|
modulesDir = os.path.dirname(REPO_DIR) |
||||
|
echo0("* looking for mtanalyze in modulesDir \"{}\"" |
||||
|
"".format(modulesDir)) |
||||
|
tryMTA = os.path.abspath(os.path.join(modulesDir, "mtanalyze")) |
||||
|
if os.path.isdir(tryMTA): |
||||
|
sys.path.append(tryMTA) |
||||
|
import mtanalyze |
||||
|
# ^ import mtanalyze/mtanalyze purposely since the main |
||||
|
# mtanalyze/ directory is a setuptools package not a module. |
||||
|
else: |
||||
|
echo0("") |
||||
|
echo0("You must install mtanalyze alongside") |
||||
|
echo0("EnlivenMinetest such that ../mtanalize/mtanalize exists") |
||||
|
echo0("such as via:") |
||||
|
echo0(" git clone https://github.com/poikilos/mtanalyze {}" |
||||
|
"".format(tryMTA)) |
||||
|
echo0("") |
||||
|
# raise tryMTA |
||||
|
exit(1) |
||||
|
|
||||
|
# from mtanalyze import profile_path |
||||
|
MY_MODULE_DIR = os.path.dirname(os.path.realpath(__file__)) |
||||
|
# ^ realpath follows symlinks |
||||
|
REPO_DIR = os.path.dirname(MY_MODULE_DIR) |
||||
|
MODS_STOPGAP_DIR = os.path.join(REPO_DIR, "patches", "mods-stopgap") |
||||
|
if not os.path.isdir(MODS_STOPGAP_DIR): |
||||
|
echo0("Error: \"{}\" is missing.".format(MODS_STOPGAP_DIR)) |
||||
|
exit(1) |
||||
|
BASE_DIR = os.path.join(REPO_DIR, "Bucket_Game-base") |
||||
|
if not os.path.isdir(BASE_DIR): |
||||
|
echo0("Error: \"{}\" is missing.".format(BASE_DIR)) |
||||
|
exit(1) |
||||
|
BRANCHES_DIR = os.path.join(REPO_DIR, "Bucket_Game-branches") |
||||
|
if not os.path.isdir(BRANCHES_DIR): |
||||
|
echo0("Error: \"{}\" is missing.".format(BRANCHES_DIR)) |
||||
|
exit(1) |
||||
|
|
||||
|
# NOTE: get a git repo's origin via: git remote show origin |
||||
|
|
||||
|
|
||||
|
def getSGPath(stopgap_mod_name): |
||||
|
return os.path.join(MODS_STOPGAP_DIR, stopgap_mod_name) |
@ -0,0 +1,77 @@ |
|||||
|
#!/usr/bin/env python |
||||
|
import setuptools |
||||
|
import sys |
||||
|
import os |
||||
|
# - For the example on which this was based, see |
||||
|
# https://github.com/poikilos/linux-preinstall/blob/main/setup.py |
||||
|
# which is based on |
||||
|
# https://github.com/poikilos/world_clock/blob/main/setup.py |
||||
|
# which is based on |
||||
|
# https://github.com/poikilos/nopackage/blob/main/setup.py |
||||
|
# which is based on |
||||
|
# https://github.com/poikilos/pypicolcd/blob/master/setup.py |
||||
|
# - For nose, see https://github.com/poikilos/mgep/blob/master/setup.py |
||||
|
|
||||
|
# python_mr = sys.version_info.major |
||||
|
# versionedModule = {} |
||||
|
# versionedModule['urllib'] = 'urllib' |
||||
|
# if python_mr == 2: |
||||
|
# versionedModule['urllib'] = 'urllib2' |
||||
|
|
||||
|
install_requires = [] |
||||
|
|
||||
|
if os.path.isfile("requirements.txt"): |
||||
|
with open("requirements.txt", "r") as ins: |
||||
|
for rawL in ins: |
||||
|
line = rawL.strip() |
||||
|
if len(line) < 1: |
||||
|
continue |
||||
|
install_requires.append(line) |
||||
|
|
||||
|
description = '''Manage Minetest using Python.''' |
||||
|
long_description = description |
||||
|
if os.path.isfile("readme.md"): |
||||
|
with open("readme.md", "r") as fh: |
||||
|
long_description = fh.read() |
||||
|
|
||||
|
setuptools.setup( |
||||
|
name='pyenliven', |
||||
|
version='0.3.0', |
||||
|
description=description, |
||||
|
long_description=long_description, |
||||
|
long_description_content_type="text/markdown", |
||||
|
classifiers=[ |
||||
|
'Development Status :: 3 - Alpha', |
||||
|
'Programming Language :: Python :: 3', |
||||
|
('License :: OSI Approved ::' |
||||
|
' GNU General Public License v2 or later (GPLv2+)'), |
||||
|
'Operating System :: POSIX :: Linux', |
||||
|
'Topic :: Software Development :: Version Control', |
||||
|
], |
||||
|
keywords=('minetest repo management commit data analyzer' |
||||
|
' meld merge compare files diff'), |
||||
|
url="https://github.com/poikilos/EnlivenMinetest", |
||||
|
author="Jake Gustafson", |
||||
|
author_email='7557867+poikilos@users.noreply.github.com', |
||||
|
license='GPLv2.1', |
||||
|
# packages=setuptools.find_packages(), |
||||
|
packages=['pyenliven'], |
||||
|
# include_package_data=True, # look for MANIFEST.in |
||||
|
# scripts=['example'] , |
||||
|
# See <https://stackoverflow.com/questions/27784271/ |
||||
|
# how-can-i-use-setuptools-to-generate-a-console-scripts-entry- |
||||
|
# point-which-calls> |
||||
|
entry_points={ |
||||
|
'console_scripts': [ |
||||
|
'compatiblizemod=pyenliven.compatiblizemod:main', |
||||
|
], |
||||
|
}, |
||||
|
install_requires=install_requires, |
||||
|
# versionedModule['urllib'], |
||||
|
# ^ "ERROR: Could not find a version that satisfies the requirement |
||||
|
# urllib (from nopackage) (from versions: none) |
||||
|
# ERROR: No matching distribution found for urllib" |
||||
|
test_suite='nose.collector', |
||||
|
tests_require=['nose', 'nose-cover3'], |
||||
|
zip_safe=False, # It can't run zipped due to needing data files. |
||||
|
) |
@ -1,183 +1,194 @@ |
|||||
#!/usr/bin/env python3 |
#!/usr/bin/env python3 |
||||
import os |
import os |
||||
|
import sys |
||||
import platform |
import platform |
||||
CMD_REM = "#" |
|
||||
CMD_RM = "rm " |
|
||||
CMD_RMDIR = "rmdir " |
|
||||
if platform.system() == "Windows": |
|
||||
CMD_REM = "REM " |
|
||||
CMD_RM = "del " |
|
||||
CMD_RMDIR = "rd " |
|
||||
|
|
||||
# profile_path = None |
def main(): |
||||
# if 'HOME' in os.environ: |
CMD_REM = "#" |
||||
# profile_path = os.environ['HOME'] |
CMD_RM = "rm " |
||||
# elif 'USERPROFILE' in os.environ: |
CMD_RMDIR = "rmdir " |
||||
# profile_path = os.environ['USERPROFILE'] |
if platform.system() == "Windows": |
||||
# downloads_path = os.path.join(profile_path, "Downloads") |
CMD_REM = "REM " |
||||
# repo_path = os.path.join(downloads_path, "minetest") |
CMD_RM = "del " |
||||
# if not os.path.isdir(repo_path): |
CMD_RMDIR = "rd " |
||||
# repo_path = os.path.join(profile_path, "minetest") |
|
||||
# if not os.path.isdir(repo_path): |
# profile_path = None |
||||
# print("ERROR: Nothing done since there is no minetest sourcecode" |
# if 'HOME' in os.environ: |
||||
# " folder in " + downloads_path |
# profile_path = os.environ['HOME'] |
||||
# + " (nor " + profile_path + ")") |
# elif 'USERPROFILE' in os.environ: |
||||
# exit(1) |
# profile_path = os.environ['USERPROFILE'] |
||||
install_manifest_name = "install_manifest.txt" |
# downloads_path = os.path.join(profile_path, "Downloads") |
||||
# install_manifest_path = os.path.join(repo_path, install_manifest_name) |
# repo_path = os.path.join(downloads_path, "minetest") |
||||
# if not os.path.isfile(install_manifest_path): |
# if not os.path.isdir(repo_path): |
||||
# print("ERROR: nothing done since there is no " + |
# repo_path = os.path.join(profile_path, "minetest") |
||||
# install_manifest_name + " in '" + repo_path + |
# if not os.path.isdir(repo_path): |
||||
# "'. The file would only be present if you " + |
# print("ERROR: Nothing done since there is no minetest sourcecode" |
||||
# "installed minetest from sourcecode" + |
# " folder in " + downloads_path |
||||
# "(otherwise this uninstaller is not for you).") |
# + " (nor " + profile_path + ")") |
||||
# exit(2) |
# return 1 |
||||
if not os.path.isfile(install_manifest_name): |
install_manifest_name = "install_manifest.txt" |
||||
print("ERROR: nothing done since there is no " + |
# install_manifest_path = os.path.join(repo_path, install_manifest_name) |
||||
install_manifest_name + " in the current " + |
# if not os.path.isfile(install_manifest_path): |
||||
"directory. You must run: ") |
# print("ERROR: nothing done since there is no " + |
||||
print(" sudo python3 "+os.path.abspath(__file__)) |
# install_manifest_name + " in '" + repo_path + |
||||
print("from the minetest sourcecode (repo) directory.") |
# "'. The file would only be present if you " + |
||||
exit(2) |
# "installed minetest from sourcecode" + |
||||
directories = [] |
# "(otherwise this uninstaller is not for you).") |
||||
print("Removing files...") |
# return 2 |
||||
f_removed_count = 0 |
if not os.path.isfile(install_manifest_name): |
||||
f_skipped_count = 0 |
print("ERROR: nothing done since there is no " + |
||||
f_failed_count = 0 |
install_manifest_name + " in the current " + |
||||
retry_lines = [] |
"directory. You must run: ") |
||||
with open(install_manifest_name, 'r') as ins: |
print(" sudo python3 "+os.path.abspath(__file__)) |
||||
original_line = True |
print("from the minetest sourcecode (repo) directory.") |
||||
while original_line: |
return 2 |
||||
original_line = ins.readline() |
directories = [] |
||||
if original_line: |
print("Removing files...") |
||||
line = original_line.rstrip() # remove trailing newline |
f_removed_count = 0 |
||||
if len(line) > 0: |
f_skipped_count = 0 |
||||
d_path = os.path.dirname(line) |
f_failed_count = 0 |
||||
if d_path not in directories: |
retry_lines = [] |
||||
if "minetest" in d_path: |
with open(install_manifest_name, 'r') as ins: |
||||
directories.append(d_path) |
original_line = True |
||||
# else must be a system directory like |
while original_line: |
||||
# /usr/local/share/applications |
original_line = ins.readline() |
||||
if os.path.isfile(line): |
if original_line: |
||||
os.remove(line) |
line = original_line.rstrip() # remove trailing newline |
||||
|
if len(line) > 0: |
||||
|
d_path = os.path.dirname(line) |
||||
|
if d_path not in directories: |
||||
|
if "minetest" in d_path: |
||||
|
directories.append(d_path) |
||||
|
# else must be a system directory like |
||||
|
# /usr/local/share/applications |
||||
if os.path.isfile(line): |
if os.path.isfile(line): |
||||
f_failed_count += 1 |
os.remove(line) |
||||
retry_lines.append(CMD_RM+'"'+line+'"') |
if os.path.isfile(line): |
||||
|
f_failed_count += 1 |
||||
|
retry_lines.append(CMD_RM+'"'+line+'"') |
||||
|
else: |
||||
|
f_removed_count += 1 |
||||
else: |
else: |
||||
f_removed_count += 1 |
f_skipped_count += 1 |
||||
else: |
|
||||
f_skipped_count += 1 |
|
||||
|
|
||||
print("Removed " + str(f_removed_count) + " file(s) (skipped not" |
print("Removed " + str(f_removed_count) + " file(s) (skipped not" |
||||
" present:" + str(f_skipped_count) + "; failed:" |
" present:" + str(f_skipped_count) + "; failed:" |
||||
+ str(f_failed_count) + ")") |
+ str(f_failed_count) + ")") |
||||
|
|
||||
# NOTE: the next line makes ASCENDING (by len) list of TUPLES (name,len) |
# NOTE: the next line makes ASCENDING (by len) list of TUPLES (name,len) |
||||
sorted_directories = [ |
sorted_directories = [ |
||||
(x, len(x)) for x in sorted(directories, key=len) |
(x, len(x)) for x in sorted(directories, key=len) |
||||
] |
] |
||||
|
|
||||
print("Removing folders...") |
print("Removing folders...") |
||||
# NOTE: they are sorted ASCENDING so start at end: |
# NOTE: they are sorted ASCENDING so start at end: |
||||
d_removed_count = 0 |
d_removed_count = 0 |
||||
d_skipped_count = 0 |
d_skipped_count = 0 |
||||
d_failed_count = 0 |
d_failed_count = 0 |
||||
|
|
||||
# still leaves: |
# still leaves: |
||||
# /usr/local/share/minetest/games/minetest_game/mods |
# /usr/local/share/minetest/games/minetest_game/mods |
||||
# /usr/local/share/minetest/textures/base/pack/: |
# /usr/local/share/minetest/textures/base/pack/: |
||||
# down_arrow.png left_arrow.png right_arrow.png up_arrow.png |
# down_arrow.png left_arrow.png right_arrow.png up_arrow.png |
||||
# /usr/local/share/minetest/games/minimal/mods |
# /usr/local/share/minetest/games/minimal/mods |
||||
# so: |
# so: |
||||
try_files = ["depends.txt", "down_arrow.png", "left_arrow.png", |
try_files = ["depends.txt", "down_arrow.png", "left_arrow.png", |
||||
"right_arrow.png", "up_arrow.png"] |
"right_arrow.png", "up_arrow.png"] |
||||
try_dirs = ["mods"] |
try_dirs = ["mods"] |
||||
|
|
||||
extra_dirs = [] |
extra_dirs = [] |
||||
ed_failed_count = 0 |
ed_failed_count = 0 |
||||
ed_removed_count = 0 |
ed_removed_count = 0 |
||||
extra_files = [] |
extra_files = [] |
||||
e_failed_count = 0 |
e_failed_count = 0 |
||||
e_removed_count = 0 |
e_removed_count = 0 |
||||
for i in reversed(range(len(sorted_directories))): |
for i in reversed(range(len(sorted_directories))): |
||||
d_path = sorted_directories[i][0] |
d_path = sorted_directories[i][0] |
||||
# for d in reversed(sorted_directories): |
# for d in reversed(sorted_directories): |
||||
# d_path = d[0] |
# d_path = d[0] |
||||
# print("checking "+str(d_path)) |
# print("checking "+str(d_path)) |
||||
if os.path.isdir(d_path): |
|
||||
try: |
|
||||
for try_name in try_files: |
|
||||
try_path = os.path.join(d_path, try_name) |
|
||||
if os.path.isfile(try_path): |
|
||||
extra_files.append(try_path) |
|
||||
print('Removing known extra file: "' + try_path |
|
||||
+ '"') |
|
||||
try: |
|
||||
os.remove(try_path) |
|
||||
e_removed_count += 1 |
|
||||
except Exception as e: |
|
||||
e_failed_count += 1 |
|
||||
retry_lines.append(CMD_RM + '"' + try_path |
|
||||
+ '"') |
|
||||
print(str(e)) |
|
||||
for try_name in try_dirs: |
|
||||
try_path = os.path.join(d_path, try_name) |
|
||||
if os.path.isdir(try_path): |
|
||||
extra_dirs.append(try_path) |
|
||||
print('Removing known extra folder: "' + try_path |
|
||||
+ '"') |
|
||||
try: |
|
||||
os.rmdir(try_path) |
|
||||
ed_removed_count += 1 |
|
||||
except Exception as e: |
|
||||
ed_failed_count += 1 |
|
||||
retry_lines.append(CMD_RMDIR+'"'+try_path+'"') |
|
||||
print(str(e)) |
|
||||
os.rmdir(d_path) |
|
||||
except Exception as e: |
|
||||
print(str(e)) |
|
||||
if os.path.isdir(d_path): |
if os.path.isdir(d_path): |
||||
d_failed_count += 1 |
try: |
||||
retry_lines.append(CMD_RMDIR+'"'+d_path+'"') |
for try_name in try_files: |
||||
|
try_path = os.path.join(d_path, try_name) |
||||
|
if os.path.isfile(try_path): |
||||
|
extra_files.append(try_path) |
||||
|
print('Removing known extra file: "' + try_path |
||||
|
+ '"') |
||||
|
try: |
||||
|
os.remove(try_path) |
||||
|
e_removed_count += 1 |
||||
|
except Exception as e: |
||||
|
e_failed_count += 1 |
||||
|
retry_lines.append(CMD_RM + '"' + try_path |
||||
|
+ '"') |
||||
|
print(str(e)) |
||||
|
for try_name in try_dirs: |
||||
|
try_path = os.path.join(d_path, try_name) |
||||
|
if os.path.isdir(try_path): |
||||
|
extra_dirs.append(try_path) |
||||
|
print('Removing known extra folder: "' + try_path |
||||
|
+ '"') |
||||
|
try: |
||||
|
os.rmdir(try_path) |
||||
|
ed_removed_count += 1 |
||||
|
except Exception as e: |
||||
|
ed_failed_count += 1 |
||||
|
retry_lines.append(CMD_RMDIR+'"'+try_path+'"') |
||||
|
print(str(e)) |
||||
|
os.rmdir(d_path) |
||||
|
except Exception as e: |
||||
|
print(str(e)) |
||||
|
if os.path.isdir(d_path): |
||||
|
d_failed_count += 1 |
||||
|
retry_lines.append(CMD_RMDIR+'"'+d_path+'"') |
||||
|
else: |
||||
|
d_removed_count += 1 |
||||
else: |
else: |
||||
d_removed_count += 1 |
d_skipped_count += 1 |
||||
else: |
print("Removed " + str(d_removed_count) + " folder(s) (skipped not" |
||||
d_skipped_count += 1 |
" present:" + str(d_skipped_count) + "; failed:" |
||||
print("Removed " + str(d_removed_count) + " folder(s) (skipped not" |
+ str(d_failed_count) + ")") |
||||
" present:" + str(d_skipped_count) + "; failed:" |
if e_failed_count > 0: |
||||
+ str(d_failed_count) + ")") |
print("(failed to remove " + e_failed_count + " known extra file(s)" |
||||
if e_failed_count > 0: |
" (will be shown under FAILURES below)") |
||||
print("(failed to remove " + e_failed_count + " known extra file(s)" |
if ed_failed_count > 0: |
||||
" (will be shown under FAILURES below)") |
print("(failed to remove " + ed_failed_count + " known extra" |
||||
if ed_failed_count > 0: |
" folder(s) (will be shown under FAILURES below)") |
||||
print("(failed to remove " + ed_failed_count + " known extra" |
print("Removed " + str(d_removed_count) + " folder(s) (skipped not" |
||||
" folder(s) (will be shown under FAILURES below)") |
" present:" + |
||||
print("Removed " + str(d_removed_count) + " folder(s) (skipped not" |
str(d_skipped_count) + "; failed:" + str(d_failed_count) + ")") |
||||
" present:" + |
|
||||
str(d_skipped_count) + "; failed:" + str(d_failed_count) + ")") |
|
||||
|
|
||||
if f_failed_count+d_failed_count+ed_failed_count <= 0: |
code = 0 |
||||
print("") |
if f_failed_count+d_failed_count+ed_failed_count <= 0: |
||||
if f_removed_count+d_removed_count <= 0: |
print("") |
||||
print("Nothing to do (minetest+minetestserver has 0 known files" |
if f_removed_count+d_removed_count <= 0: |
||||
" on system--you apparently already uninstalled the local" |
print("Nothing to do (minetest+minetestserver has 0 known files" |
||||
" version that was installed using 'sudo make install')") |
" on system--you apparently already uninstalled the local" |
||||
|
" version that was installed using 'sudo make install')") |
||||
|
else: |
||||
|
print("OK [finished uninstalling all installed files]") |
||||
|
print("") |
||||
else: |
else: |
||||
print("OK [finished uninstalling all installed files]") |
print("") |
||||
print("") |
print("") |
||||
else: |
print(CMD_REM+"FAILURES:") |
||||
print("") |
for rl in retry_lines: |
||||
print("") |
print(rl) |
||||
print(CMD_REM+"FAILURES:") |
print("") |
||||
for rl in retry_lines: |
print("In case of any failures are counted above, " |
||||
print(rl) |
"try running this script with administrative privileges." |
||||
print("") |
"If any more remain, you may have to remove them manually.") |
||||
print("In case of any failures are counted above, " |
print("") |
||||
"try running this script with administrative privileges." |
print("") |
||||
"If any more remain, you may have to remove them manually.") |
code = 1 |
||||
print("") |
if not ins.closed: |
||||
print("") |
print("ERROR: ins was not closed (this should never happen)--" |
||||
if not ins.closed: |
"closing manually...") |
||||
print("ERROR: ins was not closed (this should never happen)--" |
ins.close() |
||||
"closing manually...") |
code = 1 |
||||
ins.close() |
return code |
||||
|
|
||||
|
|
||||
|
if __name__ == "__main__": |
||||
|
sys.exit(main()) |
||||
|
@ -1,117 +1,126 @@ |
|||||
#!/usr/bin/env python |
#!/usr/bin/env python |
||||
import os |
import os |
||||
|
import sys |
||||
import platform |
import platform |
||||
|
|
||||
|
|
||||
def doDie(msg, error_code=1): |
def show_error(msg, error_code=1): |
||||
print() |
print() |
||||
print(msg) |
print(msg) |
||||
print() |
print() |
||||
print() |
print() |
||||
exit(error_code) |
return error_code |
||||
|
|
||||
|
|
||||
rem_cmd = "#" |
def main(): |
||||
rm_cmd = "rm " |
rem_cmd = "#" |
||||
rmdir_cmd = "rmdir " |
rm_cmd = "rm " |
||||
if platform.system() == "Windows": |
rmdir_cmd = "rmdir " |
||||
rm_cmd = "DEL " |
if platform.system() == "Windows": |
||||
rmdir_cmd = "RD " |
rm_cmd = "DEL " |
||||
rem_cmd = "REM " |
rmdir_cmd = "RD " |
||||
profile_path1 = os.environ.get('HOME') |
rem_cmd = "REM " |
||||
profile_path = profile_path1 |
profile_path1 = os.environ.get('HOME') |
||||
profile_path2 = os.environ.get('USERPROFILE') |
profile_path = profile_path1 |
||||
if profile_path2 is not None: |
profile_path2 = os.environ.get('USERPROFILE') |
||||
profile_path = profile_path2 |
if profile_path2 is not None: |
||||
if profile_path1 is not None: |
profile_path = profile_path2 |
||||
print(rem_cmd + "WARNING: HOME is present, but USERPROFILE '" |
if profile_path1 is not None: |
||||
+ profile_path + "' is being used.") |
print(rem_cmd + "WARNING: HOME is present, but USERPROFILE '" |
||||
else: |
+ profile_path + "' is being used.") |
||||
if profile_path1 is None: |
else: |
||||
doDie(rem_cmd + "ERROR: There is nothing to do since neither" |
if profile_path1 is None: |
||||
+ " HOME nor USERPROFILE is present.") |
return show_error(rem_cmd + "ERROR: There is nothing to do" |
||||
|
" since neither" |
||||
mnf_name = "install_manifest.txt" |
" HOME nor USERPROFILE is present.") |
||||
mnf_path = os.path.join(profile_path, mnf_name) |
|
||||
|
mnf_name = "install_manifest.txt" |
||||
unsorted_list = [] |
mnf_path = os.path.join(profile_path, mnf_name) |
||||
|
|
||||
if not os.path.isfile(mnf_path): |
unsorted_list = [] |
||||
doDie(rem_cmd + "Uninstall cannot continue since '" + mnf_path |
|
||||
+ "' is missing.") |
if not os.path.isfile(mnf_path): |
||||
|
return show_error(rem_cmd + "Uninstall cannot continue since '" |
||||
with open(mnf_path) as fp: |
+ mnf_path + "' is missing.") |
||||
for cnt, line_original in enumerate(fp): |
|
||||
# print("Line {}: {}".format(cnt, line)) |
with open(mnf_path) as fp: |
||||
line = line_original.strip() |
for cnt, line_original in enumerate(fp): |
||||
if len(line) > 0: |
# print("Line {}: {}".format(cnt, line)) |
||||
unsorted_list.append(line) |
line = line_original.strip() |
||||
|
if len(line) > 0: |
||||
if len(unsorted_list) < 1: |
unsorted_list.append(line) |
||||
doDie(rem_cmd + "ERROR: There are no files in the manifest '" |
|
||||
+ mnf_path + "'") |
if len(unsorted_list) < 1: |
||||
|
return show_error(rem_cmd + "ERROR: There are no files in the manifest" |
||||
# See https://stackoverflow.com/questions/4659524/\ |
" '"+ mnf_path + "'") |
||||
# how-to-sort-by-length-of-string-followed-by-alphabetical-order |
|
||||
sorted_list = sorted(unsorted_list, key=len, reverse=True) |
# See https://stackoverflow.com/questions/4659524/\ |
||||
# reverse: descending |
# how-to-sort-by-length-of-string-followed-by-alphabetical-order |
||||
# or (also reverse): |
sorted_list = sorted(unsorted_list, key=len, reverse=True) |
||||
# the_list.sort(key=lambda item: (-len(item), item)) |
# reverse: descending |
||||
|
# or (also reverse): |
||||
print(rem_cmd + "Uninstalling...") |
# the_list.sort(key=lambda item: (-len(item), item)) |
||||
not_removed_files = [] |
|
||||
not_removed_dirs = [] |
print(rem_cmd + "Uninstalling...") |
||||
does_not_exist = [] |
not_removed_files = [] |
||||
file_count = 0 |
not_removed_dirs = [] |
||||
dir_count = 0 |
does_not_exist = [] |
||||
for path in sorted_list: |
file_count = 0 |
||||
if os.path.isfile(path): |
dir_count = 0 |
||||
if path[0:1] == ".": |
for path in sorted_list: |
||||
|
if os.path.isfile(path): |
||||
|
if path[0:1] == ".": |
||||
|
print(rm_cmd + "\"" + path + "\"") |
||||
|
not_removed_files.append(path) |
||||
|
continue |
||||
|
try: |
||||
|
os.remove(path) |
||||
|
file_count += 1 |
||||
|
except PermissionError: |
||||
|
not_removed_files.append(path) |
||||
|
elif os.path.isdir(path): |
||||
|
if path[0:1] == ".": |
||||
|
print(rmdir_cmd + "\"" + path + "\"") |
||||
|
not_removed_dirs.append(path) |
||||
|
continue |
||||
|
try: |
||||
|
os.rmdir(path) |
||||
|
dir_count += 1 |
||||
|
except PermissionError: |
||||
|
not_removed_dirs.append(path) |
||||
|
else: |
||||
|
does_not_exist.append(path) |
||||
|
|
||||
|
if len(does_not_exist) > 0: |
||||
|
if len(does_not_exist) == len(sorted_list): |
||||
|
return show_error(rem_cmd + 'The program is not installed such as' |
||||
|
' at "{}".' |
||||
|
''.format(sorted_list[-1])) |
||||
|
|
||||
|
show_dot_warning = True |
||||
|
print(rem_cmd + "Uninstall is complete.") |
||||
|
print(rem_cmd + "- files: " + str(file_count)) |
||||
|
print(rem_cmd + "- directories: " + str(dir_count)) |
||||
|
print(rem_cmd + "- missing: " + len(does_not_exist)) |
||||
|
if (len(not_removed_files) + len(not_removed_dirs)) > 0: |
||||
|
for path in not_removed_files: |
||||
|
if path[0:1] == ".": |
||||
|
if show_dot_warning: |
||||
|
print(rem_cmd + "Paths starting with '.' are not yet" |
||||
|
" implemented.") |
||||
|
show_dot_warning = False |
||||
print(rm_cmd + "\"" + path + "\"") |
print(rm_cmd + "\"" + path + "\"") |
||||
not_removed_files.append(path) |
for path in not_removed_dirs: |
||||
continue |
|
||||
try: |
|
||||
os.remove(path) |
|
||||
file_count += 1 |
|
||||
except PermissionError: |
|
||||
not_removed_files.append(path) |
|
||||
elif os.path.isdir(path): |
|
||||
if path[0:1] == ".": |
|
||||
print(rmdir_cmd + "\"" + path + "\"") |
print(rmdir_cmd + "\"" + path + "\"") |
||||
not_removed_dirs.append(path) |
print(rem_cmd + "Deleting items above FAILED:") |
||||
continue |
print(" " + rem_cmd + "- files: " + str(not_removed_file_count)) |
||||
try: |
print(" " + rem_cmd + "- directories: " |
||||
os.rmdir(path) |
+ str(not_removed_dir_count)) |
||||
dir_count += 1 |
|
||||
except PermissionError: |
print("") |
||||
not_removed_dirs.append(path) |
print("") |
||||
else: |
return 0 |
||||
does_not_exist.append(path) |
|
||||
|
|
||||
if len(does_not_exist) > 0: |
if __name__ == "__main__": |
||||
if len(does_not_exist) == len(sorted_list): |
sys.exit(main()) |
||||
doDie(" " + rem_cmd + " The program is not installed such as" |
|
||||
+ " at '" + sorted_list[-1] + "'.") |
|
||||
|
|
||||
show_dot_warning = True |
|
||||
print(rem_cmd + "Uninstall is complete.") |
|
||||
print(rem_cmd + "- files: " + str(file_count)) |
|
||||
print(rem_cmd + "- directories: " + str(dir_count)) |
|
||||
print(rem_cmd + "- missing: " + len(does_not_exist)) |
|
||||
if (len(not_removed_files) + len(not_removed_dirs)) > 0: |
|
||||
for path in not_removed_files: |
|
||||
if path[0:1] == ".": |
|
||||
if show_dot_warning: |
|
||||
print(rem_cmd + "Paths starting with '.' are not yet" |
|
||||
" implemented.") |
|
||||
show_dot_warning = False |
|
||||
print(rm_cmd + "\"" + path + "\"") |
|
||||
for path in not_removed_dirs: |
|
||||
print(rmdir_cmd + "\"" + path + "\"") |
|
||||
print(rem_cmd + "Deleting items above FAILED:") |
|
||||
print(" " + rem_cmd + "- files: " + str(not_removed_file_count)) |
|
||||
print(" " + rem_cmd + "- directories: " |
|
||||
+ str(not_removed_dir_count)) |
|
||||
|
|
||||
print("") |
|
||||
print("") |
|
||||
|
Loading…
Reference in new issue