[Greater-commits] r354 - trunk/packaging

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Jul 6 12:53:36 CEST 2011


Author: aheinecke
Date: 2011-07-06 12:53:34 +0200 (Wed, 06 Jul 2011)
New Revision: 354

Modified:
   trunk/packaging/greater-installer.nsi
   trunk/packaging/makeinstaller.py
Log:
Fix installer / uninstaller creation and improve it so that it includes postgresql



Modified: trunk/packaging/greater-installer.nsi
===================================================================
--- trunk/packaging/greater-installer.nsi	2011-07-06 10:53:06 UTC (rev 353)
+++ trunk/packaging/greater-installer.nsi	2011-07-06 10:53:34 UTC (rev 354)
@@ -18,65 +18,19 @@
 ; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 ;
 ;--------------------------------
-;Includes
+; Includes
 
   ; Modern UI
   !include "MUI.nsh"
 
-  ; Uninstaller logging to only remove what was installed
-  !include "UninstallLog.nsh"
+;--------------------------------
+; Plugins
+  !addplugindir plugins
 
-  ;--------------------------------
-  ; Configure UnInstall log to only remove what is installed
-  ;-------------------------------- 
-  ;Set the name of the uninstall log
-  !define UninstLog "uninstall.log"
-  Var UninstLog
-
-  ;Uninstall log file missing.
-  LangString UninstLogMissing "${UninstLog} not found!$\r$\nUninstallation cannot proceed!"
-
-  ;AddItem macro
-  !define AddItem "!insertmacro AddItem"
-
-  ;File macro
-  !define File "!insertmacro File"
-
-  ;CreateShortcut macro
-  !define CreateShortcut "!insertmacro CreateShortcut"
-
-  ;Copy files macro
-  !define CopyFiles "!insertmacro CopyFiles"
-
-  ;Rename macro
-  !define Rename "!insertmacro Rename"
-
-  ;CreateDirectory macro
-  !define CreateDirectory "!insertmacro CreateDirectory"
-
-  ;SetOutPath macro
-  !define SetOutPath "!insertmacro SetOutPath"
-
-  ;WriteUninstaller macro
-  !define WriteUninstaller "!insertmacro WriteUninstaller"
-
-  ;WriteRegStr macro
-  !define WriteRegStr "!insertmacro WriteRegStr"
-
-  ;WriteRegDWORD macro
-  !define WriteRegDWORD "!insertmacro WriteRegDWORD" 
-
-  Section -openlogfile
-    CreateDirectory "$INSTDIR"
-    IfFileExists "$INSTDIR\${UninstLog}" +3
-      FileOpen $UninstLog "$INSTDIR\${UninstLog}" w
-    Goto +4
-      SetFileAttributes "$INSTDIR\${UninstLog}" NORMAL
-      FileOpen $UninstLog "$INSTDIR\${UninstLog}" a
-      FileSeek $UninstLog 0 END
-  SectionEnd
-
 ;--------------------------------
+; Variable declarations
+  Var POSTGRESQL_INSTALLED
+;--------------------------------
 ;Version Information (for installer file properties)
 
   VIProductVersion "${version_number}" ;needs integer format: x.x.x.x
@@ -90,30 +44,25 @@
 
 
 ;--------------------------------
-;General
+; General
 
   ; Define Name, File and Installdir of Installer
   Name "${productname}"
   OutFile "${setupname}"
   InstallDir "$PROGRAMFILES\${productname_short}"
-  InstType full
-  InstType client
-  InstType server
+  InstType "Single User"
+  InstType "Client Only"
+  InstType "Server Only"
 
 ;--------------------------------
 ;Interface Settings
 
