@@ -384,16 +384,18 @@ def make_annotated_pdf(name, background, foreground, pdftk=False):
384384 print ("Written {} to {}" .format (os .stat (name ).st_size , name ))
385385
386386
387- if __name__ == "__main__" :
388- args = parse_args_or_exit (sys .argv [1 :])
387+ def main (args , tmp ):
388+ """
389+ Main entry point for the script
390+ """
389391 if CONVERT is None :
390392 sys .exit (
391393 "Unable to detect the required 'convert' executable from ImageMagick" )
392394 if shutil .which ("pdftk" ) is None and args .pdftk :
393395 sys .exit ("Used --pdftk flag but the pdftk executable was not found" )
394396
395- tmp = mkdtemp ()
396397 with get_ssh_client (args .password ) as client :
398+ print ("Gathering fata from the rM device" )
397399 notebook_id = get_notebook_id (client , args .prefix )
398400 if not notebook_id :
399401 sys .exit (
@@ -404,15 +406,25 @@ def make_annotated_pdf(name, background, foreground, pdftk=False):
404406 sys .exit ("Unable to copy any file from the device" )
405407
406408 metadata = get_extended_metadata (tmp , notebook_id , templates )
409+ print ("Preparing background document" )
407410 background = prepare_background (
408411 tmp , metadata , filenames , notebook_id , resizebg = args .pdftk )
412+ print ("Preparing annotations" )
409413 foreground = prepare_foreground (
410414 tmp , filenames , args .singlefile , args .coloured )
415+ print ("Preparing final PDF" )
411416 make_annotated_pdf (metadata ["visibleName" ],
412417 background , foreground , pdftk = args .pdftk )
413418
414- if not args .keeptmp :
415- print ("Cleaning up temporary folder {}" .format (tmp ))
416- shutil .rmtree (tmp )
417- else :
418- print ("The intermediate files are available in {}" .format (tmp ))
419+
420+ if __name__ == "__main__" :
421+ args = parse_args_or_exit (sys .argv [1 :])
422+ tmp = mkdtemp ()
423+ try :
424+ main (args , tmp )
425+ finally :
426+ if not args .keeptmp :
427+ print ("Cleaning up temporary folder {}" .format (tmp ))
428+ shutil .rmtree (tmp )
429+ else :
430+ print ("The intermediate files are available in {}" .format (tmp ))
0 commit comments