The concept (installs discord to ~/.local/bin/)

This commit is contained in:
Madars Batraks 2024-05-12 01:20:31 +03:00
parent eca3d077fe
commit 09133b09f8

74
main.py
View File

@ -3,11 +3,14 @@ import tqdm
import tarfile
import os
import shutil
import getopt
import sys
discordUrl = "https://discord.com/api/download?platform=linux&format=tar.gz"
tmpDir = "/tmp/dup/"
confDir = "~/.config/"
installDir = os.path.expanduser("~") + "/.local/lib/Discord"
execDir = os.path.expanduser("~") + "/.local/bin/Discord"
def download(url: str, dest: str):
with open(tmpDir + dest, 'wb') as f:
@ -26,32 +29,81 @@ def download(url: str, dest: str):
pb.update(len(chunk))
f.write(chunk)
def rm(file):
print("TBA")
def rmdir():
print("TBA")
def mkdir():
print("TBA")
def rm(dir: str):
try:
if os.path.isdir(dir) == True:
shutil.rmtree(dir)
else:
os.remove(dir)
except Exception as err:
print(err)
# def rm(folder: str):
# try:
# shutil.rmtree(folder)
# except Exception as err:
# print(err)
def mkdir(name: str):
try:
os.mkdir(name)
except Exception as err:
print(err)
def installDiscord():
#os.mkdir(tmpDir)
rm(tmpDir)
mkdir(tmpDir)
print("Downloading Discord...")
download(discordUrl, "discord.tar.gz")
print("Extracting..." )
file = tarfile.open(tmpDir+"/discord.tar.gz")
os.mkdir("/tmp/dup/discord")
mkdir("/tmp/dup/discord")
file.extractall(tmpDir+"/discord")
file.close()
print("Installing...")
shutil.rmtree(installDir)
rm(installDir)
shutil.move(tmpDir+"/discord/Discord", installDir)
os.symlink(installDir + "/Discord", execDir)
print("Cleaning up...")
# os.remove(tmpDir+"discord.tar.gz")
shutil.rmtree(tmpDir)
rm(tmpDir)
def uninstall():
rm(installDir)
rm(tmpDir)
rm(confDir)
rm(execDir)
installDiscord()
argumentList = sys.argv[1:]
# Options
options = "hiu"
# Long options
long_options = ["help", "install", "uninstall"]
try:
# Parsing argument
arguments, values = getopt.getopt(argumentList, options, long_options)
# checking each argument
for currentArgument, currentValue in arguments:
if currentArgument in ("-h", "--help"):
print ("Displaying Help")
elif currentArgument in ("-i", "--install"):
installDiscord()
elif currentArgument in ("-u", "--uninstall"):
uninstall()
except getopt.error as err:
# output error, and return with an error code
print (str(err))