-  InstTypeSetText 0 "Full Installation"
-  InstTypeSetText 1 "Client only (no Database)"
-  InstTypeSetText 2 "Server only"
-  SectionSetInstTypes ${full_section_id} 1
-
   !define MUI_ABORTWARNING
   BrandingText "GREAT-ER III - PostgreSQL"
   ; MUI Settings / Header
   !define MUI_WELCOMEPAGE_TITLE "Welcome to the installation of GREAT-ER III - PostgreSQL"
   !define MUI_WELCOMEPAGE_TEXT "This Installer will install\r\n\
-  The Geo-referenced Regional Exposure Assesment Tool for European Rivers\r\n
+  The Geo-referenced Regional Exposure Assesment Tool for European Rivers\r\n\
   using the Postges SQL Database backend."
   !define MUI_HEADERIMAGE
   !define MUI_COMPONENTSPAGE_TEXT_TOP "Please select installation type"
@@ -124,8 +73,8 @@
   !define MUI_PAGE_CUSTOMFUNCTION_SHOW PrintNonAdminWarning
   !insertmacro MUI_PAGE_WELCOME
   !insertmacro MUI_PAGE_LICENSE ${license}
-  !insertmacro MUI_PAGE_DIRECTORY
   !insertmacro MUI_PAGE_COMPONENTS
+  !insertmacro MUI_PAGE_DIRECTORY
   Page custom CustomPageOptions
   !insertmacro MUI_PAGE_INSTFILES
   !insertmacro MUI_PAGE_FINISH
@@ -133,6 +82,7 @@
   !define MUI_PAGE_CUSTOMFUNCTION_SHOW un.PrintNonAdminWarning
   !insertmacro MUI_UNPAGE_WELCOME
   !insertmacro MUI_UNPAGE_CONFIRM
+  !insertmacro MUI_UNPAGE_COMPONENTS
   !insertmacro MUI_UNPAGE_INSTFILES
   !insertmacro MUI_UNPAGE_FINISH
 
@@ -152,7 +102,18 @@
 ;--------------------------------
 ;Installer Sections
 
-Section full full_section_id
+Section "PostgreSQL 9.0.4" SecPostgreSQL
+  SetOutPath "$TEMP"
+  File "postgresql-9.0.4-1-windows.exe"
+  DetailPrint "PostgreSQL wird installiert..."
+  ExecWait '"$TEMP\postgresql-9.0.4-1-windows.exe --mode unattended"' $0
+SectionEnd
+
+Section "Administration Tool" admin_section_id
+;  !include ${adminfiles}
+SectionEnd
+
+Section "GREAT-ER Client" client_section_id
   SetOutPath "$INSTDIR"
 
   ; Store installation folder
@@ -162,7 +123,7 @@
   ; package all files, recursively, preserving attributes
   ; assume files are in the correct places
 
-  !include ${allfiles}
+  !include ${client-in}
 
   ; Create uninstaller
   WriteUninstaller "$INSTDIR\Uninstall.exe"
@@ -208,7 +169,7 @@
   IntCmp $R0 0 no_desktop
   # Create new Desktop link
   CreateShortCut "$DESKTOP\${productname_short}.lnk" "$INSTDIR\${executable}"
-#  no_desktop:
+  no_desktop:
 
   ; Create killkde.bat 
   FileOpen $1 "$INSTDIR\bin\killgreater.bat" "w"
@@ -225,13 +186,26 @@
 ;--------------------------------
 ;Install Functions
 Function ".onInit"
-  ; Language select dialog - not needed!
-;  !insertmacro MUI_LANGDLL_DISPLAY
+  InstTypeSetText 0 "Full Installation"
+  InstTypeSetText 1 "Client only (no Database)"
+  InstTypeSetText 2 "Server only"
+  SectionSetInstTypes ${client_section_id} 3
+  SectionSetSize ${SecPostgreSQL} "207330"
   !insertmacro MUI_INSTALLOPTIONS_EXTRACT "installer-options.ini"
   call CheckExistingVersion
+  CALL DetectPostgreSQL
 FunctionEnd
 
