Пример #1
0
def ImportSTDF(fname):
    with open(fname,'rb') as fin:
        p = Parser(inp=fin)
        storage = MemoryWriter()
        p.addSink(storage)
        p.parse()
    return storage.data
Пример #2
0
def process_file(fn):
    #filename, = sys.argv[1:]
    filename = fn
    
    reopen_fn = None
    if filename is None:
        f = sys.stdin
    elif gzPattern.search(filename):
        if not have_gzip:
            print >>sys.stderr, "gzip is not supported on this system"
            sys.exit(1)
        reopen_fn = lambda: gzip.open(filename, 'rb')
        f = reopen_fn()
    elif bz2Pattern.search(filename):
        if not have_bz2:
            print >>sys.stderr, "bz2 is not supported on this system"
            sys.exit(1)
        reopen_fn = lambda: bz2.BZ2File(filename, 'rb')
        f = reopen_fn()
    else:
        f = open(filename, 'rb')
    p=Parser(inp=f, reopen_fn=reopen_fn)
    p.addSink(AtdfWriter())
    p.parse()
    f.close()
Пример #3
0
def process_file(fnames):
    filename = fnames

    reopen_fn = None
    if filename is None:
        f = sys.stdin
    elif gzPattern.search(filename):
        if not have_gzip:
            print("gzip is not supported on this system", file=sys.stderr)
            sys.exit(1)
        reopen_fn = lambda: gzip.open(filename, 'rb')
        f = reopen_fn()
    elif bz2Pattern.search(filename):
        if not have_bz2:
            print("bz2 is not supported on this system", file=sys.stderr)
            sys.exit(1)
        reopen_fn = lambda: bz2.BZ2File(filename, 'rb')
        f = reopen_fn()
    else:
        f = open(filename, 'rb')
    p = Parser(inp=f, reopen_fn=reopen_fn)
    if len(fnames) < 2:
        p.addSink(TextWriter())
        p.parse()
    else:
        with open(fnames + '_.txt', 'w') as fout:
            p.addSink(TextWriter(stream=fout))
            p.parse()
    f.close()
Пример #4
0
def STDF2Text(fname,delimiter='|'):
    """ Convert STDF to a list of text representation
    """
    with open(fname,'rb') as fin:
        p = Parser(inp=fin)
        storage = MemoryWriter()
        p.addSink(TextWriter(storage,delimiter=delimiter))
        p.parse()
        return storage.data
    return None
Пример #5
0
 def __init__(self, parent, filename):
     f = open(filename, 'rb')
     p=Parser(inp=f)
     record_mapper = StreamMapper()
     p.addSink(record_mapper)
     
     print 'Parsing %s...' % (filename)
     p.parse()
     print 'Parse complete'
     
     wx.Frame.__init__(self, parent, -1, "Huge (virtual) Table Demo", size=(640,480)) 
     grid = HugeTableGrid(self, record_mapper, f) 
     grid.SetReadOnly(5,5, True)
Пример #6
0
    def OnMenuFileOpenMenu(self, event):
        dlg = wx.FileDialog(self, "Choose a file", ".", "", "*.*")
        try:
            if dlg.ShowModal() == wx.ID_OK:
                filename = dlg.GetPath()

                # Set up the mapping parser
                self.map_stream = open(filename, 'rb')
                parser = Parser(inp=self.map_stream)
                self.record_mapper = StreamMapper()
                parser.addSink(self.record_mapper)
                material_mapper = MaterialMapper()
                parser.addSink(material_mapper)
                self.recordPositionList.record_mapper = self.record_mapper
                self.recordPositionList.material_mapper = material_mapper

                # Set up the viewing parser
                self.view_stream = open(filename, 'rb')
                self.view_parser = Parser(inp=self.view_stream)
                self.record_keeper = RecordKeeper()
                self.view_parser.addSink(self.record_keeper)
                self.view_parser.parse(1)

                # Parse the file in a separate thread
                self.mapper = MapperThread(self, parser)

        finally:
            dlg.Destroy()
Пример #7
0
    def __init__(self,
                 input_path,
                 output_path,
                 BinDefinition="",
                 QSignal=None):
        self.packFieldType = {
            "C1": self.packStructType,
            "B1": self.packStructType,
            "U1": self.packStructType,
            "U2": self.packStructType,
            "U4": self.packStructType,
            "U8": self.packStructType,
            "I1": self.packStructType,
            "I2": self.packStructType,
            "I4": self.packStructType,
            "I8": self.packStructType,
            "R4": self.packStructType,
            "R8": self.packStructType,
            "Cn": lambda f_type, data: self.packCn(data),
            "Bn": lambda f_type, data: self.packBn(data),
            "Dn": lambda f_type, data: None,  # Dn/Vn not in use
            "Vn": lambda f_type, data: None
        }
        self.outpath = output_path
        self.QSignal = QSignal

        start = time.time()  #
        try:
            self.stdin = open(input_path, "rb")
            self.a = stdfAnalyzer(BinDefinition=BinDefinition, QSignal=QSignal)
            self.p = Parser(inp=self.stdin, QSignal=QSignal)
            self.p.addSink(self.a)
            self.p.parse()
            time.sleep(0.51)  # wait for the last message
            self.fix()
        except Exception as e:
            if self.QSignal != None:
                self.QSignal.message_printer.emit(
                    '''<span style="color:red"><b>Error occurs:<br>{0!r}</b></span>'''
                    .format(e))
        finally:
            end = time.time()  #
            if self.QSignal != None:
                self.QSignal.message_printer.emit("Elapsed time: %.2f sec\n" %
                                                  (end - start))
