|
| 1 | +################################################################################ |
| 2 | +# Copyright (c) 2017 Schneider Electric Solar Inverters USA, Inc. |
| 3 | +# |
| 4 | +# No part of this document may be reproduced in any form or disclosed to third |
| 5 | +# parties without the express written consent of: |
| 6 | +# Schneider Electric Solar Inverters USA, Inc. |
| 7 | +# |
| 8 | +# FILE NAME: |
| 9 | +# SConstruct |
| 10 | +# |
| 11 | +# PURPOSE: |
| 12 | +# Used to build the program to program the SE1 fans. |
| 13 | +# |
| 14 | +# |
| 15 | +# |
| 16 | +# NOTES: |
| 17 | +# |
| 18 | +# CHANGE HISTORY: |
| 19 | +# $Log: SConstruct $ |
| 20 | +# |
| 21 | +################################################################################ |
| 22 | + |
| 23 | +############################################################################### |
| 24 | +# Included Modules # |
| 25 | +############################################################################### |
| 26 | +import os |
| 27 | +import sys |
| 28 | +import subprocess |
| 29 | +import re |
| 30 | +import fileinput |
| 31 | +#monitor_stdout = sys.stdout |
| 32 | +################################################################################ |
| 33 | +# Defines # |
| 34 | +################################################################################ |
| 35 | +GUISOURCEFILE = 'SE1FanProgrammer.pyw' |
| 36 | +SOURCEFILES = Glob('*.py') |
| 37 | +SOURCEFILES += Glob('*.pyw') |
| 38 | +#PyInstaller Spec File |
| 39 | +SPECFILE = 'SE1FanProgrammer.spec' |
| 40 | + |
| 41 | +#Version Reg-ex Patterns |
| 42 | +SRC_PATTERN = re.compile('(^__version__\s=\s")([x\d].[x\d].[x\d]+)(")') |
| 43 | +VER_PATTERN = re.compile('([x\d].[x\d].[x\d]+)') |
| 44 | + |
| 45 | +# Inno installer stuff... |
| 46 | +ISSFILE = 'SE1FanProgrammer.iss' |
| 47 | +ISS_PATTERN = re.compile(r'(AppVerName=SE1 Fan Programmer V)') |
| 48 | + |
| 49 | +INNO_LOCATION = None |
| 50 | +INNO_TEST_LOCATION_1 = r'C:\Program Files\Inno Setup 5\ISCC.exe' |
| 51 | +INNO_TEST_LOCATION_2 = r'C:\Program Files (x86)\Inno Setup 5\ISCC.exe' |
| 52 | + |
| 53 | +if os.path.exists(INNO_TEST_LOCATION_1): |
| 54 | + INNO_LOCATION = '\"' + INNO_TEST_LOCATION_1 + '\" {}' |
| 55 | +elif os.path.exists(INNO_TEST_LOCATION_2): |
| 56 | + INNO_LOCATION = '\"' + INNO_TEST_LOCATION_2 + '\" {}' |
| 57 | +elif not INNO_LOCATION: |
| 58 | + raise Exception, "Inno Setup was not found on system" |
| 59 | + |
| 60 | +################################################################################ |
| 61 | +# General Purpose Function Definitions # |
| 62 | +################################################################################ |
| 63 | + |
| 64 | +def fnVersionFormatValid(versionstring): |
| 65 | + if VER_PATTERN.match(versionstring): |
| 66 | + return |
| 67 | + else: |
| 68 | + raise Exception, 'Not correct version format' |
| 69 | + |
| 70 | +def fnReplaceVersionInLine(file, repattern, version): |
| 71 | + |
| 72 | + boolFoundAReplacment = False |
| 73 | + |
| 74 | + for line in fileinput.input(file, inplace=1): |
| 75 | + matchstring = repattern.match(line) |
| 76 | + if matchstring: |
| 77 | + line = VER_PATTERN.sub( version , line ) |
| 78 | + boolFoundAReplacment = True |
| 79 | + #monitor_stdout.write(version) |
| 80 | + #monitor_stdout.write(line) |
| 81 | + sys.stdout.write(line) |
| 82 | + fileinput.close() |
| 83 | + |
| 84 | + assert boolFoundAReplacment, "Pattern to replace not found" |
| 85 | + |
| 86 | +################################################################################ |
| 87 | +# Script Start # |
| 88 | +################################################################################ |
| 89 | +vars = Variables() |
| 90 | +vars.Add('SWVERSION', 'Sets the version in the form of x.x.x', 'x.x.x') |
| 91 | + |
| 92 | +#Create environment |
| 93 | +env = Environment(variables = vars) |
| 94 | +Help(vars.GenerateHelpText(env)) |
| 95 | + |
| 96 | +print 'Building Software Version:' + env['SWVERSION'] |
| 97 | +fnVersionFormatValid(env['SWVERSION']) |
| 98 | + |
| 99 | +#Change the version in the source files |
| 100 | +fnReplaceVersionInLine( ISSFILE, ISS_PATTERN, env['SWVERSION'] ) |
| 101 | +fnReplaceVersionInLine( GUISOURCEFILE, SRC_PATTERN, env['SWVERSION']) |
| 102 | + |
| 103 | +#Building the program |
| 104 | +gui_depends = (SOURCEFILES, GUISOURCEFILE , ISSFILE, SPECFILE) |
| 105 | +gui_targets = ('dist/bms_simulator/BMS_Simulator.exe') |
| 106 | +gui_clean_files = [r'./dist', r'./build', r'./~', r'*.pyc'] |
| 107 | +gui_command = env.Command( gui_targets, gui_depends, 'C:\Python27\Scripts\pyinstaller.exe --noconfirm {}'.format(SPECFILE) ) |
| 108 | +env.Clean(gui_command , gui_clean_files) |
| 109 | + |
| 110 | +#Building the Installer |
| 111 | +installer_depends = ('.\dist', ISSFILE) |
| 112 | +installer_targets = ('Output\SE1FanProg_V.exe') |
| 113 | +installer_command = env.Command( installer_targets , installer_depends , INNO_LOCATION.format(ISSFILE)) |
| 114 | +installer_clean_files = Glob(r'.\Output') |
| 115 | +env.Clean(installer_command , installer_clean_files) |
| 116 | + |
| 117 | +#Copy the file and rename |
| 118 | +rename_depends = ('Output\SE1FanProg_V.exe') |
| 119 | +rename_targets = 'SE1FanProg_V' + env['SWVERSION'] + '.exe' |
| 120 | +rename_clean_files = Glob('SE1FanProg_V*.exe') |
| 121 | +rename_command = env.Command( rename_targets , rename_depends , Copy("$TARGET", "$SOURCE") ) |
| 122 | +env.Clean(rename_command , rename_clean_files) |
| 123 | + |
0 commit comments