diff --git a/__init__.py b/__init__.py index 24953e8..5973df8 100644 --- a/__init__.py +++ b/__init__.py @@ -1,7 +1,5 @@ -# -*- coding: UTF-8 -*- -# -*- Mode: Python; py-indent-offset: 4 -*- # -# Copyright (c) 2006 Helmut Merz helmutm@cy55.de +# Copyright (c) 2008 Helmut Merz helmutm@cy55.de # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -22,5 +20,3 @@ $Id$ """ - -#from loops.base import Loops diff --git a/deploy/library.zip b/deploy/library.zip new file mode 100644 index 0000000..1b9a773 Binary files /dev/null and b/deploy/library.zip differ diff --git a/deploy/loops.nsi b/deploy/loops.nsi new file mode 100644 index 0000000..35bb788 --- /dev/null +++ b/deploy/loops.nsi @@ -0,0 +1,118 @@ +; Script generated by the HM NIS Edit Script Wizard. + +; HM NIS Edit Wizard helper defines +!define PRODUCT_NAME "loops" +!define PRODUCT_VERSION "0.4" +!define PRODUCT_PUBLISHER "cyberconcepts" +!define PRODUCT_WEB_SITE "http://www.cyberconcepts.de" +!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\loops.exe" +!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" +!define PRODUCT_UNINST_ROOT_KEY "HKLM" +!define PRODUCT_STARTMENU_REGVAL "NSIS:StartMenuDir" +!define PRODUCT_ROOT "Z:\home\helmutm\deploy\loops\windows\loops" + +; MUI 1.67 compatible ------ +!include "MUI.nsh" + +; MUI Settings +!define MUI_ABORTWARNING +!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico" +!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico" + +; Welcome page +!insertmacro MUI_PAGE_WELCOME +; License page +;!insertmacro MUI_PAGE_LICENSE "${PRODUCT_ROOT}\license.txt" +; Directory page +!insertmacro MUI_PAGE_DIRECTORY +; Start menu page +var ICONS_GROUP +!define MUI_STARTMENUPAGE_NODISABLE +!define MUI_STARTMENUPAGE_DEFAULTFOLDER "loops" +!define MUI_STARTMENUPAGE_REGISTRY_ROOT "${PRODUCT_UNINST_ROOT_KEY}" +!define MUI_STARTMENUPAGE_REGISTRY_KEY "${PRODUCT_UNINST_KEY}" +!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "${PRODUCT_STARTMENU_REGVAL}" +!insertmacro MUI_PAGE_STARTMENU Application $ICONS_GROUP +; Instfiles page +!insertmacro MUI_PAGE_INSTFILES +; Finish page +!define MUI_FINISHPAGE_RUN "$INSTDIR\loopsw.exe" +!insertmacro MUI_PAGE_FINISH + +; Uninstaller pages +!insertmacro MUI_UNPAGE_INSTFILES + +; Language files +!insertmacro MUI_LANGUAGE "English" +!insertmacro MUI_LANGUAGE "German" + +; MUI end ------ + +Name "${PRODUCT_NAME} ${PRODUCT_VERSION}" +OutFile "Setup.exe" +InstallDir "$PROGRAMFILES\loops" +InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" "" +ShowInstDetails show +ShowUnInstDetails show + +Section "Hauptgruppe" SEC01 + SetOutPath "$INSTDIR" + SetOverwrite ifnewer + File /r "${PRODUCT_ROOT}\*" + +; Shortcuts + !insertmacro MUI_STARTMENU_WRITE_BEGIN Application + CreateDirectory "$SMPROGRAMS\$ICONS_GROUP" + CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\loops.lnk" "$INSTDIR\loopsw.exe" + ;CreateShortCut "$DESKTOP\LearnSim.lnk" "$INSTDIR\learnsimw.exe" + !insertmacro MUI_STARTMENU_WRITE_END +SectionEnd + +Section -AdditionalIcons + !insertmacro MUI_STARTMENU_WRITE_BEGIN Application + WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}" + ;CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url" + CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Uninstall.lnk" "$INSTDIR\uninst.exe" + !insertmacro MUI_STARTMENU_WRITE_END +SectionEnd + +Section -Post + WriteUninstaller "$INSTDIR\uninst.exe" + WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\AppMainExe.exe" + WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)" + WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe" + WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\start.exe" + WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}" + ;WriteRegStr ${PRODUCT_UNINSTs_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}" + WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}" +SectionEnd + + +Function un.onUninstSuccess + HideWindow + MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) wurde erfolgreich deinstalliert." +FunctionEnd + +Function un.onInit + MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "M�hten Sie $(^Name) und alle seinen Komponenten deinstallieren?" IDYES +2 + Abort +FunctionEnd + +Section Uninstall + !insertmacro MUI_STARTMENU_GETFOLDER "Application" $ICONS_GROUP + Delete "$INSTDIR\${PRODUCT_NAME}.url" + Delete "$INSTDIR\uninst.exe" + Delete "$INSTDIR\start.exe" + + Delete "$SMPROGRAMS\$ICONS_GROUP\Uninstall.lnk" + ;Delete "$SMPROGRAMS\$ICONS_GROUP\Website.lnk" + ;Delete "$DESKTOP\LearnSim.lnk" + Delete "$SMPROGRAMS\$ICONS_GROUP\loopsm.lnk" + + RMDir "$SMPROGRAMS\$ICONS_GROUP" + RMDir "$INSTDIR" + + DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" + DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}" + SetAutoClose true +SectionEnd \ No newline at end of file diff --git a/deploy/make_setup b/deploy/make_setup new file mode 100755 index 0000000..3a3bed9 --- /dev/null +++ b/deploy/make_setup @@ -0,0 +1,39 @@ +#! /bin/bash +# +# produce Setup.exe +# call this script directly from the deploy directory +# +# $Id$ +# + +DEVELOPMENT_INSTANCE=/home/33zope/mz +LIB_SOURCE=$DEVELOPMENT_INSTANCE/lib/python +LIB_DEST=instance/lib/python +NSIS_EXE=c:\\programme\\nsis\\makensis.exe + +cd ../loops + +echo removing $LIB_DEST directories +rm -rf $LIB_DEST/cybertools +rm -rf $LIB_DEST/loops + +echo copying $LIB_SOURCE to $LIB_DEST +cp -pr $LIB_SOURCE/cybertools $LIB_DEST +cp -pr $LIB_SOURCE/loops $LIB_DEST + +echo removing $LIB_DEST/loops/deploy +rm -rf $LIB_DEST/loops/deploy + +echo removing .py files from $LIB_DEST +python ../deploy/remove_sourcefiles.py $LIB_DEST/cybertools +python ../deploy/remove_sourcefiles.py $LIB_DEST/loops + +echo inserting main.pyc into library.zip +cp $LIB_DEST/loops/main.pyc . +zip library.zip main.pyc +rm main.pyc + +cd ../deploy + +#echo creating setup.exe with NSIS +#wine $NSIS_EXE loops.nsi diff --git a/deploy/remove_sourcefiles.py b/deploy/remove_sourcefiles.py new file mode 100755 index 0000000..b484e82 --- /dev/null +++ b/deploy/remove_sourcefiles.py @@ -0,0 +1,54 @@ +#! /usr/bin/env python + +""" +Remove .py and (if .pyo files present) .pyc from the directory given. + +$Id$ +""" + +import os, sys + + +def removeSourceFiles(path): + for root, dirs, files in os.walk(path): + for d in dirs: + if d == '.svn': + removeDirectory(os.path.join(root, d)) + for f in list(files): + if f == 'README.txt': + os.unlink(os.path.join(root, f)) + continue + name, ext = os.path.splitext(f) + pyc = name + '.pyc' + pycPath = os.path.join(root, pyc) + pyo = name + '.pyo' + pyoPath = os.path.join(root, pyo) + py = name + '.py' + pyPath = os.path.join(root, py) + if ext == '.pyc': + if pyo in files: + print pyoPath, + files.remove(pyo) + os.unlink(pyoPath) + if py in files: + print pyPath, + files.remove(py) + os.unlink(pyPath) + elif ext == '.pyo': + if py in files: + print pyPath, + files.remove(py) + os.unlink(pyPath) + +def removeDirectory(path): + for root, dirs, files in os.walk(path): + for f in files: + os.unlink(os.path.join(root, f)) + for d in dirs: + removeDirectory(os.path.join(root, d)) + os.rmdir(path) + + +if __name__ == '__main__': + removeSourceFiles(sys.argv[1]) + diff --git a/deploy/start.py b/deploy/start.py new file mode 100755 index 0000000..c3be19c --- /dev/null +++ b/deploy/start.py @@ -0,0 +1,10 @@ +#! /usr/bin/env python + +""" Start script using a standardized entry point: main.main() + + $Id$ +""" + +from main import main +main() + diff --git a/main.py b/main.py new file mode 100644 index 0000000..cf600bd --- /dev/null +++ b/main.py @@ -0,0 +1,108 @@ +#! /usr/bin/env python +# +# Copyright (c) 2008 Helmut Merz helmutm@cy55.de +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +""" +Entry point for the loops application. + +$Id$ +""" + +import os, sys + + +softwareHome = None +instanceHome = configFile = None + + +def setWindowsEnvironment(): + global softwareHome, instanceHome, configFile + basedir = os.path.dirname(os.path.realpath(__file__)) + if basedir.endswith('library.zip'): + basedir = os.path.dirname(basedir) + libdir = os.path.join(basedir, 'Lib') + softwareHome = os.path.join(libdir, 'site-packages') + instanceHome = os.path.join(basedir, 'instance') + configFile = os.path.join(instanceHome, 'etc', 'zope.conf') + sys.path.insert(0, libdir) + sys.path.insert(0, softwareHome) + sys.path.insert(0, os.path.join(basedir, 'DLLs')) + sys.path.insert(0, os.path.join(instanceHome, 'lib', 'python')) + + +def setZopeEnvironment(): + global softwareHome, instanceHome, configFile + curdir = os.path.dirname(os.path.realpath(__file__)) + #for i in range(5): + for i in range(3): + curdir = os.path.dirname(curdir) + instanceHome = curdir + if softwareHome is None: + softwareHome = os.path.join(os.path.dirname(instanceHome), 'lib', 'python') + configFile = os.path.join(instanceHome, 'etc', 'zope.conf') + sys.path[:] = sys.path[1:] # remove script directory + sys.path.insert(0, softwareHome) + sys.path.insert(0, os.path.join(instanceHome, 'lib', 'python')) + os.environ['USE_RLIBRARY'] = '' # do not use the R statistics library + + +def setInstanceHomeInZopeConf(): + zc = open(configFile) + l1 = zc.readline() + rest = zc.read() + zc.close() + command, key, value = [w.strip() for w in l1.split()] + if command == '%define' and key == 'INSTANCE' and value != instanceHome: + print 'INSTANCE variable changed from %s to %s.' % (value, instanceHome) + l1 = ' '.join((command, key, instanceHome)) + '\n' + zc = open(configFile, 'w') + zc.write(l1) + zc.write(rest) + zc.close() + + +def startZope(configFile): + # set up the agent application + from cybertools.agent.main import setup + #setup() + # start Zope using the twisted server + from zope.app.twisted.main import main + try: + main(["-C", configFile]) + except IOError, e: + if str(e) == '[Errno 11] Resource temporarily unavailable': + print 'WARNING: Background process already running.' + #from startup import openBrowser + #openBrowser(None) + + +def main(): + """ Called from loops.exe (=deploy/start.py). """ + setWindowsEnvironment() + setInstanceHomeInZopeConf() + startZope(configFile) + + +def mainZope(): + """ Start in a regular Zope instance. """ + setZopeEnvironment() + startZope(configFile) + + +if __name__ == '__main__': + mainZope()