Пример #8
0
    def process_file(filename):

        # Open that bad boi up
        f = open(filename, 'rb')
        reopen_fn = None

        # The name of the new file, preserving the directory of the previous
        newFile = filename + "_parsed.txt"

        # I guess I'm making a parsing object here, but again I didn't write this part
        p = Parser(inp=f, reopen_fn=reopen_fn)

        startt = time.time()  # 9.7s --> TextWriter; 7.15s --> MyTestResultProfiler

        # Writing to a text file instead of vomiting it to the console
        with open(newFile, 'w') as fout:
            # fout writes it to the opened text file
            p.addSink(TextWriter(stream=fout))
            p.parse()

        # We don't need to keep that file open
        f.close()

        endt = time.time()
        print('STDF处理时间:', endt - startt)
Пример #9
0
def ImportSTDF(fname):
    with open(fname, 'rb') as fin:
        p = Parser(inp=fin)
        storage = MemoryWriter()
        p.addSink(storage)
        p.parse()
    return storage.data
Пример #10
0
 def OnMenuFileOpenMenu(self, event):
     dlg = wx.FileDialog(self, "Choose a file", ".", "", "*.*", wx.OPEN)
     try:
         if dlg.ShowModal() == wx.ID_OK:
             filename = dlg.GetPath()
             
             # Set up the mapping parser
             self.map_stream = open(filename, 'rb')
             parser = Parser(inp=self.map_stream)
             self.record_mapper = StreamMapper()
             parser.addSink(self.record_mapper)
             material_mapper = MaterialMapper()
             parser.addSink(material_mapper)
             self.recordPositionList.record_mapper = self.record_mapper
             self.recordPositionList.material_mapper = material_mapper
             
             # Set up the viewing parser
             self.view_stream = open(filename, 'rb')
             self.view_parser = Parser(inp=self.view_stream)
             self.record_keeper = RecordKeeper()
             self.view_parser.addSink(self.record_keeper)
             self.view_parser.parse(1)
             
             # Parse the file in a separate thread
             self.mapper = MapperThread(self, parser)
     
     finally:
         dlg.Destroy()
Пример #11
0
    def process_file(filename):
        xmlname = ''
        reopen_fn = None
        if filename is None:
            fin = sys.stdin
            fout = sys.stdin
        elif gzPattern.search(filename):
            if not have_gzip:
                print("gzip is not supported on this system", file=sys.stderr)
                sys.exit(1)
            reopen_fn = lambda: gzip.open(filename, 'rb')
            fin = reopen_fn()
        elif bz2Pattern.search(filename):
            if not have_bz2:
                print("bz2 is not supported on this system", file=sys.stderr)
                sys.exit(1)
            reopen_fn = lambda: bz2.BZ2File(filename, 'rb')
            fin = reopen_fn()
        else:
            fin = open(filename, 'rb')
            xmlname = re.sub('\.stdf$', '.xml', filename)
            try:
                fout = open(xmlname, 'x')
            except:
                print('XML version of filename already exists')
                return xmlname

        p = Parser(inp=fin, reopen_fn=reopen_fn)
        p.addSink(XmlWriter(fout))
        p.parse()
        fin.close()
        fout.close()
        return xmlname
Пример #12
0
def STDF2Text(fname, delimiter='|'):
    """ Convert STDF to a list of text representation
    """
    with open(fname, 'rb') as fin:
        p = Parser(inp=fin)
        storage = MemoryWriter()
        p.addSink(TextWriter(storage, delimiter=delimiter))
        p.parse()
        return storage.data
    return None
