w.i.p setup.py test

This commit is contained in:
Dpeta 2021-03-24 17:27:09 +01:00
parent f2a4fab1cb
commit 7a75d43f65
6 changed files with 38 additions and 382 deletions

View file

@ -1,283 +0,0 @@
#!/usr/bin/env python
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://sam.zoy.org/wtfpl/COPYING for more details.
import sys, traceback
error = 0
try:
import os, shutil
from stat import *
from string import Template
_PLATFORM = sys.platform
if _PLATFORM in ['win32','cygwin','darwin','os2','os2emx','riscos','atheos']:
print "Whoa there buddy! This installation script isn't meant to be run on your OS."
exit()
if os.getuid() != 0:
print "This program must be run as root (sudo)."
exit()
_HOME = os.environ['HOME']
_USER = os.environ['SUDO_USER']
_UID = int(os.environ['SUDO_UID'])
_GID = int(os.environ['SUDO_GID'])
# fix home if it's root weirdness
if _HOME.find("root") != -1:
_HOME = "/home/"+_USER
def setPermissions(path):
os.chown(path, _UID, _GID)
for file_ in os.listdir(path):
filePath = os.path.join(path,file_)
if os.path.isdir(filePath):
setPermissions(filePath)
else:
os.chown(filePath, _UID, _GID)
def findPesterchum(path):
for f in os.listdir(path):
filePath = os.path.join(path, f)
if os.path.isdir(filePath):
if os.path.exists(filePath+"/pesterchum.py"):
return filePath
else:
a=findPesterchum(filePath)
if a: return a
elif f == "pesterchum.py":
return path
if not os.path.exists(_HOME+"/.pcInstallLoc"):
print "Welcome to the Pesterchum 3.14 Easy Installer (for Linux)!\n\
Created by Kiooeht [evacipatedBox] May 28th-29th, 2011.\n\
License: WTFPL\n\
\n\
Leaving an option blank will accept it's default [in brackets]\n\
Are you ready to begin your MAGICAL JOURNEY?!\n\
Of course you are!!! ::::D"
# ask user about things
while 1:
install = raw_input("Install location [~/.pesterchum]: ")
if install == "":
instLoc = _HOME+"/.pesterchum"
break
else:
if install[0] == "~":
install = _HOME+install[1:]
if os.path.exists(install[:install.rfind("/")]):
instLoc = install
break
print "No can do"
if os.path.exists("/usr/share/applications"):
while 1:
gnome = raw_input("Create a GNOME menu item? [Y/n]: ")
if gnome.lower() == "y" or gnome == "":
gnome = True;break
elif gnome.lower() == "n":
gnome = False;break
else:
print "herpaderp"
while 1:
shortcut = raw_input("Create launcher in home directory? [Y/n]: ")
if shortcut.lower() == "y" or shortcut == "":
shortcut = True;break
elif shortcut.lower() == "n":
shortcut = False;break
else:
print "u jelly?"
# do some shitty install
try:
fileLoc = findPesterchum(".")
except RuntimeError:
print "I'm sorry! I was unable to find the pesterchum files :("
print "Please put them where I can find them"
exit()
if not fileLoc:
print "I'm sorry! I was unable to find the pesterchum files :("
print "Please put them where I can find them"
exit()
print "Copying files..."
ignore = shutil.ignore_patterns('*.pyc')
if not os.path.exists(instLoc):
shutil.copytree(fileLoc, instLoc, ignore=ignore)
if os.path.exists(instLoc+"/pesterchum.js"):
f = open(instLoc+"/pesterchum.js")
js = f.read()
f.close()
defa = js.find("\"defaultprofile\"")
if defa != -1:
start = js.find("\"", js.find(":", defa+1))
end = js.find("\"", start+1)
party = js[start+1:end]
if not os.path.exists(instLoc+"/profiles") or \
party+".js" not in os.listdir(instLoc+"/profiles"):
print "Protecting you from stupidity..."
print " (aka. Deleting reference to non-existant default profile)"
#os.remove(instLoc+"/pesterchum.js")
f = open(instLoc+"/pesterchum.js", "w")
f.write(js[:defa-1]+js[js.find(",", end)+1:])
f.close()
else:
if not os.path.exists(instLoc+"/logs") and os.path.exists(fileLoc+"/logs"):
shutil.copytree(fileLoc+"/logs", instLoc+"/logs", ignore=ignore)
if not os.path.exists(instLoc+"/profiles") and os.path.exists(fileLoc+"/profiles"):
shutil.copytree(fileLoc+"/profiles", instLoc+"/profiles", ignore=ignore)
if not os.path.exists(instLoc+"/pesterchum.js") and os.path.exists(fileLoc+"/pesterchum.js"):
shutil.copy(fileLoc+"/pesterchum.js", instLoc)
shutil.copytree(fileLoc+"/oyoyo", instLoc+"/oyoyo", ignore=ignore)
shutil.copytree(fileLoc+"/smilies", instLoc+"/smilies", ignore=ignore)
shutil.copytree(fileLoc+"/themes", instLoc+"/themes", ignore=ignore)
for f in os.listdir(fileLoc):
filePath = os.path.join(fileLoc, f)
if not os.path.isdir(filePath) and f != "pesterchum.js":
shutil.copy(filePath, instLoc)
setPermissions(instLoc)
# save the install location
f = open(_HOME+"/.pcInstallLoc", "w")
f.write(instLoc)
f.close()
#create a cool executable
print "Creating executable... (/usr/local/bin/pesterchum)"
f = open("/usr/local/bin/pesterchum", 'w')
f.write("#!/bin/sh\ncd "+instLoc+"\n./pesterchum $@")
f.close()
os.chmod("/usr/local/bin/pesterchum", S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)
# Create a fancy menu item in gnome
if gnome:
print "Creating menu item..."
t = Template("[Desktop Entry]\nEncoding=UTF-8\nVersion=3.14.2\nName=Pesterchum\nComment=IM client based on Homestuck Pesterchum\nCategories=Network;InstantMessaging;\nExec=/usr/local/bin/pesterchum\nIcon=$loc/pesterchum.ico\nTerminal=false\nType=Application")
f = open("/usr/share/applications/pesterchum.desktop", "w")
f.write(t.safe_substitute(loc=instLoc))
f.close()
# create shortcut launcher
if shortcut:
print "Creating launcher..."
t = Template("#!/usr/bin/env xdg-open\n[Desktop Entry]\nEncoding=UTF-8\nVersion=3.14.2\nName=Pesterchum\nComment=IM client based on Homestuck Pesterchum\nCategories=Network;InstantMessaging;\nExec=pesterchum\nIcon=$loc/pesterchum.ico\nTerminal=false\nType=Application")
f = open(_HOME+"/Pesterchum.desktop", "w")
f.write(t.safe_substitute(loc=instLoc))
f.close()
os.chown(_HOME+"/Pesterchum.desktop", _UID, _GID)
os.chmod(_HOME+"/Pesterchum.desktop", S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)
else:
print "Welcome to the Pesterchum 3.14 Easy Uninstaller (for Linux)!\n\
Created by Kiooeht [evacipatedBox] May 28th-29th, 2011.\n\
License: WTFPL\n"
while 1:
remove = raw_input("Would you like to uninstall Pesterchum? [y/n]: ")
if remove.lower() == "y":
while 1:
killdata = raw_input("Purge your settings, profiles, and logs? [y/N]: ")
if killdata.lower() == "n" or killdata == "":
killdata = False;break
elif killdata.lower() == "y":
killdata = True;break
else:
print "Hmmmmm...?"
f = open(_HOME+"/.pcInstallLoc")
instLoc = f.readline()
f.close()
os.remove(_HOME+"/.pcInstallLoc")
if killdata:
print "Removing files..."
shutil.rmtree(instLoc)
else:
print "Backing up settings, profiles, and logs..."
if os.path.exists(instLoc+"/logs"):
shutil.move(instLoc+"/logs", "_easyBackupLOGS")
if os.path.exists(instLoc+"/profiles"):
shutil.move(instLoc+"/profiles", "_easyBackupPROFILES")
if os.path.exists(instLoc+"/pesterchum.js"):
shutil.move(instLoc+"/pesterchum.js", "_easyBackupSETTINGS")
print "Removing files..."
shutil.rmtree(instLoc)
print "Restoring up settings, profiles, and logs..."
os.mkdir(instLoc)
if os.path.exists("_easyBackupLOGS"):
shutil.move("_easyBackupLOGS", instLoc+"/logs")
if os.path.exists("_easyBackupPROFILES"):
shutil.move("_easyBackupPROFILES", instLoc+"/profiles")
if os.path.exists("_easyBackupSETTINGS"):
shutil.move("_easyBackupSETTINGS", instLoc+"/pesterchum.js")
setPermissions(instLoc)
print "Trashing executable..."
os.remove("/usr/local/bin/pesterchum")
if os.path.exists("/usr/share/applications/pesterchum.desktop"):
print "Maiming menu item..."
os.remove("/usr/share/applications/pesterchum.desktop")
if os.path.exists(_HOME+"/Pesterchum.desktop"):
print "Destroying launcher..."
os.remove(_HOME+"/Pesterchum.desktop")
elif os.path.exists(_HOME+"/Desktop/Pesterchum.desktop"):
print "Destroying launcher..."
os.remove(_HOME+"/Desktop/Pesterchum.desktop")
else:
print "Unable to find launcher, non destroyed"
break
elif remove.lower() == "n":
print "Aborting uninstallation process"
break
else:
print "Invalid input, try again"
except KeyboardInterrupt:
print ""
except Exception as e:
error = -1
finally:
if error == -1:
print "Oh noes!! It seems an error has occurred!"
lineN = traceback.extract_tb(sys.exc_info()[2])[-1][1]
print "The error occurred on line %s:" % lineN
formatted_lines = traceback.format_exc().splitlines()
print " '" + formatted_lines[-2] + "'"
print formatted_lines[-1]
while 1:
print "\nWould you like to (s)end a bug report,"
send = raw_input("view the (f)ull error message, or (n)either? [s/f/n]: ")
if send.lower() == "n":
act = 2;break
elif send.lower() == "s":
act = 0;break
elif send.lower() == "f":
print "!---------------BEGIN ERROR MESSAGE---------------!"
for l in formatted_lines:
print l
print "!----------------END ERROR MESSAGE----------------!"
send = raw_input("Would you like to send this error message? [y/n]: ")
if send.lower() == "y":
act = 0;break
elif send.lower() == "n":
act = 2;break
else:
print "What was that?"
if act == 2:
print "Okay"
elif act == 0:
print "Thank you for taking time out of your day to complete a bug report."
print "Fields marked with an asterisk (*) are required."
name = raw_input("Your Name: ")
while 1:
os = raw_input("OS (include version) (ex. Ubuntu 10.10) [*]: ")
if os: break
else: print "This field is required."
while 1:
msg = raw_input("Short description of problem [*]: ")
if msg: break
else: print "This field is required."
import urllib, json
data = urllib.urlencode({"name":name, "os":os, "msg":msg, "short":formatted_lines[-1], "long":json.dumps(formatted_lines)})
try:
print "Sending..."
f = urllib.urlopen("http://distantsphere.com/pc/easyInstall.php", data)
text = f.read()
print text
if text == "success!":
print "Sent!"
else:
print "There seems to have been a problem sending your bug report! ):"
except:
print "There seems to have been a problem sending your bug report! ):"

