@mritter0
Here is the installer for AOrganiser.
It's bit more complex, shows usage of GUI elements, and page handlers, as well as using python modules to add further functionality.
#
# AOrganiser installer
#
# $VER: AOrganiser Install 1.1 (2.5.2017)
#
#################################################
import installer
from installer import *
import os
import sys
import shutil
havevars = True
try:
import amigavars
except ImportError:
havevars = False
def GetEnv(varname):
if havevars:
return amigavars.GetEnv(varname)
else:
varfile = os.path.join("ENV:",varname)
value = None
try:
f = open(varfile,"r")
if f:
value = f.readline()
f.close()
return value
except IOError:
return None
#################################################
welcome = """Welcome to the AOrganiser Diary Installation
This installation script will guide you through the process of installing the AOrganiser application to your prefered location on your system.
Please note: When you are asked for the location to install AOrganiser a directory called AOrganiser will be created at your chosen location.
This install script will also highlight and download any missing dependencies with the exception of AmiSSL 4, which will need to be preinstalled by the end user.
"""
def fixEmailMime():
try:
import email.mime
except ImportError,e:
os.system("echo NOLINE "" >python:lib/email/mime/__init__.py")
def fetchArchive(url):
sys.path.append('AOrganiser/Scripts/')
from CalDAV.oauth2client import httplib2
http = httplib2.Http(disable_ssl_certificate_validation=True)
(response,content) = http.request(url,method = "GET")
status = int(response['status'])
if (status >= 200) and (status < 299):
if 'content-disposition' in response:
disp = response['content-disposition'].split(';')
if disp[0] == "attachment":
junk,filename = disp[1].split('=')
filename = filename.strip(""")
else:
filename = url.split("/")[-1]
f = open(filename,"w")
if f:
f.write(content)
f.close()
return filename
return None
#################################################
def finalProc(page):
destination = GetString(destinationPage,"destination")
SetString(page,"message","AOrganiser is now installed to %s" % destination)
if freshProActionInstall:
current = os.getcwd()
os.chdir(os.path.join(destination, "ProAction/"))
print "Starting ProActionCTRL to add ProAction to Appdir:"
os.system("run >NIL: python ProActionCtrl")
os.chdir(current)
scripts = ["Scripts/SearchGUI.py","Scripts/CalDAV/DeleteCalDAV.py",
"Scripts/CalDAV/ExportSelected.py",
"Scripts/CalDAV/GoogleSetUpWizard.py",
"Scripts/CalDAV/ReplyCalDAV.py",
"Scripts/CalDAV/ResetCalDAVScripts.py",
"Scripts/CalDAV/SyncToCalDAV.py",
"Scripts/CalDAV/UpdateCalDAV.py"]
for s in scripts:
script = os.path.join(destination,"AOrganiser",s)
os.system("PROTECT "" + script + "" +s")
return True
#################################################
# Get dependnecies
# ProAction
freshProActionInstall = False
f = os.popen("VERSION APPDIR:ProAction")
vers = None
if f:
vers = f.read().strip("\n")
f.close()
if vers != None and vers[:7] != "VERSION":
proactionVers = vers.split(" ")[1]
version,revision = proactionVers.split(".")
proactionVersion = int(version)
proactionRevision = int(revision)
else:
proactionVers = None
# AmigaVars
try:
import amigavars
haveAmigaVars = True
except ImportError:
haveAmigaVars = False
# PythonSSL
try:
import socket
import _ssl
havePythonSSL = True
except ImportError:
havePythonSSL = False
##################################################
def installProAction():
global freshProActionInstall
installedpath = GetEnv("Appdir/Proaction")
print "Fetching the ProAction Archive from os4depot.net"
archive = fetchArchive("http://os4depot.net/share/library/reaction/proaction.lha")
if archive:
os.system("SYS:Utilities/UnArc FROM " + archive + " TO CURRDIR: AUTO QUIET")
myFiles = ["ProAction","ProAction.info"]
if installedpath:
if os.path.basename(installedpath).upper() == "PROACTION":
installedpath = os.path.dirname(installedpath)
proactionpkg = AddPackage(FILEPACKAGE,
name="ProAction Package",
alternatepath = installedpath,
description="",
files = myFiles
)
else:
os.system("C:RequestChoice "File Downloaded" "You appear to have ProAction installed in an unusual way*NThe archive has been downloaded for you to custom install by hand" "OK" >NIL:")
else:
proactionpkg = AddPackage(FILEPACKAGE,
name="ProAction Package",
description="",
files = myFiles
)
freshProActionInstall = True
else:
os.system("C:RequestChoice "Download Failed" "Unable to download the ProAction archive" "OK" >NIL:")
def installAmigaVars():
archive = fetchArchive("http://os4depot.net/share/development/library/amigavars.lha")
print "Fetching the AmigaVars Archive from os4depot.net"
if archive:
os.system("SYS:Utilities/UnArc FROM " + archive + " TO CURRDIR: AUTO QUIET")
shutil.copy2("amigavars.so","PYTHON:Lib/site-packages/amigavars.so")
else:
os.system("C:RequestChoice "Download Failed" "Unable to download the AmigaVars archive" "OK" >NIL:")
def moveToBackUp(filename):
success = False
i = 1
while not success:
backupname = filename + "." + str(i)
try:
shutil.move(filename,backupname)
success = True
except:
i = i + 1
def installPythonSSL():
archive = fetchArchive("http://os4depot.net/share/library/misc/pythonssl.lha")
print "Fetching the PythonSSL Archive from os4depot.net"
if archive:
os.system("SYS:Utilities/UnArc FROM " + archive + " TO CURRDIR: AUTO QUIET")
moveToBackUp("PYTHON:Lib/lib-dynload/select.so")
shutil.copy2("pythonssl/select.so","PYTHON:Lib/lib-dynload/select.so")
moveToBackUp("PYTHON:Lib/lib-dynload/_socket.so")
shutil.copy2("pythonssl/_socket.so","PYTHON:Lib/lib-dynload/_socket.so")
shutil.copy2("pythonssl/_ssl.so","PYTHON:Lib/lib-dynload/_ssl.so")
else:
os.system("C:RequestChoice "Download Failed" "Unable to download the PythonSSL archive" "OK" >NIL:")
def installDeps(page):
if depsProActionCB:
checked = GetUIAttr(depsPage,depsProActionCB,GUI_CHECKED)
if checked:
print "Installing ProAction!"
installProAction()
if depsAmigaVarsCB:
checked = GetUIAttr(depsPage,depsAmigaVarsCB,GUI_CHECKED)
if checked:
print "Installing AmigaVars!"
installAmigaVars()
if depsPythonSSLCB:
checked = GetUIAttr(depsPage,depsPythonSSLCB,GUI_CHECKED)
if checked:
print "Installing PythonSSL!"
installPythonSSL()
return True
##################################################
welcomePage = NewPage(WELCOME)
SetString(welcomePage, "message" , welcome)
NewPage(README)
NewPage(LICENSE)
depsPage = NewPage(GUI)
depsProActionCB = None
depsAmigaVarsCB = None
depsPythonSSLCB = None
StartGUI(depsPage)
BeginGroup(orientation=GROUP_VERTICAL,label="Dependencies", frame=GROUP_FRAME)
BeginGroup(orientation=GROUP_VERTICAL, label="ProAction", frame=GROUP_FRAME,weight=1)
if proactionVers:
AddLabel(label="ProAction Version " + proactionVers + " is installed\nProAction Version 1.8 and up is recomended")
if (proactionVersion < 1) or (proactionVersion <= 1 and proactionRevision < 8):
depsProActionCB = AddCheckBox(label="Upgrade ProAction", checked=True)
else:
AddLabel(label="ProAction is not installed\nProAction Version 1.8 is recomended")
depsProActionCB = AddCheckBox(label="Install ProAction", checked=True)
EndGroup()
BeginGroup(orientation=GROUP_VERTICAL, label="AmigaVars", frame=GROUP_FRAME,weight=1)
if haveAmigaVars:
AddLabel(label="The Amiga Vars module is installed\nNo Action required")
else:
AddLabel(label="The Amiga Vars module is recommended to allow some scripts to save settings etc\n")
depsAmigaVarsCB = AddCheckBox(label="Install AmigaVars", checked=True)
EndGroup()
BeginGroup(orientation=GROUP_VERTICAL, label="PythonSSL", frame=GROUP_FRAME,weight=1)
if havePythonSSL:
AddLabel(label="The PythonSSL module is installed\nNo Action required")
else:
AddLabel(label="The PythonSS module is recommended to allow access to https URLS\n")
depsPythonSSLCB = AddCheckBox(label="Install PythonSSL", checked=True)
EndGroup()
EndGroup()
EndGUI()
destinationPage = NewPage(DESTINATION)
SetObject(destinationPage, "entryhandler", installDeps)
installPage = NewPage(INSTALL)
SetString(installPage, "message" , "Please select a location to install AOrganiser\nAn drawer named AOrganiser will be created there:")
finalPage = NewPage(FINISH)
SetString(finalPage, "message" , "")
SetObject(finalPage, "entryhandler", finalProc)
##############################################
# Set up the packages we need
myFiles = ["AOrganiser","AOrganiser.info"]
package = AddPackage(FILEPACKAGE,
name="AOrganiser Package",
description="",
files = myFiles
)
fixEmailMime()
#fetchArchive("http://os4depot.net/share/library/reaction/proaction.lha")
#fetchArchive("http://os4depot.net/share/development/library/amigavars.lha")
#fetchArchive("http://os4depot.net/share/library/misc/pythonssl.lha")
RunInstaller()