Skip to content

Commit 89cbc9b

Browse files
committed
Working on improved argument system for script suite
1 parent b9c8a07 commit 89cbc9b

File tree

4 files changed

+145
-76
lines changed

4 files changed

+145
-76
lines changed

Build.py

Lines changed: 75 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,86 @@
1+
import argparse
2+
13
from Scripts.UpdateVersionNumber import update_version_number
24
from Scripts.UpdateFromP4 import update_from_P4
35
from Scripts.BuildLighting import build_lighting
46
from Scripts.BuildGame import build_game
57
from Scripts.UploadToDeletedNighly import upload_to_deleted_nightly
68
from Scripts.UploadToSteam import upload_to_steam
79

10+
from Scripts import Environment as env
11+
12+
# Create and setup the argument parser for the user scripts
13+
parser = argparse.ArgumentParser(description='Python based UE4 Versioning, Building, Packaging, and Uploading suite')
14+
parser.add_argument('-m', '--minor', action='store_true', default=False, help='Increment the minor version of the project. Will be overriden by the major argument')
15+
parser.add_argument('-M', '--major', action='store_true', default=False, help='Increment the major version of the project. Will override the minor argument')
16+
parser.add_argument('-n', '--no-lighting', action='store_true', default=False, help='Skip the lighting build')
17+
parser.add_argument('-a', '--all', action='store_true', default=False, help='Run the full script suite. This is purely for verbosity. Giving no individual script arguments has the same effect')
18+
parser.add_argument('-p4', '--perforce', action='store_true', default=False, help='Update from P4V')
19+
parser.add_argument('-uv', '--version', action='store_true', default=False, help='Update the version number')
20+
parser.add_argument('-bl', '--lighting', action='store_true', default=False, help='Build the lighting')
21+
parser.add_argument('-bg', '--build', action='store_true', default=False, help='Build the game')
22+
parser.add_argument('-us', '--steam', action='store_true', default=False, help='Upload to steam')
23+
parser.add_argument('--output', action='store', nargs='?', default='log.txt', help='Set the output files name that is generated in the environments build location')
24+
25+
def script_error( log_file, error_message ):
26+
log_file.write("ERROR: " + error_message)
27+
log_file.close()
28+
quit(1)
829

930
if __name__ == '__main__':
10-
print( '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++')
11-
print( 'Initiating Build Sequence ')
12-
13-
success = update_from_P4()
14-
if success:
15-
success = update_version_number( False, False, True)
16-
pass
17-
else:
18-
print("[FAILED] Failed to update from perforce")
19-
20-
if success:
21-
success = build_lighting()
22-
pass
23-
else:
24-
print("[FAILED]: Failed to update version number")
25-
26-
if success:
27-
success = build_game()
28-
pass
29-
else:
30-
print("[FAILED]: Failed to build lighting")
31-
32-
if success:
33-
success = upload_to_steam()
34-
pass
35-
else:
36-
print("[FAILEd]: Failed to build and package the game")
31+
args = parser.parse_args()
32+
33+
build_dir = env.get_env_variable('Game', 'builds_dir')
34+
log_file = open( build_dir + args.output, 'w')
35+
36+
log_file.write( '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n' )
37+
log_file.write( 'Initiating Build Sequence\n' )
38+
39+
# If no commands are give, assume the user wants to run the full suite of scripts
40+
args.all = True if not (args.perforce or args.version or args.lighting or args.build or args.steam) else args.all
41+
42+
# Defines the success of the previous operation
43+
success = True
44+
if args.all or args.perforce:
45+
success = update_from_P4(log_file)
46+
if not success:
47+
script_error(log_file, 'Failed to update from P4V')
3748

49+
if success and (args.all or args.version):
50+
success = update_version_number( log_file, args.major, args.minor)
3851
if not success:
39-
print("[FAILED]: Failed to upload to steam")
52+
script_error(log_file, 'Failed to update the version number')
53+
54+
if success and not args.no_lighting and (args.all or args.lighting):
55+
success = build_lighting( log_file )
56+
57+
58+
# success = update_from_P4()
59+
# if success:
60+
# success = update_version_number( major, minor, hotfix)
61+
# pass
62+
# else:
63+
# print('[FAILED] Failed to update from perforce')
64+
65+
# if success:
66+
# success = build_lighting()
67+
# pass
68+
# else:
69+
# print('[FAILED]: Failed to update version number')
70+
71+
# if success:
72+
# success = build_game()
73+
# pass
74+
# else:
75+
# print('[FAILED]: Failed to build lighting')
76+
77+
# if success:
78+
# success = upload_to_steam()
79+
# pass
80+
# else:
81+
# print('[FAILEd]: Failed to build and package the game')
82+
83+
# if not success:
84+
# print('[FAILED]: Failed to upload to steam')
85+
86+
log_file.close()

