This repository has been archived by the owner on Jul 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
make-app.py
executable file
·122 lines (107 loc) · 3.32 KB
/
make-app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/sh
''''exec "$(dirname "$0")"/ImageJ.sh --jython "$0" "$@" # (call again with fiji)'''
import os
import shutil
import sys
from compat import chmod, execute
from java.io import File
if len(sys.argv) < 3:
print 'Usage: ' + sys.argv[0] + ' <platform> <host-platform>'
exit(1)
platform = sys.argv[1].replace('app-', '')
host_platform = sys.argv[2]
all_platforms = ['linux32', 'linux64', 'win32', 'win64', 'macosx']
if platform == 'nojre':
copy_jre = False
platform = 'all'
else:
copy_jre = True
def removedirs(dir):
if not isinstance(dir, File):
dir = File(dir)
list = dir.listFiles()
if list is None:
return
for file in list:
if file.isDirectory():
removedirs(file)
elif file.isFile():
file.delete();
dir.delete()
def make_app():
print 'Making app'
if os.path.isdir('Fiji.app'):
removedirs('Fiji.app')
os.makedirs('Fiji.app/images')
shutil.copy('images/icon.png', 'Fiji.app/images/')
for d in ['plugins', 'macros', 'jars', 'retro', 'luts', \
'scripts']:
shutil.copytree(d, 'Fiji.app/' + d)
if os.path.isdir('samples'):
shutil.copytree('samples', 'Fiji.app/samples')
if os.path.isdir('Fiji.app/jars/jython2.2.1/cachedir'):
removedirs('Fiji.app/jars/jython2.2.1/cachedir')
if os.path.isdir('Fiji.app/jars/cachedir'):
removedirs('Fiji.app/jars/cachedir')
def get_java_platform(platform):
if platform == 'linux64':
platform = 'linux-amd64'
elif platform == 'macosx':
platform = 'macosx-java3d'
return platform
def find_java_tree(platform):
java = 'java/' + platform
revision = execute('git rev-parse HEAD:' + java)
if platform == 'macosx-java3d':
return [revision.replace('\n', ''), platform]
tree = execute('git --git-dir=' + java + '/.git ls-tree ' + revision)
return [tree[12:52] + ':jre',
platform + '/' + tree[53:].replace('\n', '') + '/jre']
def copy_java(platform):
if platform == 'linux32':
platform = 'linux'
java_platform = get_java_platform(platform)
java_tree = find_java_tree(java_platform)
os.system('git --git-dir=java/' + java_platform + '/.git ' \
+ 'archive --prefix=Fiji.app/java/' + java_tree[1] + '/ ' \
+ java_tree[0] + ' | ' \
+ 'tar xf -')
def copy_platform_specific_files(platform):
if copy_jre:
print 'Copying Java files for', platform
copy_java(platform)
print 'Copying platform-specific files for', platform, \
'(host platform=' + host_platform + ')'
if platform == 'macosx':
macos='Fiji.app/Contents/MacOS/'
os.makedirs(macos)
if (host_platform == "osx10.5"):
shutil.copy('ImageJ', macos + 'ImageJ-macosx')
shutil.copy('ImageJ-tiger', macos)
else:
shutil.copy('precompiled/ImageJ-macosx',
macos + 'ImageJ-macosx')
shutil.copy('precompiled/ImageJ-tiger', macos)
chmod(macos + 'ImageJ-macosx', 0755)
chmod(macos + 'ImageJ-tiger', 0755)
shutil.copy('Contents/Info.plist', 'Fiji.app/Contents/')
images='Fiji.app/Contents/Resources/'
os.makedirs(images)
shutil.copy('images/Fiji.icns', images)
else:
if platform.startswith('win'):
exe = ".exe"
else:
exe = ''
binary = 'ImageJ-' + platform + exe
if (host_platform == platform):
shutil.copy('ImageJ' + exe, 'Fiji.app/' + binary)
else:
shutil.copy('precompiled/' + binary, 'Fiji.app/' + binary)
chmod('Fiji.app/' + binary, 0755)
make_app()
if platform == 'all':
for p in all_platforms:
copy_platform_specific_files(p)
else:
copy_platform_specific_files(platform)