Added support for Bitcoin URIs on OS X. Implements #209
[electrum-nvc.git] / setup-release.py
1 """
2 py2app/py2exe build script for Electrum Litecoin
3
4 Usage (Mac OS X):
5      python setup.py py2app
6
7 Usage (Windows):
8      python setup.py py2exe
9 """
10
11 import sys, os, shutil, re
12 from setuptools import setup
13 from lib.version import ELECTRUM_VERSION as version
14 from lib.util import print_error
15
16
17 name = "Electrum"
18 mainscript = 'electrum'
19
20 if sys.version_info[:3] < (2,6,0):
21     print_error("Error: " + name + " requires Python version >= 2.6.0...")
22     sys.exit(1)
23
24 if sys.platform == 'darwin':
25     from plistlib import Plist
26     plist = Plist.fromFile('Info.plist')
27     plist.update(dict(CFBundleIconFile='electrum.icns'))
28
29     shutil.copy(mainscript, mainscript + '.py')
30     mainscript += '.py'
31     extra_options = dict(
32         setup_requires=['py2app'],
33         app=[mainscript],
34         options=dict(py2app=dict(argv_emulation=True,
35                                  includes = ['PyQt4.QtCore','PyQt4.QtGui', 'sip'],
36                                  packages = ['lib', 'gui', 'plugins'],
37                                  iconfile='electrum.icns',
38                                  plist=plist,
39                                  resources=["data", "icons"])),
40     )
41 elif sys.platform == 'win32':
42     extra_options = dict(
43         setup_requires=['py2exe'],
44         app=[mainscript],
45     )
46 else:
47     extra_options = dict(
48         # Normally unix-like platforms will use "setup.py install"
49         # and install the main script as such
50         scripts=[mainscript],
51     )
52
53 setup(
54     name = name,
55     version = version,
56     **extra_options
57 )
58 from distutils import dir_util
59
60 if sys.platform == 'darwin':
61     # Remove the copied py file
62     os.remove(mainscript)
63     resource = "dist/" + name + ".app/Contents/Resources/"
64
65     dir_util.copy_tree("locale", resource + "locale/")
66     # Try to locate qt_menu
67     # Let's try the port version first!
68     if os.path.isfile("/opt/local/lib/Resources/qt_menu.nib"):
69       qt_menu_location = "/opt/local/lib/Resources/qt_menu.nib"
70     else:
71       # No dice? Then let's try the brew version
72       qt_menu_location = os.popen("find /usr/local/Cellar -name qt_menu.nib | tail -n 1").read()
73       qt_menu_location = re.sub('\n','', qt_menu_location)
74
75     if(len(qt_menu_location) == 0):
76       print "Sorry couldn't find your qt_menu.nib this probably won't work"
77     else:
78       print "Found your qib: " + qt_menu_location
79
80     # Need to include a copy of qt_menu.nib
81     shutil.copytree(qt_menu_location, resource + "qt_menu.nib")
82     # Need to touch qt.conf to avoid loading 2 sets of Qt libraries
83     fname = resource + "qt.conf"
84     with file(fname, 'a'):
85         os.utime(fname, None)