54 lines
1.6 KiB
Python
Executable file
54 lines
1.6 KiB
Python
Executable file
#! /usr/bin/python3
|
|
# -*- coding: UTF-8 -*-
|
|
|
|
"""Remove symlinks to the scripts of this project from the computer."""
|
|
|
|
import os
|
|
import os.path
|
|
from constants import (CONFIGFILE, CONFIG_INSTALLDIR,
|
|
CONFIG_SEPARATOR)
|
|
from install import SCRIPTS_TO_INSTALL
|
|
|
|
|
|
def readInstallDirectoriesFromConfig():
|
|
"""Read the config file and find install dirs.
|
|
|
|
Returns:
|
|
a set consisting of the install directories specified in
|
|
the config file. An empty list in case of non-existing config
|
|
file.
|
|
|
|
"""
|
|
try:
|
|
with open(CONFIGFILE, "r") as configfile:
|
|
return {
|
|
line.strip("\n").split(CONFIG_SEPARATOR, maxsplit=1)[1]
|
|
for line in configfile.readlines()
|
|
if line.startswith(CONFIG_INSTALLDIR + CONFIG_SEPARATOR)
|
|
} # set for removind duplicates
|
|
except FileNotFoundError:
|
|
print("Debug: no config file found.")
|
|
return set()
|
|
|
|
|
|
def removeInstallationLinks(where):
|
|
"""Remove all suitable named links to parts of this program.
|
|
|
|
where: where to look for those links.
|
|
|
|
"""
|
|
for link in SCRIPTS_TO_INSTALL:
|
|
try:
|
|
if os.path.islink(os.path.join(where, link)):
|
|
os.remove(os.path.join(where, link))
|
|
except FileNotFoundError:
|
|
# good, already gone
|
|
pass
|
|
except PermissionError:
|
|
print("I could not remove " + os.path.join(where, link)
|
|
+ " due to missing permissions.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
for directory in readInstallDirectoriesFromConfig():
|
|
removeInstallationLinks(directory)
|