-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_via_cx.py
144 lines (115 loc) · 63.4 KB
/
build_via_cx.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# ----------------------------------------------------
# Build the LF daq distro using cx_freeze:
# (writing this one because bb_freeze is totally unsupported)
# Started by: Austin Sousa
# 4.17.2018
#
# Usage instructions:
# python build_via_cx.py build
#
#
# ----------------------------------------------------
import os
import sys
from cx_Freeze import setup, Executable
import subprocess
import shutil
from datetime import datetime
import multiprocessing
# multiprocessing.freeze_support()
# Genearte version number automatically on compile
current_time = datetime.today()
__ver__ = current_time.strftime("%Y.%m%d")
# __ver__ = "2018.0417.20"
if os.name != 'nt':
__ver__ += 'L'
if os.name == 'posix':
fid = open('__ver__.py',"w")
fid.write("#Autogenerated by compile script\n\n__ver__ = '%s'" % __ver__)
fid.close()
if os.name=='nt':
# Generate batch file
f = open('__ver__.py','w')
f.write("#Autogenerated by compile script\n\n__ver__ = '%s'" % __ver__)
f.close()
# Libraries to include
packages = ("matplotlib","numpy","scipy",
"PostProcessors","DaqCards","GpsClocks","Tasks",
"paramiko","email","Tkinter","tkFileDialog","FileDialog")
# Libraries to exclude
excludes = ('py_readline','setuptools','Traits','_gtkagg', '_agg2',
'_cairo', '_cocoaagg','_fltkagg', '_gtk', '_gtkcairo',
'win32api','win32wnet','mpl_toolkits.basemap','processing',
'Gnuplot','PyQt4','gdata','atom','PyQt5','gtk')
# Root modules to do
# GUI applications require a different base on Windows (the default is for a console application).
execs = [Executable('main.py',icon='lair_icon.ico'),
Executable('SerialChecker.py',icon='lair_icon.ico'),
Executable('settings_generator.py',icon='lair_icon.ico'),
Executable('GUI.py', base='Win32GUI',icon='lair_icon.ico'),
Executable('calibrate_LF.py',icon='lair_icon.ico')]
# Set output build path:
build_root = '.\\Builds'
build_subdir = 'LF_DAQ_DISTRO-%s'%__ver__
build_dir = os.path.join(build_root,build_subdir)
software_dir = os.path.join(build_dir, 'software')
if not os.path.exists(build_root):
os.mkdir(build_root)
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": packages,
"excludes": excludes,
"zip_exclude_packages": ['tkFileDialog'],
"optimize" : 2,
"include_msvcr":True,
"build_exe": software_dir}
# GUI applications require a different base on Windows (the default is for a
# console application).
# base = None
print "Building..."
# Link and build, link and build
setup( name = "LF DAQ",
version = __ver__,
description = "CU-LAIR LF DAQ",
options = {"build_exe": build_exe_options},
executables = execs)
print "copying misc files..."
# Copy data files for the GUI:
folders_to_copy = ['icons'] #no recursive
for folder in folders_to_copy:
dest_dir = os.path.join(software_dir,folder)
if not os.path.exists(dest_dir):
os.mkdir(dest_dir)
files = os.listdir(folder)
for afile in files:
src = os.path.join(folder,afile)
if os.path.isfile(src):
shutil.copy(src,os.path.join(dest_dir,afile))
# Run the default settings generators
print "Generating default settings files..."
subprocess.call('python settings_generator.py --c=default_LF_settings.txt --f=DaqSettings.xml')
# subprocess.call('python settings_generator.py --c=default_VLF_settings.txt')
# Copy default settings files:
subprocess.call('copy default_LF_settings.txt %s\settings_LF.txt'%build_dir, shell=True)
subprocess.call('copy default_VLF_settings.txt %s\settings_VLF.txt'%build_dir, shell=True)
subprocess.call('copy DaqSettings.xml %s\DaqSettings.xml'%build_dir, shell=True)
subprocess.call('copy nb.conf %s\nb.conf'%build_dir, shell=True)
print('copy filter_taps.txt %s\\filter_taps.txt'%build_dir)
subprocess.call('copy filter_taps.txt %s\\filter_taps.txt'%build_dir, shell=True)
# Build the .bat run scripts:
print "Writing batch files..."
with open(os.path.join(build_dir,"main.bat"),'w') as f:
f.write('start "VLF_DAQ" /realtime %s --a --s=DaqSettings.xml' % os.path.join('software','main.exe'))
with open(os.path.join(build_dir,"main_debug.bat"),'w') as f:
f.write('%s --a --s=DaqSettings.xml' % os.path.join('software','main.exe'))
with open(os.path.join(build_dir,"SerialChecker.bat"),'w') as f:
f.write('%s --search' % os.path.join('software','SerialChecker.exe'))
f.write('\npause\n')
with open(os.path.join(build_dir,"Make_DaqSettings_for_LF.bat"),'w') as f:
f.write('%s --c=settings_LF.txt --f=DaqSettings.xml\n'%os.path.join('software','settings_generator.exe'))
f.write('\npause\n')
with open(os.path.join(build_dir,"Make_DaqSettings_for_VLF.bat"),'w') as f:
f.write('%s --c=settings_VLF.txt --f=DaqSettings.xml\n'%os.path.join('software','settings_generator.exe'))
f.write('\npause\n')
with open(os.path.join(build_dir,'Calibration.bat'),'w') as f:
f.write('%s'%os.path.join('software','calibrate_LF.exe'))