2008-08-25 20:36:05 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
2008-08-22 04:34:44 +00:00
|
|
|
import os
|
2009-02-23 08:11:48 +00:00
|
|
|
import os.path
|
2008-08-21 20:52:18 +00:00
|
|
|
import sys
|
|
|
|
from glob import glob
|
2008-08-21 21:54:39 +00:00
|
|
|
from distutils.core import setup, Distribution
|
2008-08-26 02:45:20 +00:00
|
|
|
from config.Version import VERSION
|
2008-08-22 04:34:44 +00:00
|
|
|
|
|
|
|
|
2008-08-26 03:21:54 +00:00
|
|
|
def files( path, excludes = None ):
|
|
|
|
if excludes is None:
|
|
|
|
excludes = []
|
|
|
|
|
2008-08-21 21:54:39 +00:00
|
|
|
if sys.platform.startswith( "win" ):
|
|
|
|
path = path.replace( "/", "\\" )
|
|
|
|
|
2008-08-26 03:21:54 +00:00
|
|
|
files_in_path = glob( path )
|
|
|
|
|
|
|
|
for exclude in excludes:
|
|
|
|
if sys.platform.startswith( "win" ):
|
|
|
|
exclude = exclude.replace( "/", "\\" )
|
|
|
|
|
|
|
|
for file_to_exclude in glob( exclude ):
|
|
|
|
try:
|
|
|
|
files_in_path.remove( file_to_exclude )
|
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
return files_in_path
|
2008-08-21 21:54:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Luminotes( Distribution ):
|
|
|
|
def __init__( self, attrs ):
|
2008-08-21 22:01:47 +00:00
|
|
|
self.ctypes_com_server = []
|
2008-08-21 21:58:36 +00:00
|
|
|
self.com_server = []
|
|
|
|
self.services = []
|
2008-08-22 23:48:22 +00:00
|
|
|
self.windows = [ dict(
|
|
|
|
script = "luminotes.py",
|
|
|
|
icon_resources = [ ( 0, "static\\images\\luminotes.ico" ) ],
|
|
|
|
) ]
|
2008-08-22 05:36:57 +00:00
|
|
|
self.console = []
|
2008-08-21 22:01:47 +00:00
|
|
|
self.service = []
|
|
|
|
self.isapi = []
|
2008-08-22 04:34:44 +00:00
|
|
|
self.zipfile = "lib\luminotes.zip"
|
2008-08-21 21:54:39 +00:00
|
|
|
Distribution.__init__( self, attrs )
|
|
|
|
|
2008-08-21 20:52:18 +00:00
|
|
|
|
2008-08-22 04:34:44 +00:00
|
|
|
manifest_template = '''
|
|
|
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
|
|
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
|
|
|
<assemblyIdentity
|
|
|
|
version="5.0.0.0"
|
|
|
|
processorArchitecture="x86"
|
|
|
|
name="%(prog)s"
|
|
|
|
type="win32"
|
|
|
|
/>
|
|
|
|
<description>%(prog)s Program</description>
|
|
|
|
<dependency>
|
|
|
|
<dependentAssembly>
|
|
|
|
<assemblyIdentity
|
|
|
|
type="win32"
|
|
|
|
name="Microsoft.Windows.Common-Controls"
|
|
|
|
version="6.0.0.0"
|
|
|
|
processorArchitecture="X86"
|
|
|
|
publicKeyToken="6595b64144ccf1df"
|
|
|
|
language="*"
|
|
|
|
/>
|
|
|
|
</dependentAssembly>
|
|
|
|
</dependency>
|
|
|
|
</assembly>
|
|
|
|
'''
|
|
|
|
|
|
|
|
RT_MANIFEST = 24
|
|
|
|
|
|
|
|
luminotes = dict(
|
|
|
|
script = "luminotes.py",
|
|
|
|
other_resources = [(RT_MANIFEST, 1, manifest_template % dict(prog="Luminotes"))],
|
|
|
|
dest_base = r"prog\luminotes")
|
|
|
|
|
|
|
|
class InnoScript:
|
|
|
|
def __init__(self,
|
|
|
|
name,
|
|
|
|
lib_dir,
|
|
|
|
dist_dir,
|
|
|
|
windows_exe_files = [],
|
|
|
|
lib_files = [],
|
|
|
|
version = "1.0"):
|
|
|
|
self.lib_dir = lib_dir
|
|
|
|
self.dist_dir = dist_dir
|
|
|
|
if not self.dist_dir[-1] in "\\/":
|
|
|
|
self.dist_dir += "\\"
|
|
|
|
self.name = name
|
|
|
|
self.version = version
|
|
|
|
self.windows_exe_files = [self.chop(p) for p in windows_exe_files]
|
|
|
|
self.lib_files = [self.chop(p) for p in lib_files]
|
|
|
|
|
|
|
|
def chop(self, pathname):
|
|
|
|
assert pathname.startswith(self.dist_dir)
|
|
|
|
return pathname[len(self.dist_dir):]
|
|
|
|
|
|
|
|
def create(self, pathname="dist\\luminotes.iss"):
|
|
|
|
self.pathname = pathname
|
|
|
|
ofi = self.file = open(pathname, "w")
|
|
|
|
print >> ofi, "; WARNING: This script has been created by py2exe. Changes to this script"
|
|
|
|
print >> ofi, "; will be overwritten the next time py2exe is run!"
|
|
|
|
print >> ofi, r"[Setup]"
|
|
|
|
print >> ofi, r"AppName=%s" % self.name
|
|
|
|
print >> ofi, r"AppVerName=%s %s" % (self.name, self.version)
|
|
|
|
print >> ofi, r"DefaultDirName={pf}\%s" % self.name
|
2008-08-24 05:51:03 +00:00
|
|
|
print >> ofi, r"DisableProgramGroupPage=yes"
|
2008-08-23 00:31:09 +00:00
|
|
|
print >> ofi, r"SetupIconFile=static\images\luminotes.ico"
|
2008-08-26 22:42:55 +00:00
|
|
|
print >> ofi, r"WizardImageFile=static\images\installer.bmp"
|
|
|
|
print >> ofi, r"WizardSmallImageFile=static\images\installer_small.bmp"
|
2008-08-22 04:34:44 +00:00
|
|
|
print >> ofi
|
|
|
|
|
|
|
|
print >> ofi, r"[Files]"
|
|
|
|
for path in self.windows_exe_files + self.lib_files:
|
2008-08-26 02:20:27 +00:00
|
|
|
if path.endswith( "README.txt" ):
|
|
|
|
extra = " isreadme"
|
|
|
|
elif path.endswith( "luminotes.exe" ):
|
2008-08-25 22:15:15 +00:00
|
|
|
extra = "; BeforeInstall: stop_exe()"
|
|
|
|
else:
|
|
|
|
extra = ""
|
|
|
|
print >> ofi, r'Source: "%s"; DestDir: "{app}\%s"; Flags: ignoreversion%s' % (path, os.path.dirname(path), extra)
|
2008-08-22 04:34:44 +00:00
|
|
|
print >> ofi
|
|
|
|
|
|
|
|
print >> ofi, r"[Icons]"
|
|
|
|
for path in self.windows_exe_files:
|
2008-08-24 05:51:03 +00:00
|
|
|
print >> ofi, r'Name: "{commonprograms}\%s"; Filename: "{app}\%s"' % \
|
2008-08-22 04:34:44 +00:00
|
|
|
(self.name, path)
|
2008-08-25 21:20:13 +00:00
|
|
|
print >> ofi
|
|
|
|
|
2008-08-23 23:45:34 +00:00
|
|
|
print >> ofi, r"[UninstallDelete]"
|
|
|
|
print >> ofi, r'Type: files; Name: "{app}\luminotes.log"'
|
2008-08-24 03:00:00 +00:00
|
|
|
print >> ofi, r'Type: files; Name: "{app}\luminotes_error.log"'
|
2008-08-23 23:45:34 +00:00
|
|
|
print >> ofi
|
|
|
|
|
2008-08-23 01:37:31 +00:00
|
|
|
print >> ofi, r"[UninstallRun]"
|
|
|
|
print >> ofi, r'Filename: "{app}\luminotes.exe"; Parameters: "-k"; RunOnceId: LuminotesShutdown'
|
2008-08-25 22:15:15 +00:00
|
|
|
print >> ofi
|
|
|
|
|
|
|
|
print >> ofi, r"[Code]"
|
|
|
|
print >> ofi, r"procedure stop_exe();"
|
|
|
|
print >> ofi, r"var"
|
|
|
|
print >> ofi, r" result_code: Integer;"
|
|
|
|
print >> ofi, r"begin"
|
|
|
|
print >> ofi, r" Exec( ExpandConstant('{app}\luminotes.exe'), '-k', '', SW_SHOW, ewWaitUntilTerminated, result_code)"
|
|
|
|
print >> ofi, r"end;"
|
2008-08-22 04:34:44 +00:00
|
|
|
|
|
|
|
def compile(self):
|
2009-02-23 08:11:48 +00:00
|
|
|
import os
|
|
|
|
if os.environ.get( "CYGWIN" ):
|
|
|
|
print "Running in Cygwin, so skipping compile"
|
|
|
|
return
|
|
|
|
|
2008-08-22 04:34:44 +00:00
|
|
|
try:
|
|
|
|
import ctypes
|
|
|
|
except ImportError:
|
|
|
|
try:
|
|
|
|
import win32api
|
|
|
|
except ImportError:
|
|
|
|
import os
|
|
|
|
os.startfile(self.pathname)
|
|
|
|
else:
|
|
|
|
print "Ok, using win32api."
|
|
|
|
win32api.ShellExecute(0, "compile",
|
|
|
|
self.pathname,
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
0)
|
|
|
|
else:
|
|
|
|
print "Cool, you have ctypes installed."
|
|
|
|
res = ctypes.windll.shell32.ShellExecuteA(0, "compile",
|
|
|
|
self.pathname,
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
0)
|
|
|
|
if res < 32:
|
|
|
|
raise RuntimeError, "ShellExecute failed, error %d" % res
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-08-22 05:01:59 +00:00
|
|
|
try:
|
|
|
|
import py2exe
|
|
|
|
from py2exe.build_exe import py2exe
|
|
|
|
|
2008-08-24 05:28:13 +00:00
|
|
|
class Build_installer( py2exe ):
|
2008-08-22 05:01:59 +00:00
|
|
|
# This class first builds the exe file(s), then creates a Windows installer.
|
|
|
|
# You need InnoSetup for it.
|
2008-08-24 05:28:13 +00:00
|
|
|
def run( self ):
|
2008-08-22 05:01:59 +00:00
|
|
|
# generate an initial database file
|
|
|
|
try:
|
|
|
|
os.remove( "luminotes.db" )
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
from tools import initdb
|
|
|
|
initdb.main( ( "-l", ) )
|
|
|
|
|
2008-08-24 05:28:13 +00:00
|
|
|
# copy the README and COPYING files to have ".txt" extensions and Windows newlines
|
|
|
|
self.copy_doc( "README" )
|
|
|
|
self.copy_doc( "COPYING" )
|
|
|
|
|
2008-08-22 05:01:59 +00:00
|
|
|
# First, let py2exe do it's work.
|
|
|
|
py2exe.run(self)
|
|
|
|
|
|
|
|
lib_dir = self.lib_dir
|
|
|
|
dist_dir = self.dist_dir
|
|
|
|
|
|
|
|
# create the Installer, using the files py2exe has created.
|
|
|
|
script = InnoScript("Luminotes",
|
|
|
|
lib_dir,
|
|
|
|
dist_dir,
|
2008-08-22 05:36:57 +00:00
|
|
|
self.windows_exe_files,
|
2008-08-22 05:01:59 +00:00
|
|
|
self.lib_files,
|
2008-08-26 02:45:20 +00:00
|
|
|
version = VERSION)
|
2008-08-22 05:01:59 +00:00
|
|
|
print "*** creating the inno setup script***"
|
|
|
|
script.create()
|
|
|
|
print "*** compiling the inno setup script***"
|
|
|
|
script.compile()
|
|
|
|
# Note: By default the final setup.exe will be in an Output subdirectory.
|
2008-08-24 05:28:13 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def copy_doc( path ):
|
|
|
|
out = file( "%s.txt" % path, "w" )
|
|
|
|
|
|
|
|
for line in file( path ).readlines():
|
|
|
|
line = line.rstrip( "\r\n" )
|
|
|
|
out.write( "%s\r\n" % line )
|
|
|
|
|
|
|
|
out.close()
|
|
|
|
|
2008-08-22 05:01:59 +00:00
|
|
|
except ImportError:
|
|
|
|
class Build_installer:
|
|
|
|
pass
|
2008-08-22 04:34:44 +00:00
|
|
|
|
|
|
|
|
2008-08-25 20:36:05 +00:00
|
|
|
if "py2exe" in sys.argv[ 1: ]:
|
|
|
|
txt_extension = ".txt"
|
|
|
|
else:
|
|
|
|
txt_extension = ""
|
|
|
|
|
|
|
|
data_files = [
|
|
|
|
( "", [ "README%s" % txt_extension, ] ),
|
|
|
|
( "", [ "COPYING%s" % txt_extension, ] ),
|
|
|
|
( "", [ "luminotes.db", ] ),
|
2008-08-27 20:02:11 +00:00
|
|
|
( "", [ "tools/usb_luminotes.bat" ] ),
|
2008-08-25 20:36:05 +00:00
|
|
|
( "static/css", files( "static/css/*.*" ) ),
|
|
|
|
( "static/html", files( "static/html/*.*" ) ),
|
2008-08-26 03:21:54 +00:00
|
|
|
( "static/images", files( "static/images/*.*", excludes = [
|
|
|
|
"static/images/*.xcf",
|
|
|
|
"static/images/*screenshot*",
|
|
|
|
"static/images/*tour*",
|
|
|
|
"static/images/*index_card*",
|
|
|
|
"static/images/*thumb*",
|
2009-03-03 08:13:32 +00:00
|
|
|
"static/images/dan.png",
|
2008-08-26 03:21:54 +00:00
|
|
|
] ) ),
|
|
|
|
( "static/images/toolbar", files( "static/images/toolbar/*.*", excludes = [ "static/images/toolbar/*.xcf" ] ) ),
|
|
|
|
( "static/images/toolbar/small", files( "static/images/toolbar/small/*.*", excludes = [ "static/images/toolbar/small/*.xcf" ] ) ),
|
2009-04-28 23:19:49 +00:00
|
|
|
( "static/themes/default/images/toolbar", files( "static/themes/default/images/toolbar/*.*", excludes = [ "static/themes/default/images/toolbar/*.xcf" ] ) ),
|
|
|
|
( "static/themes/default/images/toolbar/small", files( "static/themes/default/images/toolbar/small/*.*", excludes = [ "static/themes/default/images/toolbar/small/*.xcf" ] ) ),
|
2008-08-25 20:36:05 +00:00
|
|
|
( "static/js", files( "static/js/*.*" ) ),
|
|
|
|
( "static/js", files( "static/js/*_LICENSE" ) ),
|
2008-10-24 18:51:19 +00:00
|
|
|
( "model/delta", files( "model/delta/*.sqlite" ) ),
|
2008-08-25 20:36:05 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
package_data = { ".": sum( [ pair[ 1 ] for pair in data_files ], [] ) }
|
|
|
|
|
|
|
|
|
2008-08-21 20:52:18 +00:00
|
|
|
setup(
|
2008-08-22 04:34:44 +00:00
|
|
|
name = "Luminotes",
|
|
|
|
version = VERSION,
|
|
|
|
author = "Dan Helfman",
|
|
|
|
author_email = "support@luminotes.com",
|
|
|
|
url = "http://luminotes.com",
|
|
|
|
description = "personal wiki notebook",
|
2008-08-21 21:54:39 +00:00
|
|
|
distclass = Luminotes,
|
2008-08-22 04:34:44 +00:00
|
|
|
cmdclass = { "py2exe": Build_installer }, # override default py2exe class
|
2008-08-25 20:36:05 +00:00
|
|
|
scripts = [ "luminotes.py" ],
|
|
|
|
packages = [ ".", "config", "controller", "model", "tools", "view" ],
|
|
|
|
package_dir = { ".": "." },
|
|
|
|
data_files = data_files, # for py2exe
|
|
|
|
package_data = package_data, # for everything else
|
2008-08-21 21:54:39 +00:00
|
|
|
options = dict(
|
|
|
|
py2exe = dict(
|
|
|
|
packages = "cherrypy.filters",
|
2009-02-23 08:11:48 +00:00
|
|
|
includes = "email.header,simplejson,plugins.*",
|
2008-08-22 04:34:44 +00:00
|
|
|
compressed = 1,
|
|
|
|
optimize = 2,
|
2008-08-21 21:54:39 +00:00
|
|
|
)
|
|
|
|
),
|
2008-08-21 20:52:18 +00:00
|
|
|
)
|