View file

@ -1,10 +0,0 @@
# runs pesterchum but appends stdout/err to log file
import subprocess
import datetime
f = open("debug.log", 'a')
d = datetime.datetime.now()
f.write("=== PESTERCHUM DEBUG %s ===\n" % d.strftime("%m-%d-%y %H-%M"))
f.flush()
p = subprocess.Popen("pesterchum.exe", stdout=f, stderr=subprocess.STDOUT)
p.wait()
f.close()

View file

@ -1,10 +0,0 @@
# runs pesterchum but appends stdout/err to log file
import subprocess
import datetime
f = open("debug.log", 'a')
d = datetime.datetime.now()
f.write("=== PESTERCHUM DEBUG %s ===\n" % d.strftime("%m-%d-%y %H-%M"))
f.flush()
p = subprocess.Popen(["python", "pesterchum.py"], stdout=f, stderr=subprocess.STDOUT)
p.wait()
f.close()

View file

@ -1,45 +0,0 @@
# WINDOWS setup file!
from cx_Freeze import setup, Executable
import sys
import os
import os.path
import shutil
if sys.platform == "win32":
base = "Win32GUI"
else:
base = "Console"
setup(
name = "PESTERCHUM",
version = "3.14",
description = "P3ST3RCHUM",
executables = [Executable("pesterchum.py",
base=base,
compress=True,
icon="pesterchum.ico",
)])
os.rename("build/exe.win32-2.6", "build/pesterchum")
pcloc = "build/pesterchum"
shutil.copytree("themes", "%s/themes" % (pcloc))
shutil.copytree("imageformats", "%s/imageformats" % (pcloc))
shutil.copytree("smilies", "%s/smilies" % (pcloc))
f = open("%s/pesterchum.js" % (pcloc), 'w')
f.write("{\"tabs\":true, \"chums\":[]}")
f.close()
shutil.copy("C:/Dev/Py26MSdlls-9.0.21022.8/msvc/msvcm90.dll", "%s" % (pcloc))
shutil.copy("C:/Dev/Py26MSdlls-9.0.21022.8/msvc/msvcp90.dll", "%s" % (pcloc))
shutil.copy("C:/Dev/Py26MSdlls-9.0.21022.8/msvc/msvcr90.dll", "%s" % (pcloc))
shutil.copy("C:/Dev/Py26MSdlls-9.0.21022.8/msvc/x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_d08d0375.manifest",
"%s" % (pcloc))
shutil.copy("pesterchum.nsi", "%s/" % (pcloc))
shutil.copy("pesterchum-update.nsi", "%s/ % (pcloc)")
os.mkdir("%s/profiles" % (pcloc))
os.mkdir("%s/logs" % (pcloc))
shutil.copy("logs/chums.js", "%s/logs" % (pcloc))
shutil.copy("readme.txt", "%s/" % (pcloc))
shutil.copy("themes.txt", "%s/" % (pcloc))

