@@ -372,7 +372,7 @@ def copy_build(site, destdir):
372372 shutil .rmtree (olddir )
373373
374374
375- def make_backup (site , destdir , backupdestdir ):
375+ def make_backup (building_time , site , destdir , backupdestdir ):
376376 """
377377 backup current site
378378 """
@@ -1008,142 +1008,155 @@ def create_features_page(features, build_options_by_define, vehicletype):
10081008#######################################################################
10091009
10101010
1011- if __name__ == "__main__" :
1012-
1013- if platform .system () == "Windows" :
1014- multiprocessing .freeze_support ()
1015-
1016- # Set up option parsing to get connection string
1017- parser = argparse .ArgumentParser (
1018- description = 'Copy Common Files as needed, stripping out non-relevant wiki content' ,
1019- )
1020- parser .add_argument (
1021- '--site' ,
1022- help = "If you just want to copy to one site, you can do this. Otherwise will be copied." ,
1023- )
1024- parser .add_argument (
1025- '--clean-common' ,
1026- action = 'store_true' ,
1027- help = "Force clean and copy common files into wikis directories." ,
1028- )
1029- parser .add_argument (
1030- '--cached-parameter-files' ,
1031- action = 'store_true' ,
1032- help = "Do not re-download parameter files" ,
1033- )
1034- parser .add_argument (
1035- '--parallel' ,
1036- type = int ,
1037- help = "limit parallel builds, -1 for unlimited" ,
1038- default = 1 ,
1039- )
1040- parser .add_argument (
1041- '--destdir' ,
1042- default = None ,
1043- help = "Destination directory for compiled docs" ,
1044- )
1045- parser .add_argument (
1046- '--enablebackups' ,
1047- action = 'store_true' ,
1048- default = False ,
1049- help = "Enable several backups up to const N_BACKUPS_RETAIN in --backupdestdir folder" ,
1050- )
1051- parser .add_argument (
1052- '--backupdestdir' ,
1053- default = "/var/sites/wiki-backup/web" ,
1054- help = "Destination directory for compiled docs" ,
1055- )
1056- parser .add_argument (
1057- '--paramversioning' ,
1058- action = 'store_true' ,
1059- default = False ,
1060- help = "Build multiple parameters pages for each vehicle based on its firmware repo." ,
1061- )
1062- parser .add_argument (
1063- '--verbose' ,
1064- dest = 'verbose' ,
1065- action = 'store_true' ,
1066- default = False ,
1067- help = "show debugging output" ,
1068- )
1069- parser .add_argument (
1070- '--fast' ,
1071- dest = 'fast' ,
1072- action = 'store_true' ,
1073- default = False ,
1074- help = ("Incremental build using already downloaded parameters, log messages, and video thumbnails rather than cleaning "
1075- "before build." ),
1076- )
1077-
1078- args = parser .parse_args ()
1079-
1080- VERBOSE = args .verbose
1011+ class WikiUpdater :
1012+ def __init__ (self ) -> None :
1013+ if platform .system () == "Windows" :
1014+ multiprocessing .freeze_support ()
1015+
1016+ # Set up option parsing to get connection string
1017+ parser = argparse .ArgumentParser (
1018+ description = "Copy Common Files as needed, stripping out non-relevant wiki content" ,
1019+ )
1020+ parser .add_argument (
1021+ "--site" ,
1022+ help = "If you just want to copy to one site, you can do this. Otherwise will be copied." ,
1023+ )
1024+ parser .add_argument (
1025+ "--clean-common" ,
1026+ action = "store_true" ,
1027+ help = "Force clean and copy common files into wikis directories." ,
1028+ )
1029+ parser .add_argument (
1030+ "--cached-parameter-files" ,
1031+ action = "store_true" ,
1032+ help = "Do not re-download parameter files" ,
1033+ )
1034+ parser .add_argument (
1035+ "--parallel" ,
1036+ type = int ,
1037+ help = "limit parallel builds, -1 for unlimited" ,
1038+ default = 1 ,
1039+ )
1040+ parser .add_argument (
1041+ "--destdir" ,
1042+ default = None ,
1043+ help = "Destination directory for compiled docs" ,
1044+ )
1045+ parser .add_argument (
1046+ "--enablebackups" ,
1047+ action = "store_true" ,
1048+ default = False ,
1049+ help = "Enable several backups up to const N_BACKUPS_RETAIN in --backupdestdir folder" ,
1050+ )
1051+ parser .add_argument (
1052+ "--backupdestdir" ,
1053+ default = "/var/sites/wiki-backup/web" ,
1054+ help = "Destination directory for compiled docs" ,
1055+ )
1056+ parser .add_argument (
1057+ "--paramversioning" ,
1058+ action = "store_true" ,
1059+ default = False ,
1060+ help = "Build multiple parameters pages for each vehicle based on its firmware repo." ,
1061+ )
1062+ parser .add_argument (
1063+ "--verbose" ,
1064+ dest = "verbose" ,
1065+ action = "store_true" ,
1066+ default = False ,
1067+ help = "show debugging output" ,
1068+ )
1069+ parser .add_argument (
1070+ "--fast" ,
1071+ dest = "fast" ,
1072+ action = "store_true" ,
1073+ default = False ,
1074+ help = ("Incremental build using already downloaded parameters, "
1075+ "log messages, and video thumbnails rather than cleaning "
1076+ "before build." ),
1077+ )
1078+
1079+ self .args = parser .parse_args ()
1080+ self .verbose : bool = self .args .verbose
1081+
1082+ def run (self ) -> None :
1083+ global VERBOSE
1084+ VERBOSE = self .verbose
1085+
1086+ tstart = time .time ()
1087+ now = datetime .now ()
1088+ building_time = now .strftime ("%Y-%m-%d-%H-%M-%S" )
1089+
1090+ check_imports ()
1091+ check_ref_directives ()
1092+
1093+ progress ("=== Step 1: Creating features pages ===" )
1094+ progress (f"Time elapsed so far: { time .time () - tstart :.2f} seconds" )
1095+ create_features_pages (self .args .site )
1096+
1097+ progress ("=== Step 2: Fetching parameters and log messages in parallel ===" )
1098+ progress (f"Time elapsed so far: { time .time () - tstart :.2f} seconds" )
1099+ if not self .args .fast :
1100+ if self .args .paramversioning :
1101+ # Parameters for all versions available on firmware.ardupilot.org:
1102+ fetch_versioned_parameters (self .args .site )
1103+ else :
1104+ # Single parameters file. Just present the latest parameters:
1105+ fetchparameters (self .args .site , self .args .cached_parameter_files )
10811106
1082- tstart = time .time ()
1083- now = datetime .now ()
1084- building_time = now .strftime ("%Y-%m-%d-%H-%M-%S" )
1107+ # Fetch most recent LogMessage metadata from autotest:
1108+ fetchlogmessages (self .args .site , self .args .cached_parameter_files )
10851109
1086- check_imports ()
1087- check_ref_directives ()
1110+ progress ("=== Step 3: Processing static sites ===" )
1111+ progress (f"Time elapsed so far: { time .time () - tstart :.2f} seconds" )
1112+ copy_static_html_sites (self .args .site , self .args .destdir )
10881113
1089- progress ("=== Step 1: Creating features pages ===" )
1090- progress (f"Time elapsed so far: { time .time () - tstart :.2f} seconds" )
1091- create_features_pages (args .site )
1114+ # Use clean_common=True for clean builds, False for fast/incremental builds
1115+ progress ("=== Step 4: Copying common source files ===" )
1116+ progress (f"Time elapsed so far: { time .time () - tstart :.2f} seconds" )
1117+ copy_common_source_files (clean_common = self .args .clean_common )
10921118
1093- progress ("=== Step 2: Fetching parameters and log messages in parallel ===" )
1094- progress (f"Time elapsed so far: { time .time () - tstart :.2f} seconds" )
1095- if not args .fast :
1096- if args .paramversioning :
1097- # Parameters for all versions available on firmware.ardupilot.org:
1098- fetch_versioned_parameters (args .site )
1099- else :
1100- # Single parameters file. Just present the latest parameters:
1101- fetchparameters (args .site , args .cached_parameter_files )
1119+ progress ("=== Step 5: Building documentation with Sphinx ===" )
1120+ progress (f"Time elapsed so far: { time .time () - tstart :.2f} seconds" )
1121+ sphinx_make (self .args .site , self .args .parallel , self .args .fast )
11021122
1103- # Fetch most recent LogMessage metadata from autotest:
1104- fetchlogmessages (args .site , args .cached_parameter_files )
1123+ if self .args .paramversioning :
1124+ put_cached_parameters_files_in_sites (self .args .site )
1125+ cache_parameters_files (self .args .site )
11051126
1106- progress ("=== Step 3: Processing static sites ===" )
1107- progress (f"Time elapsed so far: { time .time () - tstart :.2f} seconds" )
1108- copy_static_html_sites (args .site , args .destdir )
1127+ check_build (self .args .site )
11091128
1110- # Use clean_common=True for clean builds, False for fast/incremental builds
1111- progress ("=== Step 4: Copying common source files ===" )
1112- progress (f"Time elapsed so far: { time .time () - tstart :.2f} seconds" )
1113- copy_common_source_files (clean_common = args .clean_common )
1129+ if self .args .enablebackups :
1130+ make_backup (building_time , self .args .site , self .args .destdir , self .args .backupdestdir )
1131+ delete_old_wiki_backups (self .args .backupdestdir , N_BACKUPS_RETAIN )
11141132
1115- progress ("=== Step 5: Building documentation with Sphinx ===" )
1116- progress (f"Time elapsed so far: { time .time () - tstart :.2f} seconds" )
1117- sphinx_make (args .site , args .parallel , args .fast )
1133+ if self .args .destdir :
1134+ copy_build (self .args .site , self .args .destdir )
11181135
1119- if args .paramversioning :
1120- put_cached_parameters_files_in_sites (args .site )
1121- cache_parameters_files (args .site )
1136+ # To navigate locally and view versioning script for parameters
1137+ # working is necessary run Chrome as "chrome
1138+ # --allow-file-access-from-files". Otherwise it will appear empty
1139+ # locally and working once is on the server.
11221140
1123- check_build (args .site )
1141+ error_count = len (error_log )
1142+ total_time = time .time () - tstart
1143+ progress (f"Total execution time: { total_time :.2f} seconds ({ total_time / 60 :.1f} minutes)" )
11241144
1125- if args .enablebackups :
1126- make_backup (args .site , args .destdir , args .backupdestdir )
1127- delete_old_wiki_backups (args .backupdestdir , N_BACKUPS_RETAIN )
1145+ if error_count > 0 :
1146+ progress ("Reprinting error messages:" , file = sys .stderr )
1147+ for msg in error_log :
1148+ print (f"\033 [1;31m[update.py][error]: { msg } \033 [0m" , file = sys .stderr ) # noqa: E702,E231
1149+ fatal (f"{ error_count } errors during Wiki build" )
1150+ else :
1151+ print ("Build completed without errors" )
11281152
1129- if args .destdir :
1130- copy_build (args .site , args .destdir )
1153+ sys .exit (0 )
11311154
1132- # To navigate locally and view versioning script for parameters
1133- # working is necessary run Chrome as "chrome
1134- # --allow-file-access-from-files". Otherwise it will appear empty
1135- # locally and working once is on the server.
11361155
1137- error_count = len ( error_log )
1138- total_time = time . time () - tstart
1139- progress ( f"Total execution time: { total_time :.2f } seconds ( { total_time / 60 :.1f } minutes)" )
1156+ def main ():
1157+ updater = WikiUpdater ()
1158+ updater . run ( )
11401159
1141- if error_count > 0 :
1142- progress ("Reprinting error messages:" , file = sys .stderr )
1143- for msg in error_log :
1144- print (f"\033 [1;31m[update.py][error]: { msg } \033 [0m" , file = sys .stderr ) # noqa: E702,E231
1145- fatal (f"{ error_count } errors during Wiki build" )
1146- else :
1147- print ("Build completed without errors" )
11481160
1149- sys .exit (0 )
1161+ if __name__ == "__main__" :
1162+ main ()
0 commit comments