Scripts/BuildLighting.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,27 @@
77

88
game_name = env.get_env_variable('Game','game_name')
99

10-
def build_lighting():
11-
print( '----------------------------------------------------------------------------------------------------' )
12-
print( '{} - Step 3: Starting Lighting Build'.format( game_name ) )
13-
print( '----------------------------------------------------------------------------------------------------' )
10+
def build_lighting( log_file ):
11+
log_file.write( '----------------------------------------------------------------------------------------------------\n' )
12+
log_file.write( '{} - Step 3: Starting Lighting Build\n'.format( game_name ) )
13+
log_file.write( '----------------------------------------------------------------------------------------------------\n' )
1414

1515
maps = []
1616

1717
# Compile the list of maps
1818
map_dir = env.get_env_variable('Game', 'map_dir')
1919
map_names = env.get_env_variable('Game', 'maps').split(';')
2020

21+
log_file.write('Building lighting for these maps: ')
2122
for map in map_names:
23+
log_file.write(map + " ")
2224
full_path_map = map_dir + map
2325
maps.append( full_path_map + '.umap')
2426

2527
maps.append( full_path_map + '_BuiltData.uasset')
2628

29+
log_file.write('\n')
30+
log_file.flush()
2731

2832
# Check the file out from P4
2933
p4 = P4()
@@ -44,27 +48,32 @@ def build_lighting():
4448
# Build the lighting
4549
uproject_file = env.get_env_variable( "Game", "uproject_file" )
4650
ue4_binaries_dir = env.get_env_variable( 'Local', "ue4_binaries_dir" )
47-
print(subprocess.run( [ ue4_binaries_dir + 'UE4Editor-Cmd.exe', uproject_file, '-verbose', "-p4", "-submit", "-run=resavepackages" , "-buildlighting", "-quality=production", "-allowcommandletrendering", "-map" + ' '.join(maps)] ) )
51+
subprocess.run( [ ue4_binaries_dir + 'UE4Editor-Cmd.exe', uproject_file, '-verbose', "-p4", "-submit", "-run=resavepackages" , "-buildlighting", "-quality=production", "-allowcommandletrendering", "-map" + ' '.join(maps)], stdout=log_file )
52+
log_file.flush()
4853

4954
# Add maps back for addition to p4
5055
for map in maps:
51-
print("adding " + map)
56+
log_file.write("adding " + map + '\n')
5257
p4.run('add', map)
58+
log_file.flush()
5359

5460
change = p4.fetch_change()
5561
change._description = '[Daily_Builds] Built lighting for the follow maps:\n' + '\n\t'.join(maps)
56-
p4.run_submit( change )
62+
# p4.run_submit( change )
63+
64+
log_file.write('Lighting successfully built and submitted\n')
65+
log_file.flush()
5766

5867
return True
5968
except P4Exception:
60-
print('ERROR: Error capture in P4')
69+
log_file.write('Perforce error encountered')
6170
for e in p4.errors:
62-
print(e)
71+
log_file.write( str(e) )
72+
73+
log_file.flush()
6374

6475
return False
6576
except Exception as e:
66-
print(e)
77+
log_file.write( str(e) )
78+
log_file.flush()
6779
return False
68-
69-
if __name__ == '__main__':
70-
build_lighting()

Scripts/UpdateFromP4.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ def run(self):
3939

4040
game_name = env.get_env_variable('Game', 'game_name')
4141

42-
def update_from_P4():
43-
print( '----------------------------------------------------------------------------------------------------' )
44-
print( '{} - Step 1: Update the local workspace for P4'.format( game_name ) )
45-
print( '----------------------------------------------------------------------------------------------------' )
42+
def update_from_P4( log_file ):
43+
log_file.write( '----------------------------------------------------------------------------------------------------\n' )
44+
log_file.write( '{} - Step 1: Update the local workspace for P4\n'.format( game_name ) )
45+
log_file.write( '----------------------------------------------------------------------------------------------------\n' )
46+
log_file.flush()
4647

4748
# Perforce Settings
4849
p4.port = "129.119.63.244:1666"
@@ -52,16 +53,19 @@ def update_from_P4():
5253

5354
# Connect to the perforce server
5455
success = p4.connect()
55-
print( success )
56+
log_file.write( str(success) )
57+
log_file.write('\n')
58+
log_file.flush()
5659

5760
p4_thread = Threaded_Callback(1, p4_sync, p4_sync_callback)
5861
p4_thread.start()
5962

6063
start_time = time.time()
6164
while( not files_synced ):
62-
print( "Time Elapsed: {:.2f}".format( time.time() - start_time ), end='\r')
65+
pass
6366

64-
print( 'Completed Perfoce Sync in {:.2f} seconds'.format( time.time() - start_time ) )
67+
log_file.write( 'Completed Perfoce Sync in {:.2f} seconds\n'.format( time.time() - start_time ) )
68+
log_file.flush()
6569

