def scan_report():
    opt = option()
    job_dir = opt.job_dir
    need_design = opt.design
    syn = opt.synthesis
    #syn = ''
    family = opt.family
    report_name = opt.report_name #this is useless now
    for_pattern=''
    pap = opt.pap
    scan_mrp = tool_scan_lattice.ScanLatticeMrp()
    scan_twr = tool_scan_lattice.ScanLatticeTwr(pap)
    scan_time = tool_scan_lattice.ScanLatticeTime()
    target_fmax_re = re.compile(r"Target_Seed_is_(.+)")
    if family:
        for_pattern = '_'+family
    if syn:
        for_pattern = for_pattern + '_'+syn
    dir_pattern = re.compile(for_pattern)
    
    all_designs = []
    if os.path.isdir(job_dir):
        pass
    else:
        print 'The job_dir:%s is not a directory'%job_dir
        return
    for dir in os.listdir(job_dir):  # get all the design path
        dir2 =  os.path.join(job_dir,dir)
        if os.path.isdir(dir2):
            all_designs.append(dir)
        else:
            pass
    report_file_list = []

    
    if 1:
        root_dir = os.getcwd()
        dir = os.path.basename(opt.job_dir)
        if 1:
            scanner = (scan_mrp, scan_twr, scan_time)
            report_file = os.path.join(opt.job_dir,dir+'.csv')
            if report_file in report_file_list:
                pass
            else:
                report_file_list.append(report_file)
            if not_exists(report_file):
                title = ["Design"]
                for item in scanner: #mrp twr time
                    title += item.get_title()
                append_file(report_file, ",".join(title))
            if 1:
                report_name,subtex = os.path.splitext(report_file)
                report_file_mrp = report_name+'_mrp'+subtex
                if not_exists(report_file_mrp):
                    title = ["Design"]
                    #for item in scanner: #mrp twr time
                    title += (scanner[0]).get_title()
                    append_file(report_file_mrp, ",".join(title))
                report_file_twr = report_name+'_twr'+subtex
                if not_exists(report_file_twr):
                    title = ["Design"]
                    #for item in scanner: #mrp twr time
                    title += (scanner[1]).get_title()
                    append_file(report_file_twr, ",".join(title))
                report_file_time = report_name+'_time'+subtex
                if not_exists(report_file_time):
                    title = ["Design"] +['Target_seed']
                    #for item in scanner: #mrp twr time
                    title += (scanner[2]).get_title()
                    append_file(report_file_time, ",".join(title))
                report_file_clock = report_name+'_clock'+subtex
                append_file(report_file_clock, ",".join(['Design','Colck','Loads']))
        for design in all_designs:
            if need_design:
                if design == need_design:
                    pass
                else:
                    continue
            print_always( 'scanning %s'%design)
            design_path = os.path.join(job_dir,design)# e60_ecp3/g64
            srr_file = ''
            for dir in os.listdir(design_path): # dir:Target_Fmax_is_060MHz   
                dir_scan = os.path.join(design_path,dir)
                if (not re.search("Target", dir)) and os.path.isdir(dir_scan) and (not srr_file):
                    srr_file = get_unique_file([dir_scan, ".srr"])
                if re.search("Target", dir) and os.path.isdir(dir_scan):
                    pass
                else:
                    continue
                recover = RecoverPath(dir_scan)
                used_dir = ''
                for f_d in os.listdir(dir_scan):
                    f_d_full = os.path.join(dir_scan,f_d)
                    if os.path.isdir(f_d_full):
                        if used_dir:
                            print 'Worning: There are two implementation in the design'
                        used_dir = f_d_full
                
                if not srr_file:
                    pass
                else:
                    srr_file = os.path.join(design_path,dir,srr_file) 
                    scan_time.scan_srr(srr_file)
                mrp_file = get_unique_file([used_dir, ".mrp"])
                if not_exists(mrp_file, "map report file"):
                    
                    continue
                scan_mrp.scan_report(mrp_file)
                scan_time.scan_mrp(mrp_file)
                twr_file = time_file = par_file= ""
                target_fmax_for_time = '_'
                #------------------------------------------------#
                if 1:
                     useful_dir = used_dir
                     base_name = os.path.basename(useful_dir)
                     scan_time.reset_par_time_data()
                     target_fmax_for_match = target_fmax_re.search(dir)
                     if target_fmax_for_match:
                         target_fmax_for_time = target_fmax_for_match.group(1)
                     twr_p = os.path.join(useful_dir,'*'+base_name+".twr")
                     twr_file = get_unique_file(twr_p)
                     if not twr_file:
                         twr_file = get_unique_file([useful_dir, ".twr"])
                     time_file = os.path.join(useful_dir, time_file)
                     par_file = get_unique_file([useful_dir, ".par"])
                     if twr_file:
                         scan_twr.scan_report(twr_file)
                         scan_time.scan_report(time_file)
                         scan_time.scan_par(par_file)
                         #########################
                         #time_title = ['design']+scan_time.get_title2()
                         srr_data = scan_time.get_srr_time_data()
                         mrp_data = scan_time.get_mrp_time_data()
                         par_data = scan_time.get_par_time_data()
                         real_cpu_total = scan_time.get_total_time()
                         all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + real_cpu_total.items() )
                         data_list = []
                         for key in scan_time.get_title():
                             value = all_time_data.get(key,'NA')
                             data_list.append(value)
                         data_list2 = [design]+[target_fmax_for_time] +data_list
                         append_file(report_file_time,",".join(data_list2))
                             
                         #########################
                         #data = [design] + scan_mrp.get_data() + \
                         #      scan_twr.get_data() + data_list
                         if all_time_data['Complete'] == 'NA' or all_time_data['Par_Done'] == 'NA':
                             data_list = ['_']*len(scan_mrp.get_data()) +['_']*len(scan_twr.get_data()) +\
                                         ['_']*len(data_list)
                         else:
                             data_list = scan_mrp.get_data() + \
                               scan_twr.get_data() + data_list
                         data = [design] + data_list
                         append_file(report_file, ",".join(data))
                         data = [design]
                         append_file(report_file_mrp,",".join([design]+ scan_mrp.get_data() ))
                         append_file(report_file_twr,",".join([design]+ scan_twr.get_data() ))
                         #append_file(report_file_time,",".join([design]+ scan_time.get_data()))
                         scan_time.reset_par_time_data()
                     if not twr_file:
                         srr_data = scan_time.get_srr_time_data()
                         mrp_data = scan_time.get_mrp_time_data()
                         par_data = scan_time.get_par_time_data()
                         real_cpu_total = scan_time.get_total_time()
                         all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + \
                                               real_cpu_total.items() )
                         data_list = []
                         for key in scan_time.get_title():
                             value = all_time_data.get(key,'NA')
                             data_list.append(value)
                         data_list2 = [design]+[target_fmax_for_time] +data_list
                         append_file(report_file_time,",".join(data_list2))
                         #data = [design] + scan_mrp.get_data()+ data_list
                         if all_time_data['Complete'] == 'NA' or all_time_data['Par_Done'] == 'NA':
                             data = [design] + ['_']*len(scan_mrp.get_data())+  ['_']*len(data_list)
                         else:
                             data = [design] + scan_mrp.get_data()+ data_list
                         append_file(report_file, ",".join(data))
                         append_file(report_file_mrp,",".join([design]+ scan_mrp.get_data()))
                         scan_time.reset_par_time_data()
                scan_mrp.scan_clocks(mrp_file)
                clock_dict = scan_mrp.get_parse_line_clocks()
                for key in clock_dict.keys():
                    line = design+','+key+','+clock_dict[key]
                    append_file(report_file_clock,line)
                recover.run()
        os.chdir(root_dir)