-; Check whether application has already been installed.
+Function DetectPostgreSQL
+  ClearErrors
+  readregstr $1 HKLM "SOFTWARE\PostgreSQL\Installations\postgresql-9.0" "Version"
+  IfErrors done
+    !insertmacro UnSelectSection ${SecPostgreSQL}
+    StrCpy $POSTGRESQL_INSTALLED "yes"
+  done:
+FunctionEnd
+
+;Check whether application has already been installed.
 Function CheckExistingVersion
   ClearErrors
   Push $0
@@ -241,6 +215,7 @@
     $(T_AlreadyInstalled)" IDYES leave
     Abort
   leave:
+
 FunctionEnd
 
 # PrintNonAdminWarning
@@ -267,13 +242,13 @@
 
   # Note that the default selection is done in the ini file.
   !insertmacro MUI_INSTALLOPTIONS_WRITE "installer-options.ini" \
-        "Field 1" "Text" "Please select where ${productname_short} shall install shortcuts:"
+        "Field 1" "Text" "Please select where ${productname_short} should place shortcuts:"
   !insertmacro MUI_INSTALLOPTIONS_WRITE "installer-options.ini" \
         "Field 2" "Text" "Start Menu"
   !insertmacro MUI_INSTALLOPTIONS_WRITE "installer-options.ini" \
         "Field 3" "Text" "Desktop"
   !insertmacro MUI_INSTALLOPTIONS_WRITE "installer-options.ini" \
-        "Field 4" "Text" "Install for all users"
+        "Field 4" "Text" "Install Shortcuts for all users"
   !insertmacro MUI_INSTALLOPTIONS_DISPLAY "installer-options.ini"
 FunctionEnd
 
@@ -284,13 +259,13 @@
 Function AbortDisplayLogOption
 
   ; Display a message box with the error 
-  MessageBox MB_YESNO|MB_ICONSTOP "$R8$\r$\n$\r$\nDo you ont th open '$R9'?" IDYES adlo_show_error_log
+  MessageBox MB_YESNO|MB_ICONSTOP "$R8$\r$\n$\r$\nDo you wont to open '$R9'?" IDYES adlo_show_error_log
 
   ; If the user selects NO, simply abort the installation
-  Abort "$R8" 
+  Abort "$R8"
   Return
 
-  adlo_show_error_log: 
+  adlo_show_error_log:
     ;Otherwise show the error log first
     ExecShell "open" "$R9"
     Abort "$R8"
@@ -301,65 +276,41 @@
 ;Uninstaller
 
 
-Section "un."
-  IfFileExists "$INSTDIR\${UninstLog}" +3
-    MessageBox MB_OK|MB_ICONSTOP "$(UninstLogMissing)"
-    Abort
+Section "un.PostgreSQL" UnSecPostgreSQL
+  MessageBox MB_YESNO|MB_ICONQUESTION "Do you really wish to uninstall PostgreSQL?\
+  This will also remove all data from your GREAT-ER Database!" \
+  IDYES uninstallPostgreSQL IDNO no
+  uninstallPostgreSQL:
+   Banner::show /NOUNLOAD /set 76 "Uninstalling PostgreSQL..."
+   ; TODO find path from registry and uninstall
+   ExecWait '"uninstall-postgresql.exe --unattended"'
+   Banner::destroy 
+  no: 
+SectionEnd
 