Пример #13
0
    def to_csv(file_names, output_file_name, notify_progress_bar):
        data_summary_all = pd.DataFrame()
        for filename in file_names:
            # Open std file/s
            if filename.endswith(".std") or filename.endswith(".stdf"):
                f = open(filename, 'rb')
            elif filename.endswith(".gz"):
                f = gzip.open(filename, 'rb')
            reopen_fn = None
            # I guess I'm making a parsing object here, but again I didn't write this part
            p = Parser(inp=f, reopen_fn=reopen_fn)
            fsize = os.path.getsize(filename)
            fname = filename  # + "_csv_log.csv"
            startt = time.time()  # 9.7s --> TextWriter; 7.15s --> MyTestResultProfiler

            # Writing to a text file instead of vomiting it to the console
            data_summary = MyTestResultProfiler(filename=fname,file=f, filezise = fsize, notify_progress_bar=notify_progress_bar)
            p.addSink(data_summary)
            p.parse()

            endt = time.time()
            print('STDF处理时间:', endt - startt)
            # data_summary_all = data_summary_all.append(data_summary.frame)
            # data_summary_all = pd.concat([data_summary_all,data_summary.frame],sort=False,join='outer')
            if data_summary_all.empty:
                data_summary_all = data_summary.frame
            else:
                # data_summary_all = pd.merge(data_summary_all, data_summary.frame, sort=False, how='outer')
                data_summary_all = pd.concat([data_summary_all, data_summary.frame], sort=False,
                                             join='outer', ignore_index=True)
        # Set multiple level columns for csv table
        tname_list = []
        tnumber_list = []
        hilimit_list = []
        lolimit_list = []
        unit_vect_nam_list = []
        tmplist = data_summary_all.columns.values.tolist()
        for i in range(len(tmplist)):
            if len(str(tmplist[i]).split('|')) == 1:
                tname_list.append('')
                tnumber_list.append(str(tmplist[i]).split('|')[0])
                hilimit_list.append('')
                lolimit_list.append('')
                unit_vect_nam_list.append('')
            else:
                tname_list.append(str(tmplist[i]).split('|')[1])
                tnumber_list.append(str(tmplist[i]).split('|')[0])
                hilimit_list.append(str(tmplist[i]).split('|')[2])
                lolimit_list.append(str(tmplist[i]).split('|')[3])
                unit_vect_nam_list.append(str(tmplist[i]).split('|')[4])
        data_summary_all.columns = [tname_list, hilimit_list, lolimit_list, unit_vect_nam_list, tnumber_list]

        data_summary_all.to_csv(output_file_name + "_csv_log.csv", index=False)
Пример #14
0
    def __init__(self, parent, filename):
        f = open(filename, 'rb')
        p = Parser(inp=f)
        record_mapper = StreamMapper()
        p.addSink(record_mapper)

        print('Parsing %s...' % (filename))
        p.parse()
        print('Parse complete')

        wx.Frame.__init__(self,
                          parent,
                          -1,
                          "Huge (virtual) Table Demo",
                          size=(640, 480))
        grid = HugeTableGrid(self, record_mapper, f)
        grid.SetReadOnly(5, 5, True)
Пример #15
0
    def to_ASCII(filename):
        # Open std file/s
        if filename.endswith(".std") or filename.endswith(".stdf"):
            f = open(filename, 'rb')
        elif filename.endswith(".gz"):
            f = gzip.open(filename, 'rb')
        reopen_fn = None

        # I guess I'm making a parsing object here, but again I didn't write this part
        p = Parser(inp=f, reopen_fn=reopen_fn)

        fname = filename  # + "_csv_log.csv"
        startt = time.time()  # 9.7s --> TextWriter; 7.15s --> MyTestResultProfiler

        # Writing to a text file instead of vomiting it to the console
        stdf_df = My_STDF_V4_2007_1_Profiler(filename)
        p.addSink(stdf_df)
        p.parse()

        endt = time.time()
        print('STDF处理时间:', endt - startt)

        stdf_df.all_test_result_pd.to_csv(filename + "_diag_log.csv", index=False)
