-
Notifications
You must be signed in to change notification settings - Fork 10
/
BuildRelease.py
executable file
·145 lines (119 loc) · 6.8 KB
/
BuildRelease.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
145
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys, os, shutil, json
from subprocess import call
import distutils.dir_util
import configparser
from distutils.version import LooseVersion
from urllib.request import Request, urlopen
GlobalScriptPath = os.path.dirname(os.path.realpath(__file__)).replace('\\','/')
GlobalReleasePath = GlobalScriptPath + "/BuildRelease/PortableApps/MachinaTrader"
GlobalGitPath = GlobalScriptPath + "/MachinaTraderGit"
GlobalSourceFolder = GlobalScriptPath
GlobalConfigFileName=os.path.basename(__file__).replace('.py','.json')
GlobalConfigFile=GlobalScriptPath + "/" + GlobalConfigFileName
portableAppsPath=os.path.dirname(GlobalScriptPath)
if os.path.exists(GlobalConfigFile):
with open(GlobalConfigFile) as data_file:
GlobalConfig = json.load(data_file)
else:
print("Config not found - Creating")
GlobalConfig = {}
GlobalConfig["BuildOptions"] = {};
GlobalConfig["BuildOptions"]["BuildSetupFolders"] = True
GlobalConfig["BuildOptions"]["BuildAddPlugins"] = True
GlobalConfig["BuildOptions"]["BuildEnableAllPlugins"] = True
GlobalConfig["BuildOptions"]["BuildCompile"] = True
GlobalConfig["BuildOptions"]["BuildCreateInstaller"] = True
GlobalConfig["EnabledPlugins"] = []
# What to do
BuildSetupFolders = GlobalConfig["BuildOptions"]["BuildSetupFolders"]
BuildAddPlugins = GlobalConfig["BuildOptions"]["BuildAddPlugins"]
BuildEnableAllPlugins = GlobalConfig["BuildOptions"]["BuildEnableAllPlugins"]
BuildCompile = GlobalConfig["BuildOptions"]["BuildCompile"]
BuildCreateInstaller = GlobalConfig["BuildOptions"]["BuildCreateInstaller"]
ConfigValidPlugins=GlobalConfig["EnabledPlugins"]
if (BuildSetupFolders):
print('-------------------------------------------------------------------------')
print('Setup Folders')
print('-------------------------------------------------------------------------')
if not os.path.isdir(GlobalSourceFolder + '/BuildRelease/App'):
print ('Source Folder not found -> Fallback to Git Folder')
GlobalSourceFolder = GlobalGitPath
print (GlobalSourceFolder)
shutil.rmtree(GlobalReleasePath + "/App", ignore_errors=True)
os.makedirs(GlobalReleasePath, exist_ok=True)
os.makedirs(GlobalReleasePath +'/App/Plugins', exist_ok=True)
distutils.dir_util.copy_tree(GlobalSourceFolder + '/BuildRelease/App/AppInfo', GlobalReleasePath + '/App/AppInfo')
shutil.copy2(GlobalSourceFolder + '/BuildRelease/AppAdditions/help.html', GlobalReleasePath + '/help.html')
distutils.dir_util.copy_tree(GlobalSourceFolder + '/MachinaTrader/wwwroot', GlobalReleasePath + '/App/wwwroot')
if BuildEnableAllPlugins:
ConfigValidPlugins=[]
for root, directories, files in os.walk(GlobalSourceFolder):
for pluginFolder in directories:
if pluginFolder.startswith('MachinaTrader.Plugin.'):
ConfigValidPlugins.append(pluginFolder)
if (BuildAddPlugins):
print('-------------------------------------------------------------------------')
print('Add Plugins')
print('-------------------------------------------------------------------------')
for validPlugin in ConfigValidPlugins:
try:
distutils.dir_util.copy_tree(GlobalSourceFolder + '/' + validPlugin + '/wwwroot', GlobalReleasePath + '/App/Plugins/' + validPlugin+ '/wwwroot')
except:
print("Error: " + validPlugin + " dont contains a wwwroot Folder")
if (BuildCompile):
print('-------------------------------------------------------------------------')
print('Cleanup Project File')
print('-------------------------------------------------------------------------')
shutil.copy2(GlobalSourceFolder + '/MachinaTrader/MachinaTrader.csproj', GlobalSourceFolder + '/MachinaTrader/MachinaTrader.csproj.bak')
f = open(GlobalSourceFolder + '/MachinaTrader/MachinaTrader.csproj','r+')
d = f.readlines()
f.seek(0)
for i in d:
if 'MachinaTrader.Globals' in i:
f.write(i)
#Add all enabled Plugins
for validPlugin in ConfigValidPlugins:
f.write('<ProjectReference Include="..\\' + validPlugin + '\\' + validPlugin + '.csproj" />\r\n')
elif 'MachinaTrader.Plugin.' not in i:
f.write(i)
f.truncate()
f.close()
print('-------------------------------------------------------------------------')
print('Compile')
print('-------------------------------------------------------------------------')
os.chdir(GlobalSourceFolder + '/MachinaTrader')
os.system('dotnet restore')
if sys.platform == "win32":
os.system('dotnet publish --framework netcoreapp2.1 --self-contained --runtime win-x64 --output ' + GlobalReleasePath + '/App')
#Copy Launcher
shutil.copy2(GlobalSourceFolder + '/BuildRelease/AppAdditions/MachinaTraderLauncher.exe', GlobalReleasePath + '/MachinaTraderLauncher.exe')
if sys.platform =="linux":
os.system('dotnet publish --framework netcoreapp2.1 --self-contained --runtime linux-x64 --output ' + GlobalReleasePath + '/App')
# Restore real project
os.remove(GlobalSourceFolder + '/MachinaTrader/MachinaTrader.csproj')
shutil.copy2(GlobalSourceFolder + '/MachinaTrader/MachinaTrader.csproj.bak', GlobalSourceFolder + '/MachinaTrader/MachinaTrader.csproj')
# Windows: Release Path is scriptpath + "/PortableApps"
if BuildCreateInstaller:
# Check if needed Build Tools are installed, we DONT check for netcore/vsbuild tools because they are hard dependency
if not os.path.isdir(GlobalSourceFolder + "/BuildRelease"):
os.makedirs(GlobalSourceFolder + "/BuildRelease", exist_ok=True)
if not os.path.isdir(GlobalSourceFolder + "/BuildRelease"):
os.makedirs(GlobalSourceFolder + "/BuildRelease", exist_ok=True)
if not os.path.isfile(GlobalSourceFolder + "/BuildRelease/MachinaCore.comAppInstaller/PortableApps.comInstaller.exe"):
print("Warning Build Tools dont exist - Downloading")
os.chdir(GlobalSourceFolder + "/BuildRelease")
os.system('git clone https://github.com/MachinaCore/MachinaCore.comAppInstaller.git ' + GlobalScriptPath + "/BuildRelease/AppInstaller")
os.chdir(GlobalScriptPath)
config = configparser.ConfigParser()
config.read(GlobalSourceFolder + '/BuildRelease/App/AppInfo/appinfo.ini')
fileName = config['Details']['AppID']
fileVersion = config['Version']['PackageVersion']
installerFileName = fileName + "_" + fileVersion + ".paf.exe"
# Make sure data folder is deleted for release
shutil.rmtree(GlobalReleasePath + "/App/Data", ignore_errors=True)
# Create 7-zip
os.system('7z.exe a -r -t7z -mx=9 '+ fileName +'_'+ fileVersion +'.7z ' + GlobalReleasePath.replace("/","\\") + '\\*')
# Create Installer
os.system(GlobalSourceFolder + '/BuildRelease/AppInstaller/PortableApps.comInstaller.exe "'+ GlobalReleasePath.replace("/","\\") + '"')