def scan_report():
    opt = option()
    job_dir = opt.job_dir
    job_dir = os.path.abspath(job_dir)
    need_design = opt.design
    syn = opt.synthesis
    #syn = ''
    family = opt.family
    report_name = opt.report_name  #this is useless now
    for_pattern = ''
    pap = opt.pap
    scan_mrp = tool_scan_lattice.ScanLatticeMrp()
    scan_twr = tool_scan_lattice.ScanLatticeTwr(pap)
    scan_time = tool_scan_lattice.ScanLatticeTime()
    target_fmax_re = re.compile(r"Target_Fmax_is_(.+)MHz")
    if family:
        for_pattern = '_' + family
    if syn:
        for_pattern = for_pattern + '_' + syn
    dir_pattern = re.compile(for_pattern)

    all_designs = []
    if os.path.isdir(job_dir):
        for d in os.listdir(job_dir):
            if d.endswith('.csv'):
                d = os.path.join(job_dir, d)
                os.remove(d)
        pass
    else:
        print 'The job_dir:%s is not a directory' % job_dir
        return
    for dir in os.listdir(job_dir):  # get all the design path
        dir2 = os.path.join(job_dir, dir)
        if os.path.isdir(dir2):
            all_designs.append(dir)
        else:
            pass
    report_file_list = []

    if 1:
        root_dir = os.getcwd()
        dir = os.path.basename(opt.job_dir)
        if 1:
            scanner = (scan_mrp, scan_twr, scan_time)
            report_file = os.path.join(opt.job_dir, dir + '.csv')
            if report_file in report_file_list:
                pass
            else:
                report_file_list.append(report_file)
            if not_exists(report_file):
                title = ["Design"]
                for item in scanner:  #mrp twr time
                    title += item.get_title()
                append_file(report_file, ",".join(title))
            if 1:
                report_name, subtex = os.path.splitext(report_file)
                report_file_mrp = report_name + '_mrp' + subtex
                if not_exists(report_file_mrp):
                    title = ["Design"]
                    #for item in scanner: #mrp twr time
                    title += (scanner[0]).get_title()
                    append_file(report_file_mrp, ",".join(title))
                report_file_twr = report_name + '_twr' + subtex
                if not_exists(report_file_twr):
                    title = ["Design"]
                    #for item in scanner: #mrp twr time
                    title += (scanner[1]).get_title()
                    append_file(report_file_twr, ",".join(title))
                report_file_time = report_name + '_time' + subtex
                if not_exists(report_file_time):
                    title = ["Design"] + ['Target_fmax']
                    #for item in scanner: #mrp twr time
                    title += (scanner[2]).get_title()
                    append_file(report_file_time, ",".join(title))
                report_file_clock = report_name + '_clock' + subtex
                append_file(report_file_clock,
                            ",".join(['Design', 'Colck', 'Loads']))
        for design in all_designs:
            lock = Lock()
            if need_design:
                if design == need_design:
                    pass
                else:
                    continue

            def scan_sigal(job_dir, design):
                print_always('scanning %s' % design)
                design_path = os.path.join(job_dir, design)  # e60_ecp3/g64
                srr_file = ''
                for dir in os.listdir(
                        design_path):  # dir:Target_Fmax_is_060MHz
                    dir_scan = os.path.join(design_path, dir)
                    if (not re.search("Target", dir)
                        ) and os.path.isdir(dir_scan) and not srr_file:
                        srr_file = get_unique_file([dir_scan, ".srr"])
                for dir in os.listdir(
                        design_path):  # dir:Target_Fmax_is_060MHz
                    dir_scan = os.path.join(design_path, dir)
                    #if (not re.search("Target", dir)) and os.path.isdir(dir_scan) and not srr_file:
                    #    srr_file = get_unique_file([dir_scan, ".srr"])
                    if re.search("Target", dir) and os.path.isdir(dir_scan):
                        pass
                    else:
                        continue
                    recover = RecoverPath(dir_scan)
                    used_dir = ''
                    for f_d in os.listdir(dir_scan):
                        f_d_full = os.path.join(dir_scan, f_d)
                        if os.path.isdir(f_d_full):
                            if used_dir:
                                print 'Worning: There are two implementation in the design'
                            used_dir = f_d_full
                    #srr_file = get_unique_file([used_dir, ".srr"])
                    if not srr_file:
                        pass
                    else:
                        srr_file = os.path.join(design_path, dir, srr_file)
                        scan_time.scan_srr(srr_file)
                    mrp_file = get_unique_file([used_dir, ".mrp"])
                    if not_exists(mrp_file, "map report file"):

                        continue
                    scan_mrp.scan_report(mrp_file)
                    scan_time.scan_mrp(mrp_file)
                    twr_file = time_file = par_file = ""
                    target_fmax_for_time = '_'
                    #------------------------------------------------#
                    if 1:
                        useful_dir = used_dir
                        base_name = os.path.basename(useful_dir)
                        scan_time.reset_par_time_data()
                        target_fmax_for_match = target_fmax_re.search(dir)
                        if target_fmax_for_match:
                            target_fmax_for_time = target_fmax_for_match.group(
                                1)
                        twr_p = os.path.join(useful_dir,
                                             '*' + base_name + ".twr")
                        twr_file = get_unique_file(twr_p)
                        if not twr_file:
                            twr_file = get_unique_file([useful_dir, ".twr"])
                        time_file = os.path.join(useful_dir, time_file)
                        par_file = get_unique_file([useful_dir, ".par"])
                        if twr_file:
                            scan_twr.scan_report(twr_file)
                            scan_time.scan_report(time_file)
                            scan_time.scan_par(par_file)
                            #########################
                            #time_title = ['design']+scan_time.get_title2()
                            srr_data = scan_time.get_srr_time_data()
                            mrp_data = scan_time.get_mrp_time_data()
                            par_data = scan_time.get_par_time_data()
                            real_cpu_total = scan_time.get_total_time()
                            all_time_data = dict(srr_data.items() +
                                                 mrp_data.items() +
                                                 par_data.items() +
                                                 real_cpu_total.items())
                            data_list = []
                            for key in scan_time.get_title():
                                value = all_time_data.get(key, 'NA')
                                data_list.append(value)
                            data_list2 = [design] + [target_fmax_for_time
                                                     ] + data_list
                            lock.acquire()
                            append_file(report_file_time, ",".join(data_list2))

                            #########################
                            #data = [design] + scan_mrp.get_data() + \
                            #      scan_twr.get_data() + data_list
                            if all_time_data[
                                    'Complete'] == 'NA' or all_time_data[
                                        'Par_Done'] == 'NA':
                                data_list = ['_']*len(scan_mrp.get_data()) +['_']*len(scan_twr.get_data()) +\
                                            ['_']*len(data_list)
                            else:
                                data_list = scan_mrp.get_data() + \
                                  scan_twr.get_data() + data_list
                            data = [design] + data_list
                            append_file(report_file, ",".join(data))
                            data = [design]
                            append_file(
                                report_file_mrp,
                                ",".join([design] + scan_mrp.get_data()))
                            append_file(
                                report_file_twr,
                                ",".join([design] + scan_twr.get_data()))
                            #append_file(report_file_time,",".join([design]+ scan_time.get_data()))
                            scan_time.reset_par_time_data()
                            #lock.release()
                        if not twr_file:
                            srr_data = scan_time.get_srr_time_data()
                            mrp_data = scan_time.get_mrp_time_data()
                            par_data = scan_time.get_par_time_data()
                            real_cpu_total = scan_time.get_total_time()
                            all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + \
                                                  real_cpu_total.items() )
                            data_list = []
                            for key in scan_time.get_title():
                                value = all_time_data.get(key, 'NA')
                                data_list.append(value)
                            data_list2 = [design] + [target_fmax_for_time
                                                     ] + data_list
                            lock.acquire()
                            append_file(report_file_time, ",".join(data_list2))
                            #data = [design] + scan_mrp.get_data()+ data_list
                            if all_time_data[
                                    'Complete'] == 'NA' or all_time_data[
                                        'Par_Done'] == 'NA':
                                data = [design] + ['_'] * len(
                                    scan_mrp.get_data()) + ['_'
                                                            ] * len(data_list)
                            else:
                                data = [design
                                        ] + scan_mrp.get_data() + data_list
                            append_file(report_file, ",".join(data))
                            append_file(
                                report_file_mrp,
                                ",".join([design] + scan_mrp.get_data()))
                            scan_time.reset_par_time_data()
                    scan_mrp.scan_clocks(mrp_file)
                    clock_dict = scan_mrp.get_parse_line_clocks()
                    for key in clock_dict.keys():
                        line = design + ',' + key + ',' + clock_dict[key]
                        append_file(report_file_clock, line)
                    lock.release()
                    recover.run()

            Process(target=scan_sigal, args=(job_dir, design)).start()
        os.chdir(root_dir)
    for f in report_file_list:
        if os.path.isfile(f):
            file_sorted, note, design_fmax = report_sort.sort_csv(f)
            report_sort.write_note(file_sorted, note)
    file_hand_pass = file('pass_case.log', 'w')
    #----------read fail case first:
    try:
        file_hand_fail = file('fail_case.log', 'r')
        fail_case_lines = file_hand_fail.readlines()
        file_hand_fail.close()
        fail_case_lines2 = [
            f_c.split(':')[0].strip() for f_c in fail_case_lines
        ]
    except:
        fail_case_lines2 = []
    file_hand_fail = file('fail_case.log', 'w')
    for key in design_fmax.keys():
        v = design_fmax[key]

        if re.search(r'\d', v):
            file_hand_pass.write(key + '\n')
        else:
            if key in fail_case_lines2:
                fail_k = fail_case_lines[fail_case_lines2.index(key)]
                file_hand_fail.write(fail_k.strip() + '\n')
            else:
                file_hand_fail.write(key + '\n')
    file_hand_pass.close()
    file_hand_fail.close()

    #----------------update run_stand-------------------#
    if 1:
        pass_log = glob.glob('pass_case.log')
        if pass_log:
            pass_log = pass_log[0]
        else:
            pass_log = '__'
        if os.path.isfile(pass_log):
            file_hand = file(pass_log, 'r')
            lines = file_hand.readlines()
            file_hand.close()
            stand_name = glob.glob('*' + '_run_stand.bat')
            if stand_name:
                stand_name = stand_name[0]
            #stand_name = os.path.join(top_base,top_base2+'_'+syn+'_run_standard.bat')
            else:
                stand_name = ''
            run_standard = file(stand_name, 'r')
            run_standard_lines = run_standard.readlines()
            run_standard_lines = list(set(run_standard_lines))
            run_standard.close()
            #--------------
            try:
                again_name = glob.glob('*' + 'run_again.bat')
                if again_name:
                    again_name = again_name[0]
                #stand_name = os.path.join(top_base,top_base2+'_'+syn+'_run_standard.bat')
                else:
                    again_name = ''
                try:
                    again = file(again_name, 'r')
                    again_lines = again.readlines()
                    again_lines = list(set(again_lines))
                    again.close()
                    replaced_job_dir = os.path.basename(os.getcwd())
                    again_lines = [
                        re.sub(r'--job-dir=\S+',
                               '--job-dir=' + replaced_job_dir, ag)
                        for ag in again_lines
                    ]
                    new_again = []
                    #again_lines = [re.sub(r'--job-dir=\S+',replaced_job_dir,ag) for ag in again_lines]
                    #for ag in again_lines:
                    for ag in again_lines:
                        file_f = re.findall('--file=(\S+)', ag)
                        if file_f:
                            new_f = os.path.basename(file_f[-1])
                            ag = re.sub(r'--file=(\S+)', '--file=' + new_f, ag)
                        new_again.append(ag)

                    run_standard_lines1 = run_standard_lines + new_again
                    run_standard_lines1 = list(set(run_standard_lines1))
                except:
                    run_standard_lines1 = list(set(run_standard_lines))
                    #pass

                #run_standard_lines = run_standard_lines + again_lines
            except:
                pass

            useful_lines = []
            for case in lines:
                case = case.strip()
                if not case:
                    continue
                else:
                    pass
                case_tab = '--design=' + case
                case_tab_re = re.compile(case_tab + r'(\s+|$)')
                for line in run_standard_lines1:
                    line = line.strip()
                    if not line:
                        continue
                    if case_tab_re.search(line):
                        try:
                            fmax = float(design_fmax[case.strip()])
                            fmax = str(int(fmax))
                            line = re.sub(r'--fmax-sweep=[\s\d]+\d', '', line)
                            line2 = line + ' --fmax-sweep=' + fmax + ' ' + fmax + ' ' + '10 \n'
                            useful_lines.append(line2)
                        except:
                            #line2 = line
                            pass

            run_standard = file(stand_name, 'w')
            run_standard.writelines(useful_lines)
            run_standard.close()