6670
files_updated = 0
6771
files_deleted = 0
@@ -84,15 +88,16 @@ def update_from_P4():
8488
update_message += file['rev'] + " ) - "
8589
update_message += file['action']
8690

87-
print(update_message)
91+
log_file.write(update_message)
92+
log_file.write('\n')
93+
94+
if files_updated % 100 == 0:
95+
log_file.flush()
8896

8997
if files_deleted > 0:
90-
print( '{} files marked for deleted in total'.format( files_deleted ) )
98+
log_file.write( '{} files marked for deleted in total\n'.format( files_deleted ) )
9199
if files_updated == 0:
92-
print( 'All files are current' )
100+
log_file.write( 'All files are current\n' )
101+
log_file.flush()
93102

94103
return True
95-
96-
if __name__ == '__main__':
97-
update_from_P4()
98-

Scripts/UpdateVersionNumber.py

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,29 @@
88

99
game_name = env.get_env_variable('Game','game_name')
1010

11-
def update_version_number( major, minor, hotfix ):
12-
print( '----------------------------------------------------------------------------------------------------' )
13-
print( '{} - Step 2: Update the version number'.format( game_name ) )
14-
print( '----------------------------------------------------------------------------------------------------' )
11+
def update_version_number( log_file, major, minor ):
12+
log_file.write( '----------------------------------------------------------------------------------------------------\n' )
13+
log_file.write( '{} - Step 2: Update the version number\n'.format( game_name ) )
14+
log_file.write( '----------------------------------------------------------------------------------------------------\n' )
1515

16+
# Determine if automatic versioning is used by the config file
1617
try:
1718
automatic_versioning = env.get_env_variable('Version', 'automatic')
1819

1920
# If no versioning disinction continue
2021
except Exception as e:
21-
print('Automatic versioning system skipped because no [Version] automatic value found')
22+
log_file.write('Automatic versioning system skipped because no [Version] automatic value found\n')
2223
return True
2324

2425
if 'False' in automatic_versioning:
25-
print('Automatic versioning system skipped because its disabled')
26+
log_file.write('Automatic versioning system is disabled\n')
2627
return True
2728
elif not 'True' in automatic_versioning:
28-
print('Unknown value {} in [Version] automatic. Expected "True"/"False" values')
29+
log_file.write("Unknown value {} in [Version] automatic. Expected 'True'/'False' values\n".format(automatic_versioning) )
2930
return False
31+
log_file.flush()
3032

31-
version_number = ""
33+
version_number = ''
3234

3335
# Open ini file
3436
version_ini = env.get_env_variable('Version', 'version_ini')
@@ -53,10 +55,13 @@ def update_version_number( major, minor, hotfix ):
5355
found_version = True
5456

5557
if not found_version:
56-
print("Failed to find version number")
58+
log_file.write('Failed to find version number\n')
59+
return False
5760

5861
# Update the version number
59-
new_version = get_version_number(major, minor, hotfix, version_number)
62+
new_version = get_version_number(major, minor, version_number)
63+
log_file.write('Version number updated to {}\n'.format(new_version))
64+
log_file.flush()
6065

6166
# Check the file out from P4
6267
p4 = P4()
@@ -85,19 +90,25 @@ def update_version_number( major, minor, hotfix ):
8590

8691
change = p4.fetch_change()
8792
change._description = '[Daily_Builds] Updated the version number to ' + new_version
88-
p4.run_submit( change )
93+
# p4.run_submit( change )
94+
95+
log_file.write('New version number successfully submitted to perforce\n')
96+
log_file.flush()
8997

9098
return True
9199
except P4Exception:
100+
log_file.write('Perforce error encountered')
92101
for e in p4.errors:
93-
print(e)
102+
log_file.write( str(e) )
94103

104+
log_file.flush()
95105
return False
96106
except Exception as e:
97-
print(e)
107+
log_file.write( str(e) )
108+
log_file.flush()
98109
return False
99110

100-
def get_version_number(major, minor, hotfix, version):
111+
def get_version_number(major, minor, version):
101112
split_version = version.split('.')
102113
if major:
103114
split_version[0] = str(int(split_version[0]) + 1)
@@ -110,10 +121,7 @@ def get_version_number(major, minor, hotfix, version):
110121
split_version[2] = '0'
111122
return '.'.join(split_version)
112123

113-
if hotfix:
114-
split_version[2] = str(int(split_version[2]) + 1)
115-
return '.'.join(split_version)
116-
117-
118-
if __name__ == '__main__':
119-
update_version_number(False, False, True)
124+
# If not major or minor, must be hotfix
125+
split_version[2] = str(int(split_version[2]) + 1)
126+
return '.'.join(split_version)
127+

0 commit comments

Comments
 (0)