Source code for asterism.pipeline_manager.processing_tools

"""

"""

__author__ = 'andrea tramacere'

import os

[docs]def mkdir(dir_name): if os.path.isdir(dir_name): print "dir %s exists"%dir_name elif os.path.isfile(dir_name): print "dir %s exists as file"%dir_name raise RuntimeError("dir %s exists as file"%dir_name) else: try: os.makedirs(dir_name) except OSError: pass
[docs]def read_config_file(file_name): f=open(file_name,'r') lines=f.readlines() f.close() return lines
[docs]def parse_process_section(lines,process_name,task_name): dict={} start_p=False stop_p=False start_t=False stop_t=False for line in lines: line=line.strip() if len(line)>0: if start_t==True and stop_t==False and start_p==True and stop_p==False: if line[0]!='#': tkn=line.strip().split('=') if len(tkn)==2: dict[tkn[0].strip()]=tkn[1].strip() if line[0]!='#' and line[0]=='[': line=line.strip(']\[') line=line.strip() line=line.replace(' ','') tkn=line.split(':') if tkn[1]==process_name and tkn[2]=='start': start_p=True if tkn[1]==process_name and tkn[2]=='stop': stop_p=True if tkn[1]==task_name and tkn[2]=='start' and start_p==True: start_t=True if tkn[1]==task_name and tkn[2]=='stop' and start_p==True: stop_t=True print dict return dict
[docs]def conv_str(val,verbose=False): try: return eval(val) except: return val
[docs]def write_html_page(html_file_name,images_list,images_per_page=20): html_index_file=open(html_file_name,'w') N_pages= len(images_list)/images_per_page+1 path_html_images_file=os.path.dirname(html_file_name) for i in xrange(N_pages): images_page='images_%4.4d-%4.4d_'%( i*images_per_page,(i+1)*images_per_page)+'images.html' print>>html_index_file,"""<a href="%s"> Images %4.4d - %4.4d </a> <br>"""%(images_page,i*images_per_page,(i+1)*images_per_page) write_images_page(path_html_images_file+'/'+images_page,images_list[i*images_per_page:(i+1)*images_per_page])
[docs]def write_images_page(html_file_name,images_list): html_file=open(html_file_name,'w') header=""" <!DOCTYPE html> <html> <head> <title>Images</title> </head> <body> <h1>Images</h1> """ end="""</body> </html>""" print>>html_file,header for image in images_list: print>>html_file,div_image(image) print>>html_file,end html_file.close()
[docs]def div_image(image_file): return """</div> <div class="image"> <img src="%s"> </div>"""%os.path.basename(image_file)