def scan_report():
    opt = option()
    job_dir = opt.job_dir
    job_dir = os.path.abspath(job_dir)
    need_design = opt.design
    syn = opt.synthesis
    #syn = ''
    family = opt.family
    report_name = opt.report_name  #this is useless now
    for_pattern = ''
    pap = opt.pap
    scan_mrp = tool_scan_lattice.ScanLatticeMrp()
    scan_twr = tool_scan_lattice.ScanLatticeTwr(pap)
    scan_time = tool_scan_lattice.ScanLatticeTime()
    target_fmax_re = re.compile(r"Target_Fmax_is_(.+)MHz")
    if family:
        for_pattern = '_' + family
    if syn:
        for_pattern = for_pattern + '_' + syn
    dir_pattern = re.compile(for_pattern)

    all_designs = []
    if os.path.isdir(job_dir):
        for d in os.listdir(job_dir):
            if d.endswith('.csv'):
                d = os.path.join(job_dir, d)
                os.remove(d)
        pass
    else:
        print 'The job_dir:%s is not a directory' % job_dir
        return
    for dir in os.listdir(job_dir):  # get all the design path
        dir2 = os.path.join(job_dir, dir)
        if os.path.isdir(dir2):
            all_designs.append(dir)
        else:
            pass
    report_file_list = []

    if 1:
        root_dir = os.getcwd()
        dir = os.path.basename(opt.job_dir)
        if 1:
            scanner = (scan_mrp, scan_twr, scan_time)
            report_file = os.path.join(opt.job_dir, dir + '.csv')
            if report_file in report_file_list:
                pass
            else:
                report_file_list.append(report_file)
            if not_exists(report_file):
                title = ["Design"]
                for item in scanner:  #mrp twr time
                    title += item.get_title()
                append_file(report_file, ",".join(title))
            if 1:
                report_name, subtex = os.path.splitext(report_file)
                report_file_mrp = report_name + '_mrp' + subtex
                if not_exists(report_file_mrp):
                    title = ["Design"]
                    #for item in scanner: #mrp twr time
                    title += (scanner[0]).get_title()
                    append_file(report_file_mrp, ",".join(title))
                report_file_twr = report_name + '_twr' + subtex
                if not_exists(report_file_twr):
                    title = ["Design"]
                    #for item in scanner: #mrp twr time
                    title += (scanner[1]).get_title()
                    append_file(report_file_twr, ",".join(title))
                report_file_time = report_name + '_time' + subtex
                if not_exists(report_file_time):
                    title = ["Design"] + ['Target_fmax']
                    #for item in scanner: #mrp twr time
                    title += (scanner[2]).get_title()
                    append_file(report_file_time, ",".join(title))
                report_file_clock = report_name + '_clock' + subtex
                append_file(report_file_clock,
                            ",".join(['Design', 'Colck', 'Loads']))
        #for design in all_designs:
        for root1, dirs1, files1 in os.walk(job_dir):
            root1 = os.path.abspath(root1)
            find_mrp = 0
            for f in files1:
                if f.endswith('.mrp'):
                    find_mrp = 1
                    break
            if find_mrp == 1:
                pass
            else:
                continue
            design_path = os.path.join(root1)  # e60_ecp3/g64
            srr_file = ''
            for dir in os.listdir(design_path):  # dir:Target_Fmax_is_060MHz
                dir_scan = os.path.join(design_path, dir)
                if (not re.search("Target", dir)
                    ) and os.path.isdir(dir_scan) and not srr_file:
                    srr_file = get_unique_file([dir_scan, ".srr"])
            for dir in os.listdir(design_path):  # dir:Target_Fmax_is_060MHz

                #if (not re.search("Target", dir)) and os.path.isdir(dir_scan) and not srr_file
                recover = RecoverPath(design_path)

                mrp_file = get_unique_file([design_path, ".mrp"])
                if not_exists(mrp_file, "map report file"):

                    continue
                scan_mrp.scan_report(mrp_file)
                scan_time.scan_mrp(mrp_file)
                append_file(report_file_mrp,
                            ",".join([design_path] + scan_mrp.get_data()))
                recover.run()
        os.chdir(root_dir)
    for f in report_file_list:
        if os.path.isfile(f):
            file_sorted, note, design_fmax = report_sort.sort_csv(f)
            report_sort.write_note(file_sorted, note)
    file_hand_pass = file('pass_case.log', 'w')
    #----------read fail case first:
    try:
        file_hand_fail = file('fail_case.log', 'r')
        fail_case_lines = file_hand_fail.readlines()
        file_hand_fail.close()
        fail_case_lines2 = [
            f_c.split(':')[0].strip() for f_c in fail_case_lines
        ]
    except:
        fail_case_lines2 = []
    file_hand_fail = file('fail_case.log', 'w')
    for key in design_fmax.keys():
        v = design_fmax[key]

        if re.search(r'\d', v):
            file_hand_pass.write(key + '\n')
        else:
            if key in fail_case_lines2:
                fail_k = fail_case_lines[fail_case_lines2.index(key)]
                file_hand_fail.write(fail_k.strip() + '\n')
            else:
                file_hand_fail.write(key + '\n')
    file_hand_pass.close()
    file_hand_fail.close()
