|
| 1 | +from P4 import P4 |
| 2 | + |
| 3 | +import time |
| 4 | +import threading |
| 5 | + |
| 6 | +# Threaded P4V Sync function |
| 7 | +def p4_sync(): |
| 8 | + global synced_files |
| 9 | + synced_files = p4.run( 'sync', '-f' ) |
| 10 | + return synced_files |
| 11 | + |
| 12 | +# Threaded P$v Sync callback |
| 13 | +def p4_sync_callback( synced_files_from_p4 ): |
| 14 | + global files_synced |
| 15 | + synced_files = synced_files_from_p4 |
| 16 | + files_synced = True |
| 17 | + |
| 18 | +# |
| 19 | +threaded_callback_lock = threading.Lock() |
| 20 | +class Threaded_Callback (threading.Thread): |
| 21 | + def __init__(self, thread_id, function, callback): |
| 22 | + threading.Thread.__init__(self) |
| 23 | + self.thread_id = thread_id |
| 24 | + self.function = function |
| 25 | + self.callback = callback |
| 26 | + |
| 27 | + def run(self): |
| 28 | + returnValue = self.function() |
| 29 | + |
| 30 | + threaded_callback_lock.acquire() |
| 31 | + self.callback( returnValue ) |
| 32 | + threaded_callback_lock.release() |
| 33 | + |
| 34 | +game_name = 'HaberDashers' |
| 35 | +synced_files = {} |
| 36 | +files_synced = False |
| 37 | + |
| 38 | +if __name__ == '__main__': |
| 39 | + |
| 40 | + print( '----------------------------------------------------------------------------------------------------' ) |
| 41 | + print( '{} - Step 1: Update the local workspcae for P4'.format( game_name ) ) |
| 42 | + print( '----------------------------------------------------------------------------------------------------' ) |
| 43 | + |
| 44 | + # Perforce Settings |
| 45 | + p4 = P4() |
| 46 | + p4.user = 'daily_builds' |
| 47 | + p4.password = 'gKv52w!*' |
| 48 | + p4.client = 'NightlyBuild_HaberDashers' |
| 49 | + |
| 50 | + # Connect to the perforce server |
| 51 | + success = p4.connect() |
| 52 | + print( success ) |
| 53 | + |
| 54 | + p4_thread = Threaded_Callback(1, p4_sync, p4_sync_callback) |
| 55 | + p4_thread.start() |
| 56 | + |
| 57 | + start_time = time.time() |
| 58 | + while( not files_synced ): |
| 59 | + print( "Time Elapsed: {:.2f}".format( time.time() - start_time ), end='\r') |
| 60 | + |
| 61 | + print( 'Completed Perfoce Sync in {:.2f} seconds'.format( time.time() - start_time ) ) |
| 62 | + |
| 63 | + files_updated = 0 |
| 64 | + files_deleted = 0 |
| 65 | + for file in synced_files: |
| 66 | + if file['action'] == 'refreshed': |
| 67 | + continue |
| 68 | + |
| 69 | + if file['action'] == 'deleted': |
| 70 | + files_deleted += 1 |
| 71 | + continue |
| 72 | + |
| 73 | + files_updated += 1 |
| 74 | + update_message = str(files_updated) + ": " |
| 75 | + |
| 76 | + relative_file_name = file['clientFile'] |
| 77 | + name_loc = relative_file_name.find( game_name ) |
| 78 | + relative_file_name = relative_file_name[ name_loc + len(game_name):] |
| 79 | + |
| 80 | + update_message += relative_file_name + " ( " |
| 81 | + update_message += file['rev'] + " ) - " |
| 82 | + update_message += file['action'] |
| 83 | + |
| 84 | + print(update_message) |
| 85 | + |
| 86 | + if files_deleted > 0: |
| 87 | + print( '{} files marked for deleted in total'.format( files_deleted ) ) |
| 88 | + if files_updated == 0: |
| 89 | + print( 'All files are current' ) |
| 90 | + |
| 91 | + print( '{} - Step 1: Complete'.format( game_name ) ) |
| 92 | + input( 'Press Enter to continue...') |
0 commit comments