View file

@ -4,6 +4,12 @@ import sys
import os
import shutil
if sys.version_info < (3, 0, 0):
sys.exit("Python3 versions lower than 3 are not supported.")
def is_64bit() -> bool:
return sys.maxsize > 2**32
if sys.platform == "win32":
base = "Win32GUI"
else:
@ -19,8 +25,8 @@ build_exe_options = {
'collections.array',
'collections._weakref'],
}
setup(
if is_64bit() == true:
setup(
name = "PESTERCHUM",
version = "3.41",
description = "P3ST3RCHUM",
@ -29,16 +35,14 @@ setup(
base=base,
compress=True,
icon="pesterchum.ico",
),
Executable("pesterchum_debug.py",
base=base,
compress=True,
icon="pesterchum.ico",
build_exe: 'build\Pesterchum\'
)])
#Replace exe.win-amd64-2.7 with whatever it seems to generate as for you.
if sys.platform == "win32":
if sys.platform == "win32":
os.rename("build/exe.win-amd64-2.7", "build/pesterchum")
else:
pass
#Replace exe.win-amd64-2.7 with whatever it seems to generate as for you.
shutil.copytree("themes", "build/pesterchum/themes")
shutil.copytree("smilies", "build/pesterchum/smilies")

View file

@ -4,10 +4,10 @@ import sys
import os
import shutil
from version import _pcVersion
if sys.platform == "win32":
base = "Win32GUI"
else:
base = "Console"
build_exe_options = {
"includes": ["requests","urllib"],
@ -21,9 +21,9 @@ build_exe_options = {
}
setup(
name = "PESTERCHUM",
version = "3.41",
description = "P3ST3RCHUM",
name = "Pesterchum",
version = str(_pcVersion),
description = "Pesterchum Alt. 2.0 :)",
options = {"build_exe": build_exe_options},
executables = [Executable("pesterchum.py",
base=base,
@ -34,19 +34,19 @@ setup(
icon="pesterchum.ico",
)])
if sys.platform == "win32":
os.rename("build/exe.win32-2.7", "build/pesterchum")
#if sys.platform == "win32":
# os.rename("build/exe.win32-2.7", "build/pesterchum")
shutil.copytree("themes", "build/pesterchum/themes")
shutil.copytree("smilies", "build/pesterchum/smilies")
shutil.copytree("quirks", "build/pesterchum/quirks")
shutil.copy("pesterchum.nsi", "build/pesterchum/")
shutil.copy("pesterchum-update.nsi", "build/pesterchum/")
os.mkdir("build/pesterchum/profiles")
os.mkdir("build/pesterchum/logs")
#shutil.copy("pesterchum.nsi", "build/pesterchum/")
#shutil.copy("pesterchum-update.nsi", "build/pesterchum/")
#os.mkdir("build/pesterchum/profiles")
#os.mkdir("build/pesterchum/logs")
#Readme & txt
shutil.copy("README.md", "build/pesterchum/")
shutil.copy("README-pesterchum.mkdn", "build/pesterchum/")
shutil.copy("README-karxi.mkdn", "build/pesterchum/")
shutil.copy("themes.txt", "build/pesterchum/")
#shutil.copy("README.md", "build/pesterchum/")
#shutil.copy("README-pesterchum.mkdn", "build/pesterchum/")
#shutil.copy("README-karxi.mkdn", "build/pesterchum/")
#shutil.copy("themes.txt", "build/pesterchum/")