-  DetailPrint "Terminating Processes"
-  ExecDos::exec '"$SYSDIR\cmd.exe" /C "$INSTDIR\bin\killgreater.bat"' ""
-
-  ; Delete all files
-
-  Push $R0
-  Push $R1
-  Push $R2
-  SetFileAttributes "$INSTDIR\${UninstLog}" NORMAL
-  FileOpen $UninstLog "$INSTDIR\${UninstLog}" r
-  StrCpy $R1 -1
-
-  GetLineCount:
-    ClearErrors
-    FileRead $UninstLog $R0
-    IntOp $R1 $R1 + 1
-    StrCpy $R0 $R0 -2
-    Push $R0   
-    IfErrors 0 GetLineCount
-
-  Pop $R0
-
-  LoopRead:
-    StrCmp $R1 0 LoopDone
-    Pop $R0
-
-    IfFileExists "$R0\*.*" 0 +3
-      RMDir $R0  #is dir
-    Goto +9
-    IfFileExists $R0 0 +3
-      Delete $R0 #is file
-    Goto +6
-    StrCmp $R0 "${REG_ROOT} ${REG_APP_PATH}" 0 +3
-      DeleteRegKey ${REG_ROOT} "${REG_APP_PATH}" #is Reg Element
-    Goto +3
-    StrCmp $R0 "${REG_ROOT} ${UNINSTALL_PATH}" 0 +2
-      DeleteRegKey ${REG_ROOT} "${UNINSTALL_PATH}" #is Reg Element
-
-    IntOp $R1 $R1 - 1
-    Goto LoopRead
-  LoopDone:
-  FileClose $UninstLog
-  Delete "$INSTDIR\${UninstLog}"
-  Pop $R2
-  Pop $R1
-  Pop $R0
-
+Section "un."
+!include ${client-un}
 SectionEnd
 
 
 ;--------------------------------
 ;Uninstall Functions
 
+Function un.onInit
+    CALL un.DetectPostgreSQL
+FunctionEnd
+
 # PrintNonAdminWarning (uninstall)
+Function un.DetectPostgreSQL
+  ClearErrors
+  readregstr $1 HKLM "SOFTWARE\PostgreSQL\Installations\postgresql-9.0" "Version"
+  IfErrors noexist done
+  noexist:
+    !insertmacro UnSelectSection ${UnSecPostgreSQL}
+    !insertmacro SetSectionFlag ${UnSecPostgreSQL} ${SF_RO}
+  done:
+FunctionEnd
+
 Function un.PrintNonAdminWarning
   ClearErrors
   UserInfo::GetName
@@ -377,10 +328,18 @@
 ;---------------------------
 ; Language Strings
 ;---------------------------
+
+!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
+  !insertmacro MUI_DESCRIPTION_TEXT ${SecPostgreSQL} "Installs the PostgreSQL 9.0.4 Database with \
+  basic ${productname_short} datasets."
+  !insertmacro MUI_DESCRIPTION_TEXT ${client_section_id} "Installs the ${productname_short} Client."
+!insertmacro MUI_FUNCTION_DESCRIPTION_END
+
 # From Function CheckExistingVersion
 LangString T_AlreadyInstalled ${LANG_ENGLISH} \
-    "has already been installed.$\r$\nDo you want to\
-    continue the installation of ${productname_short} ${version_date}?"
+    "has already been installed.$\r$\nDo you want to \
+    uninstall it and continue the installation of\r\n\
+    ${productname_short} ${version_date}?"
 # From Custom Welcome Page
 #
 # Title

Modified: trunk/packaging/makeinstaller.py
===================================================================
--- trunk/packaging/makeinstaller.py	2011-07-06 10:53:06 UTC (rev 353)
+++ trunk/packaging/makeinstaller.py	2011-07-06 10:53:34 UTC (rev 354)
@@ -29,7 +29,7 @@
         "company" : "Intevation GmbH",
         "productname" : "GREAT-ER III PGSQL",
         "setupname" : "Greater-Installer",