Example #4
0
def scan_report():
    opt = option()
    job_dir = opt.job_dir
    job_dir = os.path.abspath(job_dir)
    need_design = opt.design
    if not need_design:
        print 'In the bqs, you have to specify the design name'
        return
    pap = opt.pap
    report_dir = opt.report_dir
    print '--==--' * 20
    print report_dir
    print os.path.isdir(report_dir)
    print '--==--' * 20
    scan_mrp = tool_scan_lattice.ScanLatticeMrp()
    scan_twr = tool_scan_lattice.ScanLatticeTwr(pap)
    scan_time = tool_scan_lattice.ScanLatticeTime()
    target_fmax_re = re.compile(r"Target_Fmax_is_(.+)MHz")

    if os.path.isdir(job_dir):
        pass
    else:
        print 'The job_dir:%s is not a directory' % job_dir
        return
    design_path = os.path.join(job_dir, need_design)
    design_path = re.sub(r'\\', '/', design_path)
    report_file_list = []

    if 1:
        root_dir = os.getcwd()
        dir = os.path.basename(opt.job_dir)
        design = os.path.basename(design_path)
        if 1:
            scanner = (scan_mrp, scan_twr, scan_time)
            report_file = os.path.join(opt.job_dir,
                                       dir + '_' + design + '.csv')
            if report_file in report_file_list:
                pass
            else:
                report_file_list.append(report_file)
            if not_exists(report_file):
                title = ["Design"]
                for item in scanner:  #mrp twr time
                    title += item.get_title()
                append_file(report_file, ",".join(title))
            if 1:
                report_name, subtex = os.path.splitext(report_file)
                report_file_mrp = report_name + '_mrp' + subtex
                if not_exists(report_file_mrp):
                    title = ["Design"]
                    #for item in scanner: #mrp twr time
                    title += (scanner[0]).get_title()
                    append_file(report_file_mrp, ",".join(title))
                report_file_twr = report_name + '_twr' + subtex
                if not_exists(report_file_twr):
                    title = ["Design"]
                    #for item in scanner: #mrp twr time
                    title += (scanner[1]).get_title()
                    append_file(report_file_twr, ",".join(title))
                report_file_time = report_name + '_time' + subtex
                if not_exists(report_file_time):
                    title = ["Design"] + ['Target_fmax']
                    #for item in scanner: #mrp twr time
                    title += (scanner[2]).get_title()
                    append_file(report_file_time, ",".join(title))
                report_file_clock = report_name + '_clock' + subtex
                append_file(report_file_clock,
                            ",".join(['Design', 'Colck', 'Loads']))
        if 1:  # begin scan case
            if need_design:
                if design == need_design:
                    pass
                else:
                    return
            print_always('scanning %s' % design)
            srr_file = ''
            for dir in os.listdir(design_path):  # dir:Target_Fmax_is_060MHz
                dir_scan = os.path.join(design_path, dir)
                if (not re.search("Target", dir)
                    ) and os.path.isdir(dir_scan) and not srr_file:
                    srr_file = get_unique_file([dir_scan, ".srr"])
            for dir in os.listdir(design_path):  # dir:Target_Fmax_is_060MHz
                dir_scan = os.path.join(design_path, dir)
                #if (not re.search("Target", dir)) and os.path.isdir(dir_scan) and not srr_file:
                #    srr_file = get_unique_file([dir_scan, ".srr"])
                if re.search("Target", dir) and os.path.isdir(dir_scan):
                    pass
                else:
                    continue
                recover = RecoverPath(dir_scan)
                used_dir = ''
                for f_d in os.listdir(dir_scan):
                    f_d_full = os.path.join(dir_scan, f_d)
                    if os.path.isdir(f_d_full):
                        if used_dir:
                            print 'Warning: There are two implementation in the design'
                        used_dir = f_d_full
                #srr_file = get_unique_file([used_dir, ".srr"])
                if not srr_file:
                    pass
                else:
                    srr_file = os.path.join(design_path, dir, srr_file)
                    scan_time.scan_srr(srr_file)
                mrp_file = get_unique_file([used_dir, ".mrp"])
                if not_exists(mrp_file, "map report file"):

                    continue
                scan_mrp.scan_report(mrp_file)
                scan_time.scan_mrp(mrp_file)
                twr_file = time_file = par_file = ""
                target_fmax_for_time = '_'
                #------------------------------------------------#
                if 1:
                    useful_dir = used_dir
                    base_name = os.path.basename(useful_dir)
                    scan_time.reset_par_time_data()
                    target_fmax_for_match = target_fmax_re.search(dir)
                    if target_fmax_for_match:
                        target_fmax_for_time = target_fmax_for_match.group(1)
                    twr_p = os.path.join(useful_dir, '*' + base_name + ".twr")
                    twr_file = get_unique_file(twr_p)
                    if not twr_file:
                        twr_file = get_unique_file([useful_dir, ".twr"])
                    time_file = os.path.join(useful_dir, time_file)
                    par_file = get_unique_file([useful_dir, ".par"])
                    if twr_file:
                        scan_twr.scan_report(twr_file)
                        scan_time.scan_report(time_file)
                        scan_time.scan_par(par_file)
                        #########################
                        #time_title = ['design']+scan_time.get_title2()
                        srr_data = scan_time.get_srr_time_data()
                        mrp_data = scan_time.get_mrp_time_data()
                        par_data = scan_time.get_par_time_data()
                        real_cpu_total = scan_time.get_total_time()
                        all_time_data = dict(srr_data.items() +
                                             mrp_data.items() +
                                             par_data.items() +
                                             real_cpu_total.items())
                        data_list = []
                        for key in scan_time.get_title():
                            value = all_time_data.get(key, 'NA')
                            data_list.append(value)
                        data_list2 = [design] + [target_fmax_for_time
                                                 ] + data_list
                        append_file(report_file_time, ",".join(data_list2))

                        #########################
                        #data = [design] + scan_mrp.get_data() + \
                        #      scan_twr.get_data() + data_list
                        if all_time_data['Complete'] == 'NA' or all_time_data[
                                'Par_Done'] == 'NA':
                            data_list = ['_']*len(scan_mrp.get_data()) +['_']*len(scan_twr.get_data()) +\
                                        ['_']*len(data_list)
                        else:
                            data_list = scan_mrp.get_data() + \
                              scan_twr.get_data() + data_list
                        data = [design] + data_list
                        append_file(report_file, ",".join(data))
                        #-------------------
                        #report_sort_bqs.sort_csv(report_file,job_dir)
                        #-------------------
                        data = [design]
                        append_file(report_file_mrp,
                                    ",".join([design] + scan_mrp.get_data()))
                        append_file(report_file_twr,
                                    ",".join([design] + scan_twr.get_data()))
                        #append_file(report_file_time,",".join([design]+ scan_time.get_data()))
                        scan_time.reset_par_time_data()
                    if not twr_file:
                        srr_data = scan_time.get_srr_time_data()
                        mrp_data = scan_time.get_mrp_time_data()
                        par_data = scan_time.get_par_time_data()
                        real_cpu_total = scan_time.get_total_time()
                        all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + \
                                              real_cpu_total.items() )
                        data_list = []
                        for key in scan_time.get_title():
                            value = all_time_data.get(key, 'NA')
                            data_list.append(value)
                        data_list2 = [design] + [target_fmax_for_time
                                                 ] + data_list
                        append_file(report_file_time, ",".join(data_list2))
                        #data = [design] + scan_mrp.get_data()+ data_list
                        if all_time_data['Complete'] == 'NA' or all_time_data[
                                'Par_Done'] == 'NA':
                            data = [design] + ['_'] * len(
                                scan_mrp.get_data()) + ['_'] * len(data_list)
                        else:
                            data = [design] + scan_mrp.get_data() + data_list
                        append_file(report_file, ",".join(data))
                        #-------------------
                        #report_sort_bqs.sort_csv(report_file,job_dir)

                        #-------------------

                        append_file(report_file_mrp,
                                    ",".join([design] + scan_mrp.get_data()))
                        scan_time.reset_par_time_data()
                scan_mrp.scan_clocks(mrp_file)
                clock_dict = scan_mrp.get_parse_line_clocks()
                for key in clock_dict.keys():
                    line = design + ',' + key + ',' + clock_dict[key]
                    append_file(report_file_clock, line)
                recover.run()
        report_sort_bqs.sort_csv(report_file, report_dir)
        os.chdir(root_dir)
 def scan_report(self):
     scan_mrp = tool_scan_lattice.ScanLatticeMrp()
     scan_twr = tool_scan_lattice.ScanLatticeTwr(self.pap)
     scan_time = tool_scan_lattice.ScanLatticeTime()
     if self.family:
         for_pattern = '_'+family
     if self.synthesis:
         for_pattern = for_pattern + '_'+syn
     dir_pattern = re.compile(for_pattern)
     if os.path.isdir(self.job_dir):
         pass
     else:
         print 'Error: The job_dir:%s is not a directory'%self.job_dir
         return
     report_file_list = []
     all_designs = []
     if not self.design:
         for dir in os.listdir(job_dir):  # get all the design path
             dir2 =  os.path.join(job_dir,dir)
             if os.path.isdir(dir2):
                 all_designs.append(dir)
             else:
                 pass
     else:
         dir = os.path.join(job_dir,self.design)
         if os.path.isdir(dir):
             all_designs.append(dir)
         else:
             print 'Error: Can not find case:%s'%self.design
     root_dir = os.getcwd()
     for design in all_designs:
         print_always( 'scanning %s'%design)
         design_path = os.path.join(job_dir,design)
         for dir in os.listdir(design_path):
             if dir_pattern.search(dir) and os.path.isdir(os.path.join(design_path,dir)) and dir.startswith('_'):
                 #####################
                 scanner = (scan_mrp, scan_twr, scan_time)
                 report_file = self.report_file
                 if report_file in report_file_list:
                     pass
                 else:
                     report_file_list.append(report_file)
                 if not_exists(report_file):
                     title = ["Design"]
                     for item in scanner: #mrp twr time
                         title += item.get_title()
                     append_file(report_file, ",".join(title))
                 if 1:
                     report_name,subtex = os.path.splitext(report_file)
                     report_file_mrp = report_name+'_mrp'+subtex
                     if not_exists(report_file_mrp):
                         title = ["Design"]
                         #for item in scanner: #mrp twr time
                         title += (scanner[0]).get_title()
                         append_file(report_file_mrp, ",".join(title))
                     report_file_twr = report_name+'_twr'+subtex
                     if not_exists(report_file_twr):
                         title = ["Design"]
                         #for item in scanner: #mrp twr time
                         title += (scanner[1]).get_title()
                         append_file(report_file_twr, ",".join(title))
                     report_file_time = report_name+'_time'+subtex
                     if not_exists(report_file_time):
                         title = ["Design"] +['Target_fmax']
                         #for item in scanner: #mrp twr time
                         title += (scanner[2]).get_title()
                         append_file(report_file_time, ",".join(title))
                     report_file_clock = report_name+'_clock'+subtex
                     if not_exists(report_file_clock):
                         append_file(report_file_clock, ",".join(['Design','Colck','Loads']))
            
                 dir_scan = os.path.join(design_path,dir)
                 recover = RecoverPath(dir_scan)
                 if not_exists('rev_1', "srr file directory"):
                     continue
                 srr_file = get_unique_file([os.path.join(design_path,dir,'rev_1'), ".srr"])
                 if not srr_file:
                     pass
                 else:
                     srr_file = os.path.join(design_path,dir,'rev_1',srr_file) 
                     scan_time.scan_srr(srr_file)
                 _project_name = "%s_%s" % (dir, design[:7])
                 project_name = _project_name.strip("_")
                 mrp_file = project_name + ".mrp"
                 if not_exists(mrp_file, "map report file"):
                     continue
                 scan_mrp.scan_report(mrp_file)
                 scan_time.scan_mrp(mrp_file)
                 twr_file = time_file = par_file= ""
                 target_fmax_for_time = '_'
                 target_fmax_re = re.compile(r"Target_Fmax_is_(.+)MHz")
                 for foo in os.listdir("."):
                     if os.path.isdir(foo):
                         if re.search("Target", foo):
                             scan_time.reset_par_time_data()
                             print_always("  Scanning %s" % foo)
                             target_fmax_for_match = target_fmax_re.search(foo)
                             if target_fmax_for_match:
                                 target_fmax_for_time = target_fmax_for_match.group(1)
                             twr_file = get_unique_file([foo, ".twr"])
                             time_file = os.path.join(foo, time_file)
                             par_file = get_unique_file([foo, ".par"])
                         elif re.search("\.dir$", foo):
                             twr_file = get_unique_file([foo, ".twr"])
                             par_file = get_unique_file([foo, ".par"])
                             time_file = time_file
                         else:
                             continue
         
                         if twr_file:
                             scan_twr.scan_report(twr_file)
                             scan_time.scan_report(time_file)
                             scan_time.scan_par(par_file)
                             #########################
                             #time_title = ['design']+scan_time.get_title2()
                             srr_data = scan_time.get_srr_time_data()
                             mrp_data = scan_time.get_mrp_time_data()
                             par_data = scan_time.get_par_time_data()
                             real_cpu_total = scan_time.get_total_time()
                             all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + real_cpu_total.items() )
                             data_list = []
                             for key in scan_time.get_title():
                                 value = all_time_data.get(key,'NA')
                                 data_list.append(value)
                             data_list2 = [design]+[target_fmax_for_time] +data_list
                             append_file(report_file_time,",".join(data_list2))
                                 
                             #########################
                             #data = [design] + scan_mrp.get_data() + \
                             #      scan_twr.get_data() + data_list
                             if all_time_data['Complete'] == 'NA' or all_time_data['Par_Done'] == 'NA':
                                 data_list = ['_']*len(scan_mrp.get_data()) +['_']*len(scan_twr.get_data()) +\
                                             ['_']*len(data_list)
                             else:
                                 data_list = scan_mrp.get_data() + \
                                   scan_twr.get_data() + data_list
                             data = [design] + data_list
                             append_file(report_file, ",".join(data))
                             data = [design]
                             append_file(report_file_mrp,",".join([design]+ scan_mrp.get_data() ))
                             append_file(report_file_twr,",".join([design]+ scan_twr.get_data() ))
                             #append_file(report_file_time,",".join([design]+ scan_time.get_data()))
                             scan_time.reset_par_time_data()
                         if not twr_file:
                             srr_data = scan_time.get_srr_time_data()
                             mrp_data = scan_time.get_mrp_time_data()
                             par_data = scan_time.get_par_time_data()
                             real_cpu_total = scan_time.get_total_time()
                             all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + \
                                                   real_cpu_total.items() )
                             data_list = []
                             for key in scan_time.get_title():
                                 value = all_time_data.get(key,'NA')
                                 data_list.append(value)
                             data_list2 = [design]+[target_fmax_for_time] +data_list
                             append_file(report_file_time,",".join(data_list2))
                             #data = [design] + scan_mrp.get_data()+ data_list
                             if all_time_data['Complete'] == 'NA' or all_time_data['Par_Done'] == 'NA':
                                 data = [design] + ['_']*len(scan_mrp.get_data())+  ['_']*len(data_list)
                             else:
                                 data = [design] + scan_mrp.get_data()+ data_list
                             append_file(report_file, ",".join(data))
                             append_file(report_file_mrp,",".join([design]+ scan_mrp.get_data()))
                             scan_time.reset_par_time_data()
                 scan_mrp.scan_clocks(mrp_file)
                 clock_dict = scan_mrp.get_parse_line_clocks()
                 for key in clock_dict.keys():
                     line = design+','+key+','+clock_dict[key]
                     append_file(report_file_clock,line)
                 recover.run()
         
     os.chdir(root_dir)