Пример #16
0
class MainFrame(wx.Frame):
    _custom_classes = {'wx.ListCtrl': ['RecordPositionListCtrl','RecordViewListCtrl']}
    
    def _init_coll_mainSizer_Items(self, parent):
        # generated method, don't edit

        parent.AddWindow(self.recordPositionList, 1, border=0, flag=0)
        parent.AddWindow(self.recordViewList, 2, border=0, flag=0)

    def _init_coll_mainMenuBar_Menus(self, parent):
        # generated method, don't edit

        parent.Append(menu=self.menuFile, title=u'File')
        parent.Append(menu=self.menuHelp, title=u'Help')

    def _init_coll_menuHelp_Items(self, parent):
        # generated method, don't edit

        parent.Append(help=u'', id=wxID_MAINFRAMEMENUHELPABOUT,
              kind=wx.ITEM_NORMAL, text=u'About')
        self.Bind(wx.EVT_MENU, self.OnMenuHelpAboutMenu,
              id=wxID_MAINFRAMEMENUHELPABOUT)

    def _init_coll_menuFile_Items(self, parent):
        # generated method, don't edit

        parent.Append(help='', id=wxID_MAINFRAMEMENUFILEOPEN,
              kind=wx.ITEM_NORMAL, text=u'Open')
        parent.Append(help='', id=wxID_MAINFRAMEMENUFILECLOSE,
              kind=wx.ITEM_NORMAL, text=u'Close')
        parent.Append(help='', id=wxID_MAINFRAMEMENUFILEEXIT,
              kind=wx.ITEM_NORMAL, text=u'Exit')
        self.Bind(wx.EVT_MENU, self.OnMenuFileOpenMenu,
              id=wxID_MAINFRAMEMENUFILEOPEN)
        self.Bind(wx.EVT_MENU, self.OnMenuFileCloseMenu,
              id=wxID_MAINFRAMEMENUFILECLOSE)
        self.Bind(wx.EVT_MENU, self.OnMenuFileExitMenu,
              id=wxID_MAINFRAMEMENUFILEEXIT)

    def _init_coll_recordViewList_Columns(self, parent):
        # generated method, don't edit

        parent.InsertColumn(col=0, format=wx.LIST_FORMAT_LEFT,
              heading=u'Field Name', width=-1)
        parent.InsertColumn(col=1, format=wx.LIST_FORMAT_LEFT, heading=u'Value',
              width=-1)

    def _init_coll_recordPositionList_Columns(self, parent):
        # generated method, don't edit

        parent.InsertColumn(col=0, format=wx.LIST_FORMAT_LEFT,
              heading=u'File Offset', width=-1)
        parent.InsertColumn(col=1, format=wx.LIST_FORMAT_LEFT,
              heading=u'Record Type', width=-1)
        parent.InsertColumn(col=2, format=wx.LIST_FORMAT_LEFT,
              heading=u'Wafer', width=-1)
        parent.InsertColumn(col=3, format=wx.LIST_FORMAT_LEFT,
              heading=u'Insertion', width=-1)
        parent.InsertColumn(col=4, format=wx.LIST_FORMAT_LEFT,
              heading=u'Part', width=-1)

    def _init_coll_statusBar_Fields(self, parent):
        # generated method, don't edit
        parent.SetFieldsCount(1)

        parent.SetStatusText(number=0, text=u'Status')

        parent.SetStatusWidths([-1])

    def _init_sizers(self):
        # generated method, don't edit
        self.mainSizer = wx.BoxSizer(orient=wx.HORIZONTAL)

        self._init_coll_mainSizer_Items(self.mainSizer)

        self.SetSizer(self.mainSizer)

    def _init_utils(self):
        # generated method, don't edit
        self.menuFile = wx.Menu(title='')

        self.menuHelp = wx.Menu(title='')

        self.mainMenuBar = wx.MenuBar()

        self._init_coll_menuFile_Items(self.menuFile)
        self._init_coll_menuHelp_Items(self.menuHelp)
        self._init_coll_mainMenuBar_Menus(self.mainMenuBar)

    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_MAINFRAME, name=u'MainFrame',
              parent=prnt, pos=wx.Point(304, 125), size=wx.Size(615, 556),
              style=wx.DEFAULT_FRAME_STYLE, title=u'STDF Explorer')
        self._init_utils()
        self.SetClientSize(wx.Size(607, 527))
        self.SetMenuBar(self.mainMenuBar)
        self.SetExtraStyle(0)
        self.SetStatusBarPane(0)

        self.statusBar = wx.StatusBar(id=wxID_MAINFRAMESTATUSBAR,
              name=u'statusBar', parent=self, style=0)
        self._init_coll_statusBar_Fields(self.statusBar)
        self.SetStatusBar(self.statusBar)

        self.recordPositionList = RecordPositionListCtrl(id=wxID_MAINFRAMERECORDPOSITIONLIST,
              name=u'recordPositionList', parent=self, pos=wx.Point(0, 0),
              size=wx.Size(202, 487),
              style=wx.LC_REPORT | wx.LC_VIRTUAL | wx.LC_HRULES | wx.LC_VRULES)
        self._init_coll_recordPositionList_Columns(self.recordPositionList)
        self.recordPositionList.Bind(wx.EVT_LIST_ITEM_SELECTED,
              self.OnRecordPositionListListItemSelected,
              id=wxID_MAINFRAMERECORDPOSITIONLIST)

        self.recordViewList = RecordViewListCtrl(id=wxID_MAINFRAMERECORDVIEWLIST,
              name=u'recordViewList', parent=self, pos=wx.Point(202, 0),
              size=wx.Size(404, 487),
              style=wx.LC_REPORT | wx.LC_VIRTUAL | wx.LC_HRULES | wx.LC_VRULES)
        self.recordViewList.SetAutoLayout(False)
        self.recordViewList.SetMinSize(wx.Size(404, 487))
        self._init_coll_recordViewList_Columns(self.recordViewList)

        self._init_sizers()
        
    def __init__(self, parent):
        self._init_ctrls(parent)
        self.view_stream = None
        EVT_MAPPED(self, self.OnMapped)
        
    def OnMenuHelpAboutMenu(self, event):
        event.Skip()
    
    def OnMenuFileOpenMenu(self, event):
        dlg = wx.FileDialog(self, "Choose a file", ".", "", "*.*", wx.OPEN)
        try:
            if dlg.ShowModal() == wx.ID_OK:
                filename = dlg.GetPath()
                
                # Set up the mapping parser
                self.map_stream = open(filename, 'rb')
                parser = Parser(inp=self.map_stream)
                self.record_mapper = StreamMapper()
                parser.addSink(self.record_mapper)
                material_mapper = MaterialMapper()
                parser.addSink(material_mapper)
                self.recordPositionList.record_mapper = self.record_mapper
                self.recordPositionList.material_mapper = material_mapper
                
                # Set up the viewing parser
                self.view_stream = open(filename, 'rb')
                self.view_parser = Parser(inp=self.view_stream)
                self.record_keeper = RecordKeeper()
                self.view_parser.addSink(self.record_keeper)
                self.view_parser.parse(1)
                
                # Parse the file in a separate thread
                self.mapper = MapperThread(self, parser)
        
        finally:
            dlg.Destroy()
    
    def OnMapped(self, event):
        if event.cancelled:
            self.statusBar.SetStatusText('%s... Cancelled!' % (
                self.statusBar.GetStatusText()))
        else:
            self.recordPositionList.SetItemCount(
                len(self.record_mapper.indexes))
            self.statusBar.SetStatusText('%s... Done' % (
                self.statusBar.GetStatusText()))
        
        if self.map_stream is not None:
            self.map_stream.close()
            self.map_stream = None
        self.mapper = None
        
    def OnMenuFileCloseMenu(self, event):
        self.recordPositionList.record_mapper = None
        self.recordPositionList.material_mapper = None
        self.view_stream.close()
        self.view_stream = None
        self.view_parser = None
        self.record_mapper = None
        
        self.recordPositionList.SetItemCount(0)
        self.recordPositionList.Refresh()
        self.recordViewList.SetItemCount(0)
        self.recordViewList.Refresh()
        
        if self.mapper:
            self.mapper.cancel()
    
    def OnMenuFileExitMenu(self, event):
        self.Close()
    
    def OnRecordPositionListListItemSelected(self, event):
        if self.record_mapper:
            self.view_stream.seek(self.record_mapper.indexes[event.GetIndex()])
            self.view_parser.parse(1)
            self.recordViewList.record = self.record_keeper.record_type, self.record_keeper.record_data 