-        "license" : os.path.join("GREAT-ER", "COPYING"),
+        "license" : os.path.abspath(os.path.join("GREAT-ER", "COPYING")),
         "copyright" : "Copyright (c) %s Intevation GmbH" % time.strftime("%Y"),
         "productname_short" : "GREAT-ER",
         "description" : ("Geo-referenced Regional Exposure "
@@ -41,7 +41,7 @@
 INSTALLER_OPTIONS["setupname" ] = INSTALLER_OPTIONS[ "setupname" ] + \
                                "-%s.exe" % time.strftime("%Y-%m-%d-%H-%M")
 
-def traverse(self, directory, whitelist = lambda f: True):
+def traverse(directory, whitelist = lambda f: True):
     '''
         Traverse through a directory tree and return every
         dirname and filename that the function whitelist returns as true
@@ -53,42 +53,61 @@
             f = os.path.join(mypath, f)
             if os.path.isdir(f):
                 dirs.append(f)
-                yield f
             elif os.path.isfile(f) and whitelist(f):
                 yield f
 
+def generate_files(dirs, in_name, un_name, whitelist = lambda f: True):
+    curoutpath = None
+    dirlist = []
+    fptr, unptr = (open(in_name, "w"), open(un_name, "w"))
+    for dir in dirs:
+        dir = os.path.abspath(dir)
+        for fname in traverse(dir, whitelist):
+            if os.path.dirname(fname) != curoutpath:
+                curoutpath = os.path.dirname(fname)
+                fptr.write('SetOutPath "%s"\r\n' % \
+                            curoutpath.replace(dir, "$INSTDIR"))
+                dirlist.insert(0, curoutpath.replace(dir, "$INSTDIR"))
+            else:
+                fptr.write('File "%s"\r\n' % fname)
+                unptr.write('Delete "%s"\r\n' % \
+                        fname.replace(dir, "$INSTDIR"))
+    for dir in dirlist:
+        unptr.write('RMDir "%s"\r\n' % dir)
+
+    fptr.close()
+    unptr.close()
+    return (os.path.abspath(in_name), os.path.abspath(un_name))
+
 def generate_clientfiles():
-    pass
+    instdirs = ["GREAT-ER", "GREAT-ERModel", "GREAT-ER-DB"]
+    def whitelist(f):
+        for bad in [".svn", "postgres", ".pyc"]:
+            if bad in f:
+                return False
+        return True
+    return generate_files(instdirs, "client-in.nsi", "client-un.nsi", whitelist)
 
 def generate_serverfiles():
     pass
 
-def generate_allfiles():
-    instdirs = ["GREAT-ER", "GREAT-ERModel", "GREAT-ER-DB"]
-
-    with fptr as open("allfiles.nsi", "w"):
-        for dir in instdirs:
-            dir = os.path.abspath(os.path.join("..", dir))
-        for fname in traverse(dir):
-            if os.path.isdir(fname):
-                fptr.write('${SetOutPath} "\%s"\r\n' % fname.replace(dir,
-                                                        "$INSTDIR"))
-            else:
-                fptr.write('${File} "%s"\r\n' % fname)
-
-    return os.path.abspath("allfiles.nsi")
-
 def main():
-    INSTALLER_OPTIONS["clientfiles"] = generate_clientfiles()
-    INSTALLER_OPTIONS["serverfiles"] = generate_serverfiles()
-    INSTALLER_OPTIONS["allfiles"] = generate_allfiles()
+    (INSTALLER_OPTIONS["client-in"],
+     INSTALLER_OPTIONS["client-un"]) = generate_clientfiles()
+#     INSTALLER_OPTIONS["admin-in"]
+#     INSTALLER_OPTIONS["serverfiles"]) = generate_serverfiles()
+#    INSTALLER_OPTIONS["allfiles"],
+#    INSTALLER_OPTIONS["un-allfiles"] = generate_allfiles()
 
     cmd = ["makensis"]
-    for key, value in INSTALLER_OPTIONS:
-        cmd.append("/D%s=%s" % key, value)
+    for key in INSTALLER_OPTIONS:
+        cmd.append('/D%s=%s' % (key, INSTALLER_OPTIONS[key]))
     cmd.append(os.path.join("packaging", "greater-installer.nsi"))
+    print "Calling NSIS with command: \n %s " % " ".join(cmd)
+    try:
+        run.capture_output(cmd, env = os.environ.copy(), shell=True)
+    except run.SubprocessError, e:
+        print e.output[:-20]
 
-    run.call(cmd)
-
 if __name__ == '__main__':
     main()



More information about the Greater-commits mailing list