def scan_report():
    opt = option()
    job_dir = opt.job_dir
    design = opt.design
    syn = opt.synthesis
    #syn = ''
    family = opt.family
    report_name = opt.report_name #this is useless now
    for_pattern=''
    pap = opt.pap
    scan_mrp = tool_scan_lattice.ScanLatticeMrp()
    scan_twr = tool_scan_lattice.ScanLatticeTwr(pap)
    scan_time = tool_scan_lattice.ScanLatticeTime()
    if family:
        for_pattern = '_'+family
    if syn:
        for_pattern = for_pattern + '_'+syn
    dir_pattern = re.compile(for_pattern)
    
    all_designs = []
    if os.path.isdir(job_dir):
        pass
    else:
        print 'The job_dir:%s is not a directory'%job_dir
        return
    for dir in os.listdir(job_dir):  # get all the design path
        dir2 =  os.path.join(job_dir,dir)
        if os.path.isdir(dir2):
            all_designs.append(dir)
        else:
            pass
    report_file_list = []
    if design:
        print_always( 'scanning %s'%design)
        if design in all_designs:
            design_path = os.path.join(job_dir,design)
            for dir in os.listdir(design_path):
                if dir_pattern.search(dir) and os.path.isdir(os.path.join(design_path,dir)) and dir.startswith('_'):
                    #####################
                    scanner = (scan_mrp, scan_twr, scan_time)
                    report_file = os.path.join(opt.job_dir,dir+'.csv')
                    report_file_list.append(report_file)
                    if not_exists(report_file):
                        title = ["Design"]
                        for item in scanner: #mrp twr time
                            title += item.get_title()
                        append_file(report_file, ",".join(title))
                    if 1:
                        report_name,subtex = os.path.splitext(report_file)
                        report_file_mrp = report_name+'_mrp'+subtex
                        if not_exists(report_file_mrp):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[0]).get_title()
                            append_file(report_file_mrp, ",".join(title))
                        report_file_twr = report_name+'_twr'+subtex
                        if not_exists(report_file_twr):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[1]).get_title()
                            append_file(report_file_twr, ",".join(title))
                        report_file_time = report_name+'_time'+subtex
                        if not_exists(report_file_time):
                            title = ["Design"] +['Target_fmax']
                            #for item in scanner: #mrp twr time
                            title += (scanner[2]).get_title()
                            append_file(report_file_time, ",".join(title))
                        report_file_clock = report_name+'_clock'+subtex
                        if not_exists(report_file_clock):
                            append_file(report_file_clock, ",".join(['Design','Colck','Loads']))
                ######################
                    dir_scan = os.path.join(design_path,dir)
                    recover = RecoverPath(dir_scan)
                    if not_exists('rev_1', "srr file directory"):
                        continue
                    srr_file = get_unique_file([os.path.join(design_path,dir,'rev_1'), ".srr"])
                    if srr_file:
                        srr_file = os.path.join(design_path,dir,'rev_1',srr_file) 
                        scan_time.scan_srr(srr_file)
                    _project_name = "%s_%s" % (dir, design[:7])
                    project_name = _project_name.strip("_")
                    mrp_file = project_name + ".mrp"
                    if not_exists(mrp_file, "map report file"):
                        continue
                    scan_mrp.scan_report(mrp_file)
                    scan_time.scan_mrp(mrp_file)
                    twr_file = time_file = par_file= ""
                    target_fmax_for_time = '_'
                    target_fmax_re = re.compile(r"Target_Fmax_is_(.+)MHz")
                    for foo in os.listdir("."):
                        if os.path.isdir(foo):
                            if re.search("Target", foo):
                                print_always("  Scanning %s" % foo)
                                target_fmax_for_match = target_fmax_re.search(foo)
                                if target_fmax_for_match:
                                    target_fmax_for_time = target_fmax_for_match.group(1)
                                twr_file = get_unique_file([foo, ".twr"])
                                time_file = os.path.join(foo, time_file)
                                par_file = get_unique_file([foo, ".par"])
                            elif re.search("\.dir$", foo):
                                twr_file = get_unique_file([foo, ".twr"])
                                par_file = get_unique_file([foo, ".par"])
                                time_file = time_file
                            else:
                                continue
            
                            if twr_file:
                                scan_twr.scan_report(twr_file)
                                scan_time.scan_report(time_file)
                                scan_time.scan_par(par_file)
                                #########################
                                #time_title = ['design']+scan_time.get_title2()
                                srr_data = scan_time.get_srr_time_data()
                                mrp_data = scan_time.get_mrp_time_data()
                                par_data = scan_time.get_par_time_data()
                                real_cpu_total = scan_time.get_total_time()
                                all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + real_cpu_total.items() )
                                data_list = []
                                for key in scan_time.get_title():
                                    value = all_time_data.get(key,'NA')
                                    data_list.append(value)
                                data_list2 = [design]+[target_fmax_for_time] +data_list
                                append_file(report_file_time,",".join(data_list2))
                                    
                                #########################
                                if all_time_data['Complete'] == 'NA' or all_time_data['Par_Done'] == 'NA':
                                    data_list = ['_']*len(scan_mrp.get_data()) +['_']*len(scan_twr.get_data()) + ['_']*len(data_list)
                                else:
                                    data_list = scan_mrp.get_data() + \
                                      scan_twr.get_data() + data_list
                                data = [design] + data_list
                                append_file(report_file, ",".join(data))
                                data = [design]
                                append_file(report_file_mrp,",".join([design]+ scan_mrp.get_data() ))
                                append_file(report_file_twr,",".join([design]+ scan_twr.get_data() ))
                                #append_file(report_file_time,",".join([design]+ scan_time.get_data()))
                            if not twr_file:
                                srr_data = scan_time.get_srr_time_data()
                                mrp_data = scan_time.get_mrp_time_data()
                                par_data = scan_time.get_par_time_data()
                                real_cpu_total = scan_time.get_total_time()
                                all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + real_cpu_total.items() )
                                data_list = []
                                for key in scan_time.get_title():
                                    value = all_time_data.get(key,'NA')
                                    data_list.append(value)
                                data_list2 = [design]+[target_fmax_for_time] +data_list
                                append_file(report_file_time,",".join(data_list2))
                                
                                if all_time_data['Complete'] == 'NA' or all_time_data['Par_Done'] == 'NA':
                                    data = [design] + ['_']*len(scan_mrp.get_data())+ ['_']*len(data_list)
                                else:
                                    data = [design] + scan_mrp.get_data()+ data_list
                                append_file(report_file, ",".join(data))
                                append_file(report_file_mrp,",".join([design]+ scan_mrp.get_data()))
                    scan_mrp.scan_clocks(mrp_file)
                    clock_dict = scan_mrp.get_parse_line_clocks()
                    for key in clock_dict.keys():
                        line = design+','+key+','+clock_dict[key]
                        append_file(report_file_clock,line)
                    
        else:
            print 'The design is not exists in the job_dir'
            return
    
    else:
        root_dir = os.getcwd()
        for design in all_designs:
            print_always( 'scanning %s'%design)
            design_path = os.path.join(job_dir,design)
            for dir in os.listdir(design_path):
                if dir_pattern.search(dir) and os.path.isdir(os.path.join(design_path,dir)) and dir.startswith('_'):
                    #####################
                    scanner = (scan_mrp, scan_twr, scan_time)
                    report_file = os.path.join(opt.job_dir,dir+'.csv')
                    if report_file in report_file_list:
                        pass
                    else:
                        report_file_list.append(report_file)
                    if not_exists(report_file):
                        title = ["Design"]
                        for item in scanner: #mrp twr time
                            title += item.get_title()
                        append_file(report_file, ",".join(title))
                    if 1:
                        report_name,subtex = os.path.splitext(report_file)
                        report_file_mrp = report_name+'_mrp'+subtex
                        if not_exists(report_file_mrp):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[0]).get_title()
                            append_file(report_file_mrp, ",".join(title))
                        report_file_twr = report_name+'_twr'+subtex
                        if not_exists(report_file_twr):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[1]).get_title()
                            append_file(report_file_twr, ",".join(title))
                        report_file_time = report_name+'_time'+subtex
                        if not_exists(report_file_time):
                            title = ["Design"] +['Target_fmax']
                            #for item in scanner: #mrp twr time
                            title += (scanner[2]).get_title()
                            append_file(report_file_time, ",".join(title))
                        report_file_clock = report_name+'_clock'+subtex
                        append_file(report_file_clock, ",".join(['Design','Colck','Loads']))
                ######################
                    dir_scan = os.path.join(design_path,dir)
                    recover = RecoverPath(dir_scan)
                    if not_exists('rev_1', "srr file directory"):
                        
                        continue
                    srr_file = get_unique_file([os.path.join(design_path,dir,'rev_1'), ".srr"])
                    if not srr_file:
                        pass
                    else:
                        srr_file = os.path.join(design_path,dir,'rev_1',srr_file) 
                        scan_time.scan_srr(srr_file)
                    _project_name = "%s_%s" % (dir, design[:7])
                    project_name = _project_name.strip("_")
                    mrp_file = project_name + ".mrp"
                    if not_exists(mrp_file, "map report file"):
                        
                        continue
                    scan_mrp.scan_report(mrp_file)
                    scan_time.scan_mrp(mrp_file)
                    twr_file = time_file = par_file= ""
                    target_fmax_for_time = '_'
                    target_fmax_re = re.compile(r"Target_Fmax_is_(.+)MHz")
                    for foo in os.listdir("."):
                        if os.path.isdir(foo):
                            if re.search("Target", foo):
                                scan_time.reset_par_time_data()
                                print_always("  Scanning %s" % foo)
                                target_fmax_for_match = target_fmax_re.search(foo)
                                if target_fmax_for_match:
                                    target_fmax_for_time = target_fmax_for_match.group(1)
                                twr_file = get_unique_file([foo, ".twr"])
                                time_file = os.path.join(foo, time_file)
                                par_file = get_unique_file([foo, ".par"])
                            elif re.search("\.dir$", foo):
                                twr_file = get_unique_file([foo, ".twr"])
                                par_file = get_unique_file([foo, ".par"])
                                time_file = time_file
                            else:
                                continue
            
                            if twr_file:
                                scan_twr.scan_report(twr_file)
                                scan_time.scan_report(time_file)
                                scan_time.scan_par(par_file)
                                #########################
                                #time_title = ['design']+scan_time.get_title2()
                                srr_data = scan_time.get_srr_time_data()
                                mrp_data = scan_time.get_mrp_time_data()
                                par_data = scan_time.get_par_time_data()
                                real_cpu_total = scan_time.get_total_time()
                                all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + real_cpu_total.items() )
                                data_list = []
                                for key in scan_time.get_title():
                                    value = all_time_data.get(key,'NA')
                                    data_list.append(value)
                                data_list2 = [design]+[target_fmax_for_time] +data_list
                                append_file(report_file_time,",".join(data_list2))
                                    
                                #########################
                                #data = [design] + scan_mrp.get_data() + \
                                #      scan_twr.get_data() + data_list
                                if all_time_data['Complete'] == 'NA' or all_time_data['Par_Done'] == 'NA':
                                    data_list = ['_']*len(scan_mrp.get_data()) +['_']*len(scan_twr.get_data()) +\
                                                ['_']*len(data_list)
                                else:
                                    data_list = scan_mrp.get_data() + \
                                      scan_twr.get_data() + data_list
                                data = [design] + data_list
                                append_file(report_file, ",".join(data))
                                data = [design]
                                append_file(report_file_mrp,",".join([design]+ scan_mrp.get_data() ))
                                append_file(report_file_twr,",".join([design]+ scan_twr.get_data() ))
                                #append_file(report_file_time,",".join([design]+ scan_time.get_data()))
                                scan_time.reset_par_time_data()
                            if not twr_file:
                                srr_data = scan_time.get_srr_time_data()
                                mrp_data = scan_time.get_mrp_time_data()
                                par_data = scan_time.get_par_time_data()
                                real_cpu_total = scan_time.get_total_time()
                                all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + \
                                                      real_cpu_total.items() )
                                data_list = []
                                for key in scan_time.get_title():
                                    value = all_time_data.get(key,'NA')
                                    data_list.append(value)
                                data_list2 = [design]+[target_fmax_for_time] +data_list
                                append_file(report_file_time,",".join(data_list2))
                                #data = [design] + scan_mrp.get_data()+ data_list
                                if all_time_data['Complete'] == 'NA' or all_time_data['Par_Done'] == 'NA':
                                    data = [design] + ['_']*len(scan_mrp.get_data())+  ['_']*len(data_list)
                                else:
                                    data = [design] + scan_mrp.get_data()+ data_list
                                append_file(report_file, ",".join(data))
                                append_file(report_file_mrp,",".join([design]+ scan_mrp.get_data()))
                                scan_time.reset_par_time_data()
                    scan_mrp.scan_clocks(mrp_file)
                    clock_dict = scan_mrp.get_parse_line_clocks()
                    for key in clock_dict.keys():
                        line = design+','+key+','+clock_dict[key]
                        append_file(report_file_clock,line)
                    recover.run()
            
        os.chdir(root_dir)
    for f in report_file_list:
        if os.path.isfile(f):
            file_sorted,note,design_fmax = report_sort.sort_csv(f)
            report_sort.write_note(file_sorted,note)
    #----------------update run_stand-------------------#
    pass_log = glob.glob('*'+syn+'_pass_case.log')
    if pass_log:
        pass_log = pass_log[0]
    else:
        pass_log = '__'
    if os.path.isfile(pass_log):
        file_hand = file(pass_log,'r')
        lines = file_hand.readlines()
        file_hand.close()
        stand_name = glob.glob('*'+syn+'_run_standard.bat')
        if stand_name:
            stand_name = stand_name[0]
        #stand_name = os.path.join(top_base,top_base2+'_'+syn+'_run_standard.bat')
        else:
            stand_name = ''
        run_standard = file(stand_name,'r')
        run_standard_lines = run_standard.readlines()
        run_standard.close()
        useful_lines = []
        for case in lines:
            case = case.strip()
            if not case:
                 continue
            else:
                 pass
            case_tab = '--design='+case
            case_tab_re = re.compile(case_tab+r'(\s+|$)')
            for line in run_standard_lines:
                line = line.strip()
                if not line:
                    continue
                if case_tab_re.search(line):
                    try:
                        fmax = float( design_fmax[case.strip()] )
                        fmax = str( int( fmax ))
                    #line = case_tab_re.sub('',line)
                        line = re.sub(r'--fmax-sweep=[\s\d]+\d','',line)
                        line2 = line + ' --fmax-sweep='+fmax+' '+fmax+' '+'10 \n'
                    except:
                        line2 = line
                    useful_lines.append(line2)
        run_standard = file(stand_name,'w')
        run_standard.writelines(useful_lines)
        run_standard.close()