Пример #17
0
class MainFrame(wx.Frame):
    _custom_classes = {
        'wx.ListCtrl': ['RecordPositionListCtrl', 'RecordViewListCtrl']
    }

    def _init_coll_mainSizer_Items(self, parent):
        # generated method, don't edit

        parent.Add(self.recordPositionList, 1, border=0, flag=0)
        parent.Add(self.recordViewList, 2, border=0, flag=0)

    def _init_coll_mainMenuBar_Menus(self, parent):
        # generated method, don't edit

        parent.Append(menu=self.menuFile, title=u'File')
        parent.Append(menu=self.menuHelp, title=u'Help')

    def _init_coll_menuHelp_Items(self, parent):
        # generated method, don't edit

        parent.Append(id=wxID_MAINFRAMEMENUHELPABOUT,
                      kind=wx.ITEM_NORMAL,
                      item=u'About')
        self.Bind(wx.EVT_MENU,
                  self.OnMenuHelpAboutMenu,
                  id=wxID_MAINFRAMEMENUHELPABOUT)

    def _init_coll_menuFile_Items(self, parent):
        # generated method, don't edit

        parent.Append(id=wxID_MAINFRAMEMENUFILEOPEN,
                      kind=wx.ITEM_NORMAL,
                      item=u'Open')
        parent.Append(id=wxID_MAINFRAMEMENUFILECLOSE,
                      kind=wx.ITEM_NORMAL,
                      item=u'Close')
        parent.Append(id=wxID_MAINFRAMEMENUFILEEXIT,
                      kind=wx.ITEM_NORMAL,
                      item=u'Exit')
        self.Bind(wx.EVT_MENU,
                  self.OnMenuFileOpenMenu,
                  id=wxID_MAINFRAMEMENUFILEOPEN)
        self.Bind(wx.EVT_MENU,
                  self.OnMenuFileCloseMenu,
                  id=wxID_MAINFRAMEMENUFILECLOSE)
        self.Bind(wx.EVT_MENU,
                  self.OnMenuFileExitMenu,
                  id=wxID_MAINFRAMEMENUFILEEXIT)

    def _init_coll_recordViewList_Columns(self, parent):
        # generated method, don't edit

        parent.InsertColumn(col=0,
                            format=wx.LIST_FORMAT_LEFT,
                            heading=u'Field Name',
                            width=-1)
        parent.InsertColumn(col=1,
                            format=wx.LIST_FORMAT_LEFT,
                            heading=u'Value',
                            width=-1)

    def _init_coll_recordPositionList_Columns(self, parent):
        # generated method, don't edit

        parent.InsertColumn(col=0,
                            format=wx.LIST_FORMAT_LEFT,
                            heading=u'File Offset',
                            width=-1)
        parent.InsertColumn(col=1,
                            format=wx.LIST_FORMAT_LEFT,
                            heading=u'Record Type',
                            width=-1)
        parent.InsertColumn(col=2,
                            format=wx.LIST_FORMAT_LEFT,
                            heading=u'Wafer',
                            width=-1)
        parent.InsertColumn(col=3,
                            format=wx.LIST_FORMAT_LEFT,
                            heading=u'Insertion',
                            width=-1)
        parent.InsertColumn(col=4,
                            format=wx.LIST_FORMAT_LEFT,
                            heading=u'Part',
                            width=-1)

    def _init_coll_statusBar_Fields(self, parent):
        # generated method, don't edit
        parent.SetFieldsCount(1)

        parent.SetStatusText(u'Status')

        parent.SetStatusWidths([-1])

    def _init_sizers(self):
        # generated method, don't edit
        self.mainSizer = wx.BoxSizer(orient=wx.HORIZONTAL)

        self._init_coll_mainSizer_Items(self.mainSizer)

        self.SetSizer(self.mainSizer)

    def _init_utils(self):
        # generated method, don't edit
        self.menuFile = wx.Menu(title='')

        self.menuHelp = wx.Menu(title='')

        self.mainMenuBar = wx.MenuBar()

        self._init_coll_menuFile_Items(self.menuFile)
        self._init_coll_menuHelp_Items(self.menuHelp)
        self._init_coll_mainMenuBar_Menus(self.mainMenuBar)

    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self,
                          id=wxID_MAINFRAME,
                          name=u'MainFrame',
                          parent=prnt,
                          pos=wx.Point(304, 125),
                          size=wx.Size(615, 556),
                          style=wx.DEFAULT_FRAME_STYLE,
                          title=u'STDF Explorer')
        self._init_utils()
        self.SetClientSize(wx.Size(607, 527))
        self.SetMenuBar(self.mainMenuBar)
        self.SetExtraStyle(0)
        self.SetStatusBarPane(0)

        self.statusBar = wx.StatusBar(id=wxID_MAINFRAMESTATUSBAR,
                                      name=u'statusBar',
                                      parent=self,
                                      style=0)
        self._init_coll_statusBar_Fields(self.statusBar)
        self.SetStatusBar(self.statusBar)

        self.recordPositionList = RecordPositionListCtrl(
            id=wxID_MAINFRAMERECORDPOSITIONLIST,
            name=u'recordPositionList',
            parent=self,
            pos=wx.Point(0, 0),
            size=wx.Size(202, 487),
            style=wx.LC_REPORT | wx.LC_VIRTUAL | wx.LC_HRULES | wx.LC_VRULES)
        self._init_coll_recordPositionList_Columns(self.recordPositionList)
        self.recordPositionList.Bind(wx.EVT_LIST_ITEM_SELECTED,
                                     self.OnRecordPositionListListItemSelected,
                                     id=wxID_MAINFRAMERECORDPOSITIONLIST)

        self.recordViewList = RecordViewListCtrl(
            id=wxID_MAINFRAMERECORDVIEWLIST,
            name=u'recordViewList',
            parent=self,
            pos=wx.Point(202, 0),
            size=wx.Size(404, 487),
            style=wx.LC_REPORT | wx.LC_VIRTUAL | wx.LC_HRULES | wx.LC_VRULES)
        self.recordViewList.SetAutoLayout(False)
        self.recordViewList.SetMinSize(wx.Size(404, 487))
        self._init_coll_recordViewList_Columns(self.recordViewList)

        self._init_sizers()

    def __init__(self, parent):
        self._init_ctrls(parent)
        self.view_stream = None
        EVT_MAPPED(self, self.OnMapped)

    def OnMenuHelpAboutMenu(self, event):
        event.Skip()

    def OnMenuFileOpenMenu(self, event):
        dlg = wx.FileDialog(self, "Choose a file", ".", "", "*.*")
        try:
            if dlg.ShowModal() == wx.ID_OK:
                filename = dlg.GetPath()

                # Set up the mapping parser
                self.map_stream = open(filename, 'rb')
                parser = Parser(inp=self.map_stream)
                self.record_mapper = StreamMapper()
                parser.addSink(self.record_mapper)
                material_mapper = MaterialMapper()
                parser.addSink(material_mapper)
                self.recordPositionList.record_mapper = self.record_mapper
                self.recordPositionList.material_mapper = material_mapper

                # Set up the viewing parser
                self.view_stream = open(filename, 'rb')
                self.view_parser = Parser(inp=self.view_stream)
                self.record_keeper = RecordKeeper()
                self.view_parser.addSink(self.record_keeper)
                self.view_parser.parse(1)

                # Parse the file in a separate thread
                self.mapper = MapperThread(self, parser)

        finally:
            dlg.Destroy()

    def OnMapped(self, event):
        if event.cancelled:
            self.statusBar.SetStatusText('%s... Cancelled!' %
                                         (self.statusBar.GetStatusText()))
        else:
            self.recordPositionList.SetItemCount(
                len(self.record_mapper.indexes))
            self.statusBar.SetStatusText('%s... Done' %
                                         (self.statusBar.GetStatusText()))

        if self.map_stream is not None:
            self.map_stream.close()
            self.map_stream = None
        self.mapper = None

    def OnMenuFileCloseMenu(self, event):
        self.recordPositionList.record_mapper = None
        self.recordPositionList.material_mapper = None
        self.view_stream.close()
        self.view_stream = None
        self.view_parser = None
        self.record_mapper = None

        self.recordPositionList.SetItemCount(0)
        self.recordPositionList.Refresh()
        self.recordViewList.SetItemCount(0)
        self.recordViewList.Refresh()

        if self.mapper:
            self.mapper.cancel()

    def OnMenuFileExitMenu(self, event):
        self.Close()

    def OnRecordPositionListListItemSelected(self, event):
        if self.record_mapper:
            self.view_stream.seek(self.record_mapper.indexes[event.GetIndex()])
            self.view_parser.parse(1)
            self.recordViewList.record = self.record_keeper.record_type, self.record_keeper.record_data
