''' Program Name: build_webpage.py Contact(s): Mallory Row Abstract: This is run at the end of all step2 scripts in scripts/. This creates a job card to: 1) if needed, create website from EMC_verif-global template (webpage.tar) at specified user location on web server 2) send images to web server It then submits to the transfer queue. ''' import os import datetime import glob import shutil print("BEGIN: "+os.path.basename(__file__)) # Read in environment variables KEEPDATA = os.environ['KEEPDATA'] machine = os.environ['machine'] USHverif_global = os.environ['USHverif_global'] DATA = os.environ['DATA'] NET = os.environ['NET'] RUN = os.environ['RUN'] RUN_type = RUN.split('_')[0] QUEUESERV = os.environ['QUEUESERV'] ACCOUNT = os.environ['ACCOUNT'] PARTITION_BATCH = os.environ['PARTITION_BATCH'] webhost = os.environ['webhost'] webhostid = os.environ['webhostid'] webdir = os.environ['webdir'] print("Webhost: "+webhost) if RUN == 'fit2obs_plots': DATA = DATA.replace('/fit2obs_plots/data', '') webdir = webdir.replace( '/fits/horiz/'+os.environ['fit2obs_plots_expnlist'].split(' ')[1], '' ) web_fits_dir = os.path.join(DATA, RUN, 'fit2obs', 'web', 'fits') nimages = 0 for root, dirs, files in os.walk(web_fits_dir, topdown=False): nimages = nimages + len(glob.glob(os.path.join(root, '*.png'))) print("Webhost location: "+webdir) print("\nTotal images within "+web_fits_dir+": "+str(nimages)) else: image_list = os.listdir( os.path.join(DATA, RUN, 'metplus_output', 'images') ) nimages = len(image_list) print("Webhost location: "+webdir) print("\nTotal images in " +os.path.join(DATA, RUN, 'metplus_output', 'images')+": " +str(nimages)) # Set up job wall time information web_walltime = '180' walltime_seconds = datetime.timedelta(minutes=int(web_walltime)) \ .total_seconds() walltime = (datetime.datetime.min + datetime.timedelta(minutes=int(web_walltime))).time() # Create webpage templates for tropcyc def tropcyc_write_template_header(template_filename): """! Writes common webpage header information to template Args: template_filename - string of the full file path to write to Returns: """ template_type = template_filename.split('/')[-1].split('_')[0] template_file = open(template_filename, 'w') template_file.write( '\n' ) template_file.write( '\n' ) template_file.write('\n') template_file.write('
\n') template_file.write( '\n' ) template_file.write('