Example #7
0
def scan_report():
    opt = option()
    job_dir = opt.job_dir
    need_design = opt.design
    syn = opt.synthesis
    #syn = ''
    family = opt.family
    report_name = opt.report_name #this is useless now
    for_pattern=''
    pap = opt.pap
    scan_mrp = tool_scan_lattice.ScanLatticeMrp()
    scan_twr = tool_scan_lattice.ScanLatticeTwr(pap)
    scan_time = tool_scan_lattice.ScanLatticeTime()
    
    all_designs = []
    if os.path.isdir(job_dir):
        pass
    else:
        print 'The job_dir:%s is not a directory'%job_dir
        return
    for dir in os.listdir(job_dir):  # get all the design path
        dir2 =  os.path.join(job_dir,dir)
        if os.path.isdir(dir2):
            all_designs.append(dir)
        else:
            pass
    report_file_list = []
    
    if 1:
        root_dir = os.getcwd()
        for design in all_designs:
            if need_design:
                if design ==  need_design:
                    pass
                else:
                    continue
            print_always( 'scanning %s'%design)
            design_path = os.path.join(job_dir,design)
            if 1:
                if 1:
                    #####################
                    scanner = (scan_mrp, scan_twr, scan_time)
                    report_file = os.path.join(opt.job_dir,'aa'+'.csv')
                    if report_file in report_file_list:
                        pass
                    else:
                        report_file_list.append(report_file)
                    if not_exists(report_file):
                        title = ["Design"]
                        for item in scanner: #mrp twr time
                            title += item.get_title()
                        append_file(report_file, ",".join(title))
                    if 1:
                        report_name,subtex = os.path.splitext(report_file)
                        report_file_mrp = report_name+'_mrp'+subtex
                        if not_exists(report_file_mrp):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[0]).get_title()
                            append_file(report_file_mrp, ",".join(title))
                        report_file_twr = report_name+'_twr'+subtex
                        if not_exists(report_file_twr):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[1]).get_title()
                            append_file(report_file_twr, ",".join(title))
                        report_file_time = report_name+'_time'+subtex
                        if not_exists(report_file_time):
                            title = ["Design"] +['Target_fmax']
                            #for item in scanner: #mrp twr time
                            title += (scanner[2]).get_title()
                            append_file(report_file_time, ",".join(title))
                        report_file_clock = report_name+'_clock'+subtex
                        append_file(report_file_clock, ",".join(['Design','Colck','Loads']))
                ######################
                    #dir_scan = os.path.join(design_path,dir)
                    recover = RecoverPath(design_path)
                    srr_file = get_unique_file([os.path.join(design_path,'impl'), ".srr"])
                    if not srr_file:
                        pass
                    else:
                        srr_file = os.path.join(design_path,dir,'rev_1',srr_file) 
                        scan_time.scan_srr(srr_file)
                    twr_file = time_file = par_file= mrp_file = ""
                    target_fmax_for_time = '_'
                    target_fmax_re = re.compile(r"Target_Seed_is_(.+)")
                    for foo in os.listdir("."):
                        if os.path.isdir(foo):
                            if re.search("Target", foo):
                                scan_time.reset_par_time_data()
                                print_always("  Scanning %s" % foo)
                                target_fmax_for_match = target_fmax_re.search(foo)
                                if target_fmax_for_match:
                                    target_fmax_for_time = target_fmax_for_match.group(1)
                                twr_file = get_unique_file([foo, ".twr"])
                                mrp_file = get_unique_file([foo, ".mrp"])
                                scan_mrp.scan_report(mrp_file)
                                scan_time.scan_mrp(mrp_file)
                                time_file = os.path.join(foo, time_file)
                                par_file = get_unique_file([os.path.join(foo,'PrjName.dir'), ".par"])
                            elif re.search("\.dir$", foo):
                                twr_file = get_unique_file([foo, ".twr"])
                                par_file = get_unique_file([foo, ".par"])
                                time_file = time_file
                            else:
                                continue
            
                            if twr_file:
                               
                                if design.startswith('hu'):
                                    scan_twr.scan_report(twr_file,'clk_246mhz_c') ### add by yu
                                
                                elif design =='fir1c':
                                        scan_twr.scan_report(twr_file,'fir_clk_c')
                                elif design.startswith('fir'):
                                        scan_twr.scan_report(twr_file,'fir_clk')
                                elif design.startswith('config'):
                                        scan_twr.scan_report(twr_file,'clk_c')
                                else:
                                    scan_twr.scan_report(twr_file,'i_clk')
                                
                                
                                scan_time.scan_report(time_file)
                                scan_time.scan_par(par_file)
                                #########################
                                #time_title = ['design']+scan_time.get_title2()
                                srr_data = scan_time.get_srr_time_data()
                                mrp_data = scan_time.get_mrp_time_data()
                                par_data = scan_time.get_par_time_data()
                                real_cpu_total = scan_time.get_total_time()
                                all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + real_cpu_total.items() )
                                data_list = []
                                for key in scan_time.get_title():
                                    value = all_time_data.get(key,'NA')
                                    data_list.append(value)
                                data_list2 = [design]+[target_fmax_for_time] +data_list
                                append_file(report_file_time,",".join(data_list2))
                                    
                                #########################
                                #data = [design] + scan_mrp.get_data() + \
                                #      scan_twr.get_data() + data_list
                                if all_time_data['Complete'] == 'NA' or all_time_data['Par_Done'] == 'NA':
                                    data_list = ['_']*len(scan_mrp.get_data()) +['_']*len(scan_twr.get_data()) +\
                                                ['_']*len(data_list)
                                else:
                                    data_list = scan_mrp.get_data() + \
                                      scan_twr.get_data() + data_list
                                data = [design] + data_list
                                append_file(report_file, ",".join(data))
                                data = [design]
                                append_file(report_file_mrp,",".join([design]+ scan_mrp.get_data() ))
                                append_file(report_file_twr,",".join([design]+ scan_twr.get_data() ))
                                #append_file(report_file_time,",".join([design]+ scan_time.get_data()))
                                scan_time.reset_par_time_data()
                            if not twr_file:
                                srr_data = scan_time.get_srr_time_data()
                                mrp_data = scan_time.get_mrp_time_data()
                                par_data = scan_time.get_par_time_data()
                                real_cpu_total = scan_time.get_total_time()
                                all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + \
                                                      real_cpu_total.items() )
                                data_list = []
                                for key in scan_time.get_title():
                                    value = all_time_data.get(key,'NA')
                                    data_list.append(value)
                                data_list2 = [design]+[target_fmax_for_time] +data_list
                                append_file(report_file_time,",".join(data_list2))
                                #data = [design] + scan_mrp.get_data()+ data_list
                                if all_time_data['Complete'] == 'NA' or all_time_data['Par_Done'] == 'NA':
                                    data = [design] + ['_']*len(scan_mrp.get_data())+  ['_']*len(data_list)
                                else:
                                    data = [design] + scan_mrp.get_data()+ data_list
                                append_file(report_file, ",".join(data))
                                append_file(report_file_mrp,",".join([design]+ scan_mrp.get_data()))
                                scan_time.reset_par_time_data()
                    scan_mrp.scan_clocks(mrp_file)
                    clock_dict = scan_mrp.get_parse_line_clocks()
                    for key in clock_dict.keys():
                        line = design+','+key+','+clock_dict[key]
                        append_file(report_file_clock,line)
                    recover.run()
        os.chdir(root_dir)
    for f in report_file_list:
        if os.path.isfile(f):
            file_sorted,note,design_fmax = report_sort.sort_csv(f,add_average=1)
            report_sort.write_note(file_sorted,note)