Пример #18
0
class stdfFixer:
    def __init__(self,
                 input_path,
                 output_path,
                 BinDefinition="",
                 QSignal=None):
        self.packFieldType = {
            "C1": self.packStructType,
            "B1": self.packStructType,
            "U1": self.packStructType,
            "U2": self.packStructType,
            "U4": self.packStructType,
            "U8": self.packStructType,
            "I1": self.packStructType,
            "I2": self.packStructType,
            "I4": self.packStructType,
            "I8": self.packStructType,
            "R4": self.packStructType,
            "R8": self.packStructType,
            "Cn": lambda f_type, data: self.packCn(data),
            "Bn": lambda f_type, data: self.packBn(data),
            "Dn": lambda f_type, data: None,  # Dn/Vn not in use
            "Vn": lambda f_type, data: None
        }
        self.outpath = output_path
        self.QSignal = QSignal

        start = time.time()  #
        try:
            self.stdin = open(input_path, "rb")
            self.a = stdfAnalyzer(BinDefinition=BinDefinition, QSignal=QSignal)
            self.p = Parser(inp=self.stdin, QSignal=QSignal)
            self.p.addSink(self.a)
            self.p.parse()
            time.sleep(0.51)  # wait for the last message
            self.fix()
        except Exception as e:
            if self.QSignal != None:
                self.QSignal.message_printer.emit(
                    '''<span style="color:red"><b>Error occurs:<br>{0!r}</b></span>'''
                    .format(e))
        finally:
            end = time.time()  #
            if self.QSignal != None:
                self.QSignal.message_printer.emit("Elapsed time: %.2f sec\n" %
                                                  (end - start))

    def fix(self):
        if self.QSignal != None:
            self.QSignal.message_printer.emit(
                '''<br><span style="color:#3498DB">**{}**</span><br>'''.format(
                    "Analysis completed, start fixing..."))
            self.QSignal.pgbar_setter.emit(0)

        MissingRecList = self.a.getMissingRecList()

        if not len(MissingRecList) == 0:
            byteStream = b''
            for i, recs in enumerate(MissingRecList):
                if self.QSignal != None:
                    self.QSignal.message_printer.emit(
                        '''<span style="color:#3498DB">**{}**</span><br>'''.
                        format("Generating missing " + recs))
                    self.QSignal.pgbar_setter.emit(
                        int(100 * (i + 1) / len(MissingRecList)))
                byteStream += self.getBytes(recs)

            # write into new file
            std_out = open(self.outpath, "wb+")
            self.copy_original(std_out)
            if self.QSignal != None:
                self.QSignal.message_printer.emit(
                    '''<br><span style="color:#3498DB">**{}**</span><br>'''.
                    format("Writing missing data"))
            std_out.write(byteStream)
            std_out.close()
            if self.QSignal != None:
                self.QSignal.message_printer.emit(
                    '''<span style="color:green">Fix successfully! The file is located in<br><b><span style="color:#F39C12">{}</span></b></span><br>'''
                    .format(self.outpath))

        self.stdin.close()

    def copy_original(self, fout):
        if self.QSignal != None:
            self.QSignal.pgbar_setter.emit(0)  # Init progressBar value
        self.p.inp.seek(0)
        bytes_per_read = int(1e6)  # 1M
        FormatSize = lambda num: "%d Bytes" % num if num < 1e3 else (
            "%.2f KB" % (num / 1e3)
            if num < 1e6 else ("%.2f MB" % (num / 1e6)
                               if num < 1e9 else "%.2f GB" % (num / 1e9)))

        while self.p.inp.tell() < self.a.offset:
            bytes_should_read = bytes_per_read if (
                self.p.inp.tell() + bytes_per_read < self.a.offset
            ) else self.a.offset - self.p.inp.tell()
            fout.write(self.p.inp.read(bytes_should_read))

            if self.QSignal != None:
                text = "Copied <b>%s</b>, total <b>%s</b>" % (FormatSize(
                    fout.tell()), FormatSize(self.a.offset))
                self.QSignal.message_printer.emit(text)
                self.QSignal.pgbar_setter.emit(
                    int(100 * fout.tell() / self.a.offset))

    def getBytes(self, recs):

        if recs == "PRR":
            return self.packData(V4.prr, self.a.PRR)

        elif recs == "WRR":
            return self.packData(V4.wrr, self.a.WRR)

        elif recs == "siteSUM":
            tmpBytes = b''
            for site in sorted(self.a.siteTSR.keys()):
                tmpBytes += self.THSP_toBytes(self.a.siteTSR[site],
                                              self.a.siteHBR[site],
                                              self.a.siteSBR[site],
                                              self.a.sitePCR[site])
            return tmpBytes

        elif recs == "overallSUM":
            return self.THSP_toBytes(self.a.sumTSR, self.a.sumHBR,
                                     self.a.sumSBR, self.a.sumPCR)

        elif recs == "MRR":
            return self.packData(V4.mrr, self.a.MRR)

        else:
            pass

    def THSP_toBytes(self, TSR_dict, HBR_dict, SBR_dict, PCR):
        byteOut = b''
        for TEST_NUM in sorted(TSR_dict.keys()):
            byteOut += self.packData(V4.tsr, TSR_dict[TEST_NUM])
        for HBin in sorted(HBR_dict.keys()):
            byteOut += self.packData(V4.hbr, HBR_dict[HBin])
        for SBin in sorted(SBR_dict.keys()):
            byteOut += self.packData(V4.sbr, SBR_dict[SBin])
        byteOut += self.packData(V4.pcr, PCR)

        return byteOut

    def packData(self, recType, Rec_data):
        recDataDict = Rec_data.__dict__

        rec_byte_data = b''
        for field_name, field_type in recType.fieldMap:
            if recType == V4.hbr or recType == V4.sbr:
                if field_name.startswith("HBIN") or field_name.startswith(
                        "SBIN"):
                    field_name = field_name[1:]
            rec_byte_data += self.packFieldType[field_type](
                field_type, recDataDict[field_name])

        rec_byte_len = self.packFieldType["U2"]("U2", len(rec_byte_data))
        rec_byte_typ = self.packFieldType["U1"]("U1", recType.typ)
        rec_byte_sub = self.packFieldType["U1"]("U1", recType.sub)

        return rec_byte_len + rec_byte_typ + rec_byte_sub + rec_byte_data

    def packStructType(self, f_type, data):
        data = data.encode("ascii") if isinstance(data, str) else data
        return struct.pack(self.p.endian + packFormatMap[f_type], data)

    def packCn(self, data):
        s = struct.pack(self.p.endian + str(len(data)) + "s",
                        data.encode("ascii"))
        l = self.packStructType("U1", len(s))
        return l + s

    def packBn(self, data):
        # Bn is only used in PRR during the fix,
        # return default value if PRR needs to be generated
        return b''
