Python Installer API

3 posts / 0 new
Last post
frederick
frederick's picture
Offline
Last seen: 6 months 2 weeks ago
Joined: 2018-01-15 22:51
Python Installer API

Hello everybody,

Lately I was looking for material about OS4 installer. Naturally I looked at the Hyperion wiki and followed the advice of checking the operating system installer.
But I still would like to know about all the available Python API for the installer.

Is there any reference somewhere ?

Thanks !

broadblues
broadblues's picture
Offline
Last seen: 1 month 3 days ago
Joined: 2012-05-02 21:48
Re: Python Installer API

Well you said you looked at the wikki but this is the main manual http://wiki.amigaos.net/wiki/Installation_Utility

Also take the OS4 install script as an example.

broadblues
broadblues's picture
Offline
Last seen: 1 month 3 days ago
Joined: 2012-05-02 21:48
Re: Python Installer API

Here is my AOrganiser installation script

  1. #
  2. # AOrganiser installer
  3. #
  4. # $VER: AOrganiser Install 1.1 (2.5.2017)
  5. #
  6.  
  7. #################################################
  8. import installer
  9. from installer import *
  10. import os
  11. import sys
  12. import shutil
  13.  
  14.  
  15. havevars = True
  16. try:
  17. import amigavars
  18. except ImportError:
  19. havevars = False
  20.  
  21. def GetEnv(varname):
  22. if havevars:
  23. return amigavars.GetEnv(varname)
  24. else:
  25. varfile = os.path.join("ENV:",varname)
  26. value = None
  27. try:
  28. f = open(varfile,"r")
  29. if f:
  30. value = f.readline()
  31. f.close()
  32. return value
  33. except IOError:
  34. return None
  35.  
  36.  
  37.  
  38. #################################################
  39. welcome = """Welcome to the AOrganiser Diary Installation
  40.  
  41. This installation script will guide you through the process of installing the AOrganiser application to your prefered
  42. location on your system.
  43.  
  44. Please note: When you are asked for the location to install AOrganiser a directory called AOrganiser will be created at your
  45. chosen location.
  46.  
  47. This install script will also highlight and download any missing dependencies with the exception of AmiSSL 4, which will
  48. need to be preinstalled by the end user.
  49. """
  50.  
  51. def fixEmailMime():
  52. try:
  53. import email.mime
  54. except ImportError,e:
  55. os.system("echo NOLINE \"\" >python:lib/email/mime/__init__.py")
  56.  
  57. def fetchArchive(url):
  58. sys.path.append('AOrganiser/Scripts/')
  59. from CalDAV.oauth2client import httplib2
  60.  
  61. http = httplib2.Http(disable_ssl_certificate_validation=True)
  62. (response,content) = http.request(url,method = "GET")
  63. status = int(response['status'])
  64. if (status >= 200) and (status < 299):
  65. if 'content-disposition' in response:
  66. disp = response['content-disposition'].split(';')
  67. if disp[0] == "attachment":
  68. junk,filename = disp[1].split('=')
  69. filename = filename.strip("\"")
  70. else:
  71. filename = url.split("/")[-1]
  72. f = open(filename,"w")
  73. if f:
  74. f.write(content)
  75. f.close()
  76. return filename
  77. return None
  78.  
  79. #################################################
  80.  
  81. def finalProc(page):
  82. destination = GetString(destinationPage,"destination")
  83. SetString(page,"message","AOrganiser is now installed to %s" % destination)
  84. if freshProActionInstall:
  85. current = os.getcwd()
  86. os.chdir(os.path.join(destination, "ProAction/"))
  87. print "Starting ProActionCTRL to add ProAction to Appdir:"
  88. os.system("run >NIL: python ProActionCtrl")
  89. os.chdir(current)
  90. scripts = ["Scripts/SearchGUI.py","Scripts/CalDAV/DeleteCalDAV.py",
  91. "Scripts/CalDAV/ExportSelected.py",
  92. "Scripts/CalDAV/GoogleSetUpWizard.py",
  93. "Scripts/CalDAV/ReplyCalDAV.py",
  94. "Scripts/CalDAV/ResetCalDAVScripts.py",
  95. "Scripts/CalDAV/SyncToCalDAV.py",
  96. "Scripts/CalDAV/UpdateCalDAV.py"]
  97. for s in scripts:
  98. script = os.path.join(destination,"AOrganiser",s)
  99. os.system("PROTECT \"" + script + "\" +s")
  100. return True
  101.  
  102.  
  103.  
  104. #################################################
  105. # Get dependnecies
  106.  
  107. # ProAction
  108.  
  109. freshProActionInstall = False
  110.  
  111. f = os.popen("VERSION APPDIR:ProAction")
  112.  
  113. vers = None
  114.  
  115. if f:
  116. vers = f.read().strip("\n")
  117. f.close()
  118.  
  119. if vers != None and vers[:7] != "VERSION":
  120. proactionVers = vers.split(" ")[1]
  121. version,revision = proactionVers.split(".")
  122. proactionVersion = int(version)
  123. proactionRevision = int(revision)
  124. else:
  125. proactionVers = None
  126.  
  127. # AmigaVars
  128.  
  129. try:
  130. import amigavars
  131. haveAmigaVars = True
  132. except ImportError:
  133. haveAmigaVars = False
  134.  
  135. # PythonSSL
  136.  
  137. try:
  138. import socket
  139. import _ssl
  140. havePythonSSL = True
  141. except ImportError:
  142. havePythonSSL = False
  143.  
  144. ##################################################
  145.  
  146. def installProAction():
  147. global freshProActionInstall
  148.  
  149. installedpath = GetEnv("Appdir/Proaction")
  150. print "Fetching the ProAction Archive from os4depot.net"
  151. archive = fetchArchive("http://os4depot.net/share/library/reaction/proaction.lha")
  152. if archive:
  153. os.system("SYS:Utilities/UnArc FROM " + archive + " TO CURRDIR: AUTO QUIET")
  154. myFiles = ["ProAction","ProAction.info"]
  155.  
  156. if installedpath:
  157. if os.path.basename(installedpath).upper() == "PROACTION":
  158. installedpath = os.path.dirname(installedpath)
  159. proactionpkg = AddPackage(FILEPACKAGE,
  160. name="ProAction Package",
  161. alternatepath = installedpath,
  162. description="",
  163. files = myFiles
  164. )
  165. else:
  166. os.system("C:RequestChoice \"File Downloaded\" \"You appear to have ProAction installed in
  167. an unusual way*NThe archive has been downloaded for you to custom install by hand\" \"OK\" >NIL:")
  168. else:
  169. proactionpkg = AddPackage(FILEPACKAGE,
  170. name="ProAction Package",
  171. description="",
  172. files = myFiles
  173. )
  174. freshProActionInstall = True
  175. else:
  176. os.system("C:RequestChoice \"Download Failed\" \"Unable to download the ProAction archive\" \"OK\" >NIL:")
  177.  
  178. def installAmigaVars():
  179. archive = fetchArchive("http://os4depot.net/share/development/library/amigavars.lha")
  180. print "Fetching the AmigaVars Archive from os4depot.net"
  181. if archive:
  182. os.system("SYS:Utilities/UnArc FROM " + archive + " TO CURRDIR: AUTO QUIET")
  183. shutil.copy2("amigavars.so","PYTHON:Lib/site-packages/amigavars.so")
  184. else:
  185. os.system("C:RequestChoice \"Download Failed\" \"Unable to download the AmigaVars archive\" \"OK\" >NIL:")
  186.  
  187. def moveToBackUp(filename):
  188. success = False
  189. i = 1
  190. while not success:
  191. backupname = filename + "." + str(i)
  192. try:
  193. shutil.move(filename,backupname)
  194. success = True
  195. except:
  196. i = i + 1
  197.  
  198. def installPythonSSL():
  199. archive = fetchArchive("http://os4depot.net/share/library/misc/pythonssl.lha")
  200. print "Fetching the PythonSSL Archive from os4depot.net"
  201. if archive:
  202. os.system("SYS:Utilities/UnArc FROM " + archive + " TO CURRDIR: AUTO QUIET")
  203. moveToBackUp("PYTHON:Lib/lib-dynload/select.so")
  204. shutil.copy2("pythonssl/select.so","PYTHON:Lib/lib-dynload/select.so")
  205.  
  206. moveToBackUp("PYTHON:Lib/lib-dynload/_socket.so")
  207. shutil.copy2("pythonssl/_socket.so","PYTHON:Lib/lib-dynload/_socket.so")
  208.  
  209. shutil.copy2("pythonssl/_ssl.so","PYTHON:Lib/lib-dynload/_ssl.so")
  210. else:
  211. os.system("C:RequestChoice \"Download Failed\" \"Unable to download the PythonSSL archive\" \"OK\" >NIL:")
  212.  
  213. def installDeps(page):
  214.  
  215. if depsProActionCB:
  216. checked = GetUIAttr(depsPage,depsProActionCB,GUI_CHECKED)
  217. if checked:
  218. print "Installing ProAction!"
  219. installProAction()
  220. if depsAmigaVarsCB:
  221. checked = GetUIAttr(depsPage,depsAmigaVarsCB,GUI_CHECKED)
  222. if checked:
  223. print "Installing AmigaVars!"
  224. installAmigaVars()
  225. if depsPythonSSLCB:
  226. checked = GetUIAttr(depsPage,depsPythonSSLCB,GUI_CHECKED)
  227. if checked:
  228. print "Installing PythonSSL!"
  229. installPythonSSL()
  230. return True
  231.  
  232. ##################################################
  233. welcomePage = NewPage(WELCOME)
  234. SetString(welcomePage, "message" , welcome)
  235.  
  236. NewPage(README)
  237. NewPage(LICENSE)
  238.  
  239. depsPage = NewPage(GUI)
  240.  
  241. depsProActionCB = None
  242. depsAmigaVarsCB = None
  243. depsPythonSSLCB = None
  244.  
  245. StartGUI(depsPage)
  246.  
  247. BeginGroup(orientation=GROUP_VERTICAL,label="Dependencies", frame=GROUP_FRAME)
  248. BeginGroup(orientation=GROUP_VERTICAL, label="ProAction", frame=GROUP_FRAME,weight=1)
  249. if proactionVers:
  250. AddLabel(label="ProAction Version " + proactionVers + " is installed\nProAction Version 1.8 and up is recomended")
  251.  
  252. if (proactionVersion < 1) or (proactionVersion <= 1 and proactionRevision < 8):
  253. depsProActionCB = AddCheckBox(label="Upgrade ProAction", checked=True)
  254. else:
  255. AddLabel(label="ProAction is not installed\nProAction Version 1.8 is recomended")
  256. depsProActionCB = AddCheckBox(label="Install ProAction", checked=True)
  257.  
  258. EndGroup()
  259.  
  260. BeginGroup(orientation=GROUP_VERTICAL, label="AmigaVars", frame=GROUP_FRAME,weight=1)
  261. if haveAmigaVars:
  262. AddLabel(label="The Amiga Vars module is installed\nNo Action required")
  263. else:
  264. AddLabel(label="The Amiga Vars module is recommended to allow some scripts to save settings etc\n")
  265. depsAmigaVarsCB = AddCheckBox(label="Install AmigaVars", checked=True)
  266. EndGroup()
  267.  
  268. BeginGroup(orientation=GROUP_VERTICAL, label="PythonSSL", frame=GROUP_FRAME,weight=1)
  269. if havePythonSSL:
  270. AddLabel(label="The PythonSSL module is installed\nNo Action required")
  271. else:
  272. AddLabel(label="The PythonSS module is recommended to allow access to https URLS\n")
  273. depsPythonSSLCB = AddCheckBox(label="Install PythonSSL", checked=True)
  274. EndGroup()
  275.  
  276. EndGroup()
  277. EndGUI()
  278.  
  279. destinationPage = NewPage(DESTINATION)
  280. SetObject(destinationPage, "entryhandler", installDeps)
  281.  
  282. installPage = NewPage(INSTALL)
  283. SetString(installPage, "message" , "Please select a location to install AOrganiser\nAn drawer named AOrganiser will be
  284. created there:")
  285.  
  286. finalPage = NewPage(FINISH)
  287. SetString(finalPage, "message" , "")
  288. SetObject(finalPage, "entryhandler", finalProc)
  289.  
  290.  
  291. ##############################################
  292. # Set up the packages we need
  293.  
  294. myFiles = ["AOrganiser","AOrganiser.info"]
  295.  
  296. package = AddPackage(FILEPACKAGE,
  297. name="AOrganiser Package",
  298. description="",
  299. files = myFiles
  300. )
  301.  
  302.  
  303. fixEmailMime()
  304. #fetchArchive("http://os4depot.net/share/library/reaction/proaction.lha")
  305. #fetchArchive("http://os4depot.net/share/development/library/amigavars.lha")
  306. #fetchArchive("http://os4depot.net/share/library/misc/pythonssl.lha")
  307.  
  308. RunInstaller()
Log in or register to post comments