2020
2121# global variables
2222debug = False
23+ alibuild_exists = False
2324alibuild_arch , alibuild_opt , alibuild_dir_alice , alibuild_dir_sw = "" , "" , "" , ""
2425clean_do , clean_aggressive , clean_purge = 0 , 0 , 0
2526
@@ -83,16 +84,14 @@ def exec_cmd(cmd: str, msg=None, silent=False, safe=False):
8384 msg_fatal ("Command contains forbidden characters!" )
8485 try :
8586 if silent :
86- sp .run ( # nosec B602
87- cmd , shell = True , check = True , stdout = sp .DEVNULL , stderr = sp .DEVNULL
88- )
87+ sp .run (cmd , shell = True , check = True , stdout = sp .DEVNULL , stderr = sp .DEVNULL ) # nosec B602
8988 else :
9089 sp .run (cmd , shell = True , check = True ) # nosec B602
9190 except sp .CalledProcessError :
9291 msg_fatal (msg if msg else f"executing: { cmd } " )
9392
9493
95- def get_cmd (cmd : str , msg = None , safe = False ):
94+ def get_cmd (cmd : str , msg = None , safe = False ) -> str :
9695 """Get output of a shell command."""
9796 if debug :
9897 eprint (cmd )
@@ -104,6 +103,7 @@ def get_cmd(cmd: str, msg=None, safe=False):
104103 return out .strip ()
105104 except sp .CalledProcessError :
106105 msg_fatal (msg if msg else f"executing: { cmd } " )
106+ return ""
107107
108108
109109def chdir (path : str ):
@@ -148,22 +148,20 @@ def healthy_structure(dic_full: dict):
148148 msg_err ('"aliBuild" is not a dictionary.' )
149149 return False
150150 for key , val in template_alibuild .items ():
151- dic_alibuild [key ] = dic_alibuild .get (
152- key , val
153- ) # Create a default value if not set.
151+ dic_alibuild [key ] = dic_alibuild .get (key , val ) # Create a default value if not set.
154152 global alibuild_arch , alibuild_dir_alice , alibuild_opt , alibuild_dir_sw , clean_do , clean_aggressive , clean_purge
155153 alibuild_arch = dic_alibuild ["architecture" ]
156154 alibuild_dir_alice = dic_alibuild ["dir_alice" ]
157155 if not alibuild_dir_alice :
158156 msg_fatal (f"Invalid path: { alibuild_dir_alice } ." )
159157 alibuild_dir_alice_real = get_cmd (f"realpath { alibuild_dir_alice } " )
160- if not os .path .isdir (alibuild_dir_alice_real ):
158+ if alibuild_exists and not os .path .isdir (alibuild_dir_alice_real ):
161159 msg_fatal (f"{ alibuild_dir_alice } does not exist." )
162160 alibuild_opt = dic_alibuild ["options" ]
163161 alibuild_dir_sw = os .environ ["ALIBUILD_WORK_DIR" ]
164162 if not alibuild_dir_sw :
165163 msg_fatal ("ALIBUILD_WORK_DIR is not defined." )
166- if not os .path .isdir (alibuild_dir_sw ):
164+ if alibuild_exists and not os .path .isdir (alibuild_dir_sw ):
167165 msg_fatal (f"{ alibuild_dir_sw } does not exist." )
168166 clean_do = dic_alibuild ["clean" ]
169167 clean_aggressive = dic_alibuild ["clean_aggressive" ]
@@ -230,15 +228,11 @@ def update_branch(remote_upstream, remote_origin, branch_main, branch_current):
230228
231229 # Synchronise with the origin first, just in case there are some commits pushed from another local repository.
232230 if remote_origin :
233- msg_subsubstep (
234- f"-- Updating branch { branch_current } from { remote_origin } /{ branch_current } "
235- )
231+ msg_subsubstep (f"-- Updating branch { branch_current } from { remote_origin } /{ branch_current } " )
236232 exec_cmd (f"git pull --rebase { remote_origin } { branch_current } " )
237233
238234 # Synchronise with upstream/main.
239- msg_subsubstep (
240- f"-- Updating branch { branch_current } from { remote_upstream } /{ branch_main } "
241- )
235+ msg_subsubstep (f"-- Updating branch { branch_current } from { remote_upstream } /{ branch_main } " )
242236 exec_cmd (f"git pull --rebase { remote_upstream } { branch_main } " )
243237
244238 # Push to the origin.
@@ -304,20 +298,19 @@ def update_package(repo: str, dic_repo: dict):
304298 print ("Update deactivated. Skipping" )
305299 # Build package.
306300 if dic_repo .get ("build" , False ):
307- build_package (repo , dic_repo )
301+ if alibuild_exists :
302+ build_package (repo , dic_repo )
303+ else :
304+ msg_warn ("Skipping build because of absent aliBuild." )
308305
309306
310307def main ():
311308 """Main function"""
312309 parser = argparse .ArgumentParser (
313310 description = "This script updates local and remote Git repositories, builds aliBuild packages and does cleanup."
314311 )
315- parser .add_argument (
316- "database" , help = "database with package configuration and options"
317- )
318- parser .add_argument (
319- "-d" , "--debug" , action = "store_true" , help = "print debugging info"
320- )
312+ parser .add_argument ("database" , help = "database with package configuration and options" )
313+ parser .add_argument ("-d" , "--debug" , action = "store_true" , help = "print debugging info" )
321314 parser .add_argument ("-l" , action = "store_true" , help = "print latest commits and exit" )
322315 parser .add_argument ("-c" , action = "store_true" , help = "print configuration and exit" )
323316 args = parser .parse_args ()
@@ -343,16 +336,22 @@ def main():
343336 dic_repos = dic_in ["repositories" ]
344337
345338 # Check aliBuild
346- get_cmd ("which aliBuild" , "aliBuild not found" )
339+ global alibuild_exists
340+ try :
341+ get_cmd ("which aliBuild" , "aliBuild not found" )
342+ alibuild_exists = True
343+ except SystemExit :
344+ msg_warn ("aliBuild commands will be skipped." )
347345
348346 global alibuild_arch
349- if not alibuild_arch :
347+ if not alibuild_arch and alibuild_exists :
350348 alibuild_arch = get_cmd ("aliBuild architecture" , "Failed to get architecture" )
351349
352350 # Dry run: Print out configuration and exit.
353351 if show_config :
354352 msg_step ("Configuration" )
355- print (get_cmd ("aliBuild version" , "Failed to get aliBuild version" ))
353+ if alibuild_exists :
354+ print (get_cmd ("aliBuild version" , "Failed to get aliBuild version" ))
356355 print (f"Architecture: { alibuild_arch } " )
357356 print (f"aliBuild work dir: { alibuild_dir_sw } " )
358357 print (f"aliBuild build dir: { alibuild_dir_alice } " )
@@ -376,7 +375,7 @@ def main():
376375 update_package (repo , dic_repo )
377376
378377 # Cleanup
379- if clean_do :
378+ if clean_do and alibuild_exists :
380379 msg_step ("Cleaning aliBuild files" )
381380 alibuild_dir_arch = f"{ alibuild_dir_sw } /{ alibuild_arch } "
382381 alibuild_dir_build = f"{ alibuild_dir_sw } /BUILD"
@@ -388,9 +387,7 @@ def main():
388387 # Delete all symlinks to builds and recreate the latest ones to allow deleting of all other builds.
389388 if clean_purge :
390389 msg_substep ("- Purging builds" )
391- msg_warn (
392- "This action will run 'aliBuild build' for each development package."
393- )
390+ msg_warn ("This action will run 'aliBuild build' for each development package." )
394391 # Check existence of the build directories.
395392 msg_subsubstep ("-- Checking existence of the build directories" )
396393 for dir in (alibuild_dir_arch , alibuild_dir_build ):
@@ -429,9 +426,7 @@ def main():
429426 msg_subsubstep (f"-- Recreating symlinks in SOURCES to { repo } " )
430427 path_link = f"{ alibuild_dir_sw } /SOURCES/{ repo } /{ dic_repo ['branch' ]} "
431428 os .makedirs (path_link )
432- os .symlink (
433- get_cmd (f"realpath { dic_repo ['path' ]} " ), f"{ path_link } /0"
434- )
429+ os .symlink (get_cmd (f"realpath { dic_repo ['path' ]} " ), f"{ path_link } /0" )
435430
436431 # Get the directory size after cleaning.
437432 msg_substep (f"- Estimating size of { alibuild_dir_sw } " )
0 commit comments