Пример #19
0
        if rectype in self.indexable_types:
            head = rec[rectype.HEAD_NUM]
            self.waferid.append(self.getCurrentWafer(head))
            self.insertionid.append(self.getCurrentInsertion(head))
            if rectype in self.per_part_types:
                site = rec[rectype.SITE_NUM]
                self.partid.append(self.getCurrentPart(head, site))
            else:
                self.partid.append(None)
        else:
            self.waferid.append(None)
            self.insertionid.append(None)
            self.partid.append(None)


if __name__ == '__main__':
    from pystdf.IO import Parser
    from pystdf.Writers import AtdfWriter
    import pystdf.V4

    filename, = sys.argv[1:]
    f = open(filename, 'rb')
    p = Parser(inp=f)
    record_mapper = StreamMapper()
    p.addSink(record_mapper)
    p.parse()
    f.close()

    for index, rectype in zip(record_mapper.indexes, record_mapper.types):
        print index, rectype
Пример #20
0
        if rectype in self.indexable_types:
            head = rec[rectype.HEAD_NUM]
            self.waferid.append(self.getCurrentWafer(head))
            self.insertionid.append(self.getCurrentInsertion(head))
            if rectype in self.per_part_types:
                site = rec[rectype.SITE_NUM]
                self.partid.append(self.getCurrentPart(head, site))
            else:
                self.partid.append(None)
        else:
            self.waferid.append(None)
            self.insertionid.append(None)
            self.partid.append(None)
    
if __name__ == '__main__':
    from pystdf.IO import Parser
    from pystdf.Writers import AtdfWriter
    import pystdf.V4
    
    filename, = sys.argv[1:]
    f = open(filename, 'rb')
    p=Parser(inp=f)
    record_mapper = StreamMapper()
    p.addSink(record_mapper)
    p.parse()
    f.close()
    
    for index, rectype in zip(record_mapper.indexes, record_mapper.types):
        print index, rectype