예제 #1
0
class File2QRCode(object):
    D_CONST_MAXSIZE=2331
    D_CONST_PREFERSIZE=560
    def __init__(self):
        self._log=LogUtil().logger('core')
        self._qr=qrcode.QRCode()
        self._progfunc=None
        self.clearLastData()
    def clearLastData(self):
        self._lastwidth=0
        self._lasttotalpack=0
        self._lastprefix=''
        self._lastextname=''
        self._lastoutpath=''
    def regProgressFunc(self,func):
        self._log.info('callback(%s) register'%(func.__name__,))
        if callable(func):
            self._progfunc=func
        else:
            self._log.error('callback function error')
    def quickSplit(self,infile,splitsize=D_CONST_PREFERSIZE,outpath='',prefix='quick',method='png'):
        if self._fileCheck(infile):
            if outpath=='':
                outpath=dirname(infile)
            self.splitFile(infile,
                           splitsize,
                           outpath,
                           prefix,
                           method)
            return True
        return False
    def splitFile(self,infile,splitsize,outpath,outprefix,outmethod):
        self._log.info('InFile(%s) SplitSize(%d) OutPath(%s) Prefix(%s) Format(%s)'%(infile,splitsize,outpath,outprefix,outmethod))
        if self._fileCheck(infile):
            self.clearLastData()
            if outpath=='':
                self._log.debug('use current dir as output dir')
                outpath='.'
            if exists(outpath) and isdir(outpath):
                pass
            else:
                self._log.debug('make output dir')
                makedirs(outpath)
            self._lastoutpath=outpath
            self._lastprefix=outprefix
            if splitsize<=0 or splitsize>File2QRCode.D_CONST_MAXSIZE:
                splitsize=File2QRCode.D_CONST_MAXSIZE
                self._log.warning('SplitSize out of range, use %d'%(splitsize,))
            om=str(outmethod).upper()
            if om=='PNG':
                image_factory=qrcode.image.pil.PilImage
                self._lastextname='png'
            else:
                image_factory=qrcode.image.svg.SvgImage
                self._lastextname='svg'
            totalsize=getsize(infile)
            self._log.debug('InFile Size:%d'%(totalsize,))
            currentcnt=1
            self._lasttotalpack=(totalsize+splitsize-1)/splitsize
            self._log.debug('Package Count:%d'%(self._lasttotalpack,))
            self._lastwidth=len(str(self._lasttotalpack))
            with open(infile,'rb') as fh:
                while currentcnt<=self._lasttotalpack:
                    data=fh.read(splitsize)
                    self._qr.add_data(data)
                    img = self._qr.make_image(image_factory=image_factory)
                    outfile=self.getLastFilename(currentcnt)
                    img.save(outfile)
                    self._log.debug('%d/%d InSize:%d OutFile:%s QRVersion:%d'%(currentcnt,self._lasttotalpack,len(data),outfile,self._qr.version))
                    self._qr.clear()
                    self._qr.version=0
                    self._fireCallback(currentcnt,self._lasttotalpack)
                    currentcnt+=1
            return True
        return False
    def getLastFilename(self,idx):
        self._log.info('Index:%d Width:%d Prefix:%s'%(idx,self._lastwidth,self._lastprefix))
        filename=self._genOutfile(self._lastprefix,
                                  self._lastextname,
                                  idx,
                                  self._lastwidth)
        return join(self._lastoutpath,filename)
    def _genOutfile(self,prefix,extname,curcnt,width):
        outstr=prefix
        strfmt="%0"+str(width)+"d"
        outstr+=strfmt%(curcnt)
        outstr+='.'+extname
        return outstr
    def _fileCheck(self,infile):
        if exists(infile) and isfile(infile):
            return True
        return False
    def _fireCallback(self,cur,total):
        self._log.info('Current:%d Total:%d'%(cur,total))
        if self._progfunc:
            self._progfunc(cur,total)
예제 #2
0
class BaseMatrix(object):
    def __init__(self,ivars,ovars,irules,orules):
        self._initdata()
        self._checkdata(ivars,ovars,irules,orules)
    #def __init__(self,ivars,ovars,rules):
        #self._initdata()
        #self._checkdata(ivars,ovars,rules)
    #def _checkdata(self,ivars,ovars,rules):
        #if len(rules)<1:
            #self._log.error('No Rules')
            #return
        #if len(ivars)+len(ovars)!=len(rules[0]):
            #self._log.error('The Number Of I/O Variables Is Wrong')
            #return
        #self._setdata(ivars,ovars,rules)
    def getIVars(self):
        return self._getVars(self._ivars)
    def getOVars(self):
        return self._getVars(self._ovars)
    def iterRules(self):
        for rule in self._rules:
            yield tuple(rule)
    def ruleValues(self):
        outlist=[]
        for rule in self._rules:
            outlist.append(tuple([item['value'] for item in rule]))
        return tuple(outlist)
    def getPairs(self):
        return tuple(self._iopairs)
    def _getVars(self,varlist):
        outlist=[]
        for v in varlist:
            outlist.append(v['value'])
        return tuple(outlist)
    def _initdata(self):
        self._log=LogUtil().logger('Data')
        self._rules=()
        self._ivars=()
        self._ovars=()
        self._icnt=-1
        self._iopairs=()
    def _checkdata(self,ivars,ovars,irules,orules):
        if len(irules)!=len(orules):
            self._log.error('Rule Count for Input[%d] And Output[%d] Are Not Equal'%(len(irules),len(orules)))
            return
        if len(irules)<1:
            self._log.error('No Rules')
            return
        if len(ivars)!=len(irules[0]) or len(ovars)!=len(orules[0]):
            self._log.error('The Number Of I/O Variables Is Wrong')
            return
        rules=[]
        for i in range(len(irules)):
            rules.append([])
            rules[-1].extend(irules[i])
            rules[-1].extend(orules[i])
        self._setdata(ivars,ovars,rules)
    def _setdata(self,ivars,ovars,rules):
        def rulecmp(objx,objy):
            maxidx=len(ivars)
            def _itemcmp(objx,objy,idx):
                ret=cmp(objx[idx]['value'],objy[idx]['value'])
                if ret!=0:
                    if objx[idx]['value']=='__ELSE__' or objy[idx]['value']=='__NOTCARE__':
                        ret=1
                    elif objy[idx]['value']=='__ELSE__' or objx[idx]['value']=='__NOTCARE__':
                        ret=-1
                return ret
            def _rulecmp(objx,objy):
                i=0
                ret=0
                while i<maxidx and ret==0:
                    ret=_itemcmp(objx,objy,i)
                    i+=1
                return ret
            return _rulecmp(objx,objy)
        tmprules=list(rules)
        tmprules.sort(cmp=rulecmp)
        self._rules=list(tmprules)
        self._ivars=list(ivars)
        self._ovars=list(ovars)
        self._icnt=len(self._ivars)

        i=0
        j=0
        maxj=len(self._ovars)
        pairs=[]
        while i<self._icnt:
            ivar=self._ivars[i]['value']
            if ivar.endswith(')'):
                self._log.debug('Finding Pair For Input[%d]:%s'%(i,ivar))
                while j<maxj:
                    ovar=self._ovars[j]['value']
                    self._log.debug('Checking Output[%d]:%s'%(j+self._icnt,ovar))
                    if ovar==ivar:
                        self._log.debug('Found Pair Input[%d]:Output[%d]'%(i,j+self._icnt))
                        pairs.append((i,j+self._icnt))
                        j+=1
                        break
                    j+=1
                else:
                    self._log.error('Functions In Input And Output Donot Match')
                    return
            i+=1
        self._iopairs=tuple(pairs)
예제 #3
0
class Txt2Xml(object):
    D_FIELDSEP='\t'
    D_CASTCHAR='(U1*)'
    D_FLAGSTR1=u'■関数宣言'.encode('utf-8')
    D_FLAGSTR21=u'■自動変数'.encode('utf-8')
    D_FLAGSTR22=u'■完了'.encode('utf-8')
    D_FLAGSTR31=u'■入出力表'.encode('utf-8')
    D_FLAGSTR32=u'■完了'.encode('utf-8')
    D_FLAGSTR33=u'入力'.encode('utf-8')
    D_FLAGSTR34=u'出力'.encode('utf-8')
    D_FLAGSTR41=u'■外部関数'.encode('utf-8')
    D_FLAGSTR42=u'■完了'.encode('utf-8')
    D_FLAGSTR51=u'■外部変数'.encode('utf-8')
    D_FLAGSTR52=u'■完了'.encode('utf-8')
    D_MARK1=u'戻り値'.encode('utf-8')
    D_MARK2=u'○'.encode('utf-8')
    D_MARK3=u'×'.encode('utf-8')
    D_MARK4=u'△'.encode('utf-8')
    D_MARK5=u'-'.encode('utf-8')
    D_MARK6=u'上記以外'.encode('utf-8')

    def __init__(self):
        self._log=LogUtil().logger('Txt2Xml')

    def loadTxt(self,filename,fileencode):
        self._log.info('File:%s Encode:%s'%(filename,fileencode))
        fh=open(filename,'rU')
        data=fh.read()
        fh.close()
        data8=data.decode(fileencode).encode('utf-8')

        self.initData()
        self.splitTxt(data8)
        self.parseTxt()

    def toXml(self,filename):
        root=etree.Element('root')

        func=etree.SubElement(root,'function')
        self._xmlFunc(func,self._funcvars[0])

        for i in range(len(self._funcvars)-1):
            func=etree.SubElement(root,'ex-function')
            self._xmlFunc(func,self._funcvars[i+1])

        if len(self._exvardecl)>0:
            exvar=etree.SubElement(root,'ex-var')
            for data in self._exvardecl:
                self._xmlVar(exvar,data)

        if len(self._vardecl)>0:
            autovar=etree.SubElement(root,'auto-var')
            for data in self._vardecl:
                self._xmlVar(autovar,data)

        matrix=etree.SubElement(root,'matrix')
        self._xmlMatrix(matrix)

        with open(filename,'w') as fh:
            fh.write(etree.tostring(root,
                                    method='xml',
                                    xml_declaration=True,
                                    pretty_print=True,
                                    encoding='utf-8'))

    def _xmlFunc(self,element,funcdata):
        for idx,data in enumerate(funcdata):
            sub=etree.SubElement(element,'param%d'%(idx,))
            sub.set('type',data[0])
            sub.set('name',data[1])
    def _xmlVar(self,element,vardata):
        subvar=etree.SubElement(element,'var')
        subvar.set('type',vardata[0])
        subvar.set('name',vardata[1])
        if len(vardata)==3:
            subvar.set('value',vardata[2])
        elif len(vardata)==5:
            subvar.set('method',vardata[2])
            subvar.set('value',vardata[3])
            subvar.set('size',vardata[4])
    def _xmlMatrix(self,element):
        if len(self._invars)>0:
            invar=etree.SubElement(element,'in-var')
            for idx,v in enumerate(self._invars):
                inv=etree.SubElement(invar,'var%d'%(idx,))
                inv.set('value',v)
        if len(self._outvars)>0:
            outvar=etree.SubElement(element,'out-var')
            for idx,v in enumerate(self._outvars):
                outv=etree.SubElement(outvar,'var%d'%(idx,))
                outv.set('value',v)
        for i in range(len(self._incond)):
            item=etree.SubElement(element,'rule%d'%(i,))
            if len(self._incond[i])>0:
                irule=etree.SubElement(item,'in-rule')
                for idx,value in enumerate(self._incond[i]):
                    ivalue=etree.SubElement(irule,'value%d'%(idx,))
                    ivalue.set('value',value)
            if len(self._outcond[i])>0:
                orule=etree.SubElement(item,'out-rule')
                for idx,value in enumerate(self._outcond[i]):
                    ovalue=etree.SubElement(orule,'value%d'%(idx,))
                    ovalue.set('value',value)

    def initData(self):
        # output for splitTxt
        self._funcs=()
        self._extvars=()
        self._autovars=()
        self._iomatrix=()
        # output for parseTxt
        self._funcvars=[]
        self._exvardecl=[]
        self._vardecl=[]
        self._invars=[]
        self._outvars=[]
        self._incond=[]
        self._outcond=[]

    def splitTxt(self,data8):
        flag=0 #0:init
        step=0
        flagtable=((self.D_FLAGSTR1,1),
                   (self.D_FLAGSTR21,2),
                   (self.D_FLAGSTR31,3),
                   (self.D_FLAGSTR41,4),
                   (self.D_FLAGSTR51,5))
        donetable=[]
        funcdeclare=''
        autovars=[]
        iomatrix=[]
        extfunc=[]
        extvars=[]
        for lineno,line in enumerate(data8.splitlines()):
            if flag==0:
                for item in flagtable:
                    if line.startswith(item[0]):
                        self._log.debug('Found Start-tag:%d at line:%d'%(item[1],lineno))
                        if item[1] not in donetable:
                            flag=item[1]
                            donetable.append(flag)
                            step=0
                            break
                        else:
                            self._log.warning('Found Duplicated Start-tag:%d'%(item[1],))
            if flag==1:
                # function declare
                if step==0:
                    step=1
                elif step>=1:
                    funcdeclare=line.strip()
                    self._log.debug('Found End-tag:%d at line:%d'%(flag,lineno))
                    flag=0
            elif flag==2:
                # auto vars
                if step<2:
                    step+=1
                elif step>=2:
                    if line.startswith(self.D_FLAGSTR22):
                        self._log.debug('Found End-tag:%d at line:%d'%(flag,lineno))
                        flag=0
                    else:
                        autovars.append(line.strip())
            elif flag==3:
                # i/o matrix
                if step==0:
                    step+=1
                else:
                    iomatrix.append(line)
                    if self.D_FLAGSTR32 in line:
                        self._log.debug('Found End-tag:%d at line:%d'%(flag,lineno))
                        flag=0
            elif flag==4:
                # extern function
                if step==0:
                    step+=1
                else:
                    if line.startswith(self.D_FLAGSTR42):
                        self._log.debug('Found End-tag:%d at line:%d'%(flag,lineno))
                        flag=0
                    else:
                        extfunc.append(line.strip())
            elif flag==5:
                # extern vars
                if step<2:
                    step+=1
                else:
                    if line.startswith(self.D_FLAGSTR52):
                        self._log.debug('Found End-tag:%d at line:%d'%(flag,lineno))
                        flag=0
                    else:
                        extvars.append(line.strip())
        self._autovars=tuple(autovars)
        self._iomatrix=tuple(iomatrix)
        funcs=[]
        funcs.append(funcdeclare)
        funcs.extend(extfunc)
        self._funcs=tuple(funcs)
        self._extvars=tuple(extvars)

    def parseTxt(self):
        for func in self._funcs:
            self._funcvars.append(self.parseFuncDecl(func))
        self.parseExtVars()
        self.parseAutoVars()
        self.parseIOMatrix()

    def parseFuncDecl(self,fdec):
        self._log.info('Parse Function Declaration:%s'%(fdec,))
        pos_l=fdec.find('(')
        pos_r=fdec.rfind(')')
        outdata=[]
        if pos_l<0 or pos_r!=len(fdec)-1:
            self._log.warning('cannot find proper "(" and ")"')
        else:
            outdata.append(self._parseFuncParam(fdec[:pos_l]))
            for param in fdec[pos_l+1:pos_r].split(','):
                outdata.append(self._parseFuncParam(param))
        return tuple(outdata)
    def _parseFuncParam(self,data):
        self._log.debug('Parse Function Parameter:%s'%(data,))
        ptype=''
        pname=''
        sdata=data.strip()
        rpat=re.compile(r'(?P<type>.+[^a-zA-Z0-9_])(?P<name>[a-zA-Z0-9_]+)')
        rret=rpat.search(sdata)
        if rret:
            ptype=rret.group('type').strip()
            pname=rret.group('name').strip()
        else:
            ptype=sdata.strip()
            pname=ptype
        return tuple((ptype,pname))

    def parseExtVars(self):
        for line in self._extvars:
            self._log.debug('Parse External Parameter:%s'%(line,))
            parts=line.split(self.D_FIELDSEP)
            if len(parts)<2:
                self._log.warning('Input Check Error, Skip')
            else:
                self._exvardecl.append((parts[0],parts[1]))
    def parseAutoVars(self):
        for line in self._autovars:
            self._log.debug('Parse Internal Parameter:%s'%(line,))
            parts=line.split(self.D_FIELDSEP)
            if len(parts)<2:
                self._log.warning('Input Check Error, Skip')
            else:
                if len(parts)==2:
                    parts.append('0')
                if parts[2]=='memset':
                    if len(parts)<4:
                        parts.append('')
                    if parts[3]=='':
                        parts[3]='0'
                    if len(parts)<5:
                        parts.append('')
                    if parts[4]=='':
                        parts[4]='sizeof(%s)'%(parts[0],)
                    self._vardecl.append(tuple(parts[0:5]))
                elif parts[2]=='memcpy':
                    if len(parts)<4:
                        parts.append('')
                    if parts[3]=='':
                        self._log.warning('No Source Buffer Found, Change To memset')
                        parts[2]='memset'
                        parts[3]='0'
                    if len(parts)<5:
                        parts.append('')
                    if parts[4]=='':
                        parts[4]='sizeof(%s)'%(parts[0],)
                    self._vardecl.append(tuple(parts[0:5]))
                else:
                    self._vardecl.append(tuple(parts[0:3]))

    def parseIOMatrix(self):
        inidx,outidx=0,0
        parts=self._iomatrix[0].split(self.D_FIELDSEP)
        if self.D_FLAGSTR34 in parts:
            inidx=parts.index(self.D_FLAGSTR34)
        else:
            self._log.error('No Output Found')
            return
        parts=self._iomatrix[-1].split(self.D_FIELDSEP)
        if self.D_FLAGSTR32 in parts:
            outidx=parts.index(self.D_FLAGSTR32)
        else:
            self._log.error('Cannot Figure Out Count Of In/Out Vars')
            return
        parts=self._iomatrix[1].split(self.D_FIELDSEP)
        if len(parts)<=outidx:
            self._log.error('Not Enough In/Out Vars')
            return
        else:
            if self.D_MARK1 in parts:
                parts[parts.index(self.D_MARK1)]='__RET__'
            for i in range(inidx):
                self._invars.append(parts[i].strip())
            for i in range(outidx-inidx+1):
                self._outvars.append(parts[i+inidx].strip())
        for line in self._iomatrix[2:-1]:
            self._log.debug('Parse I/O Matrix:%s'%(line.decode('utf-8'),))
            parts=line.split(self.D_FIELDSEP)
            for markfrom,markto in ((self.D_MARK2,'__CALL__'),
                                    (self.D_MARK3,'__NOCALL__'),
                                    (self.D_MARK4,'__NOTCARE__'),
                                    (self.D_MARK5,'__NOACT__'),
                                    (self.D_MARK6,'__ELSE__')):
                while markfrom in parts:
                    parts[parts.index(markfrom)]=markto
            self._incond.append([])
            self._outcond.append([])
            for i in range(inidx):
                self._incond[-1].append(parts[i].strip())
            for i in range(outidx-inidx+1):
                self._outcond[-1].append(parts[i+inidx].strip())
예제 #4
0
class XmlReader(object):
    def __init__(self):
        self._log = LogUtil().logger("XmlReader")

    def loadXml(self, filename):
        self._log.info("Reading XML File:%s" % (filename,))
        self._initdata()
        tagstack = []
        for action, elem in etree.iterparse(filename, events=("start", "end")):
            if action == "start":
                tag = elem.tag
                tagstack.append(tag)
                self.starttag(":".join(tagstack), elem)
            else:
                self.endtag(":".join(tagstack), elem)
                tagstack.pop(-1)

    def getInfo(self, infoobj):
        if not isinstance(infoobj, ManageC):
            return False
        for func in self._funcs:
            infoobj.addFunction(func)
        for var in self._vars:
            infoobj.addVariable(var)
        infoobj.setMatrix(self._invars, self._outvars, self._incond, self._outcond)
        return True

    def _initdata(self):
        self._funcs = []
        self._funcs.append([])
        self._vars = []
        self._invars = []
        self._outvars = []
        self._incond = []
        self._outcond = []

    def starttag(self, path, elem):
        if path.startswith("root:function:param"):
            self._log.debug(path)
            self._funcs[0].append(elem.attrib)
        elif path == "root:ex-function":
            self._log.debug(path)
            self._funcs.append([])
        elif path.startswith("root:ex-function:param"):
            self._log.debug(path)
            self._funcs[-1].append(elem.attrib)
        elif path.startswith("root:ex-var:var"):
            self._log.debug(path)
            self._vars.append(elem.attrib)
        elif path.startswith("root:auto-var:var"):
            self._log.debug(path)
            self._vars.append(elem.attrib)
        elif path.startswith("root:matrix:in-var:var"):
            self._log.debug(path)
            self._invars.append(elem.attrib)
        elif path.startswith("root:matrix:out-var:var"):
            self._log.debug(path)
            self._outvars.append(elem.attrib)
        elif path.startswith("root:matrix:rule"):
            if path.endswith("in-rule"):
                self._incond.append([])
            elif path.endswith("out-rule"):
                self._outcond.append([])
            if ":in-rule:value" in path:
                self._log.debug(path)
                self._incond[-1].append(elem.attrib)
            elif ":out-rule:value" in path:
                self._log.debug(path)
                self._outcond[-1].append(elem.attrib)

    def endtag(self, path, elem):
        if path == "root:function":
            self._log.debug(path)
        elif path == "root:ex-function":
            self._log.debug(path)
        elif path == "root:ex-var":
            self._log.debug(path)
        elif path == "root:auto-var":
            self._log.debug(path)
        elif path == "root:matrix:in-var":
            self._log.debug(path)
        elif path == "root:matrix:out-var":
            self._log.debug(path)
        elif path.startswith("root:matrix:rule"):
            if ":in-rule:value" in path:
                self._log.debug(path)
            elif ":out-rule:value" in path:
                self._log.debug(path)
예제 #5
0
class F2QToolPanel(wx.Panel):
    def __init__(self,parent,id=wx.ID_ANY,pos=wx.DefaultPosition,size=wx.DefaultSize,style=wx.TAB_TRAVERSAL,name=wx.PanelNameStr):
        super(F2QToolPanel,self).__init__(parent,id,pos,size,style,name)
        self._log=LogUtil().logger('ui')
        self._tool=f2q.File2QRCode()
        self._tool.regProgressFunc(self.OnProgress)
        self.SetupUi()
    def SetupUi(self):
        sizer=wx.GridBagSizer()
        label1=wx.StaticText(self,label='Input File')
        self._txt1=wx.TextCtrl(self,value='')
        btn1=wx.Button(self,label='...')
        label2=wx.StaticText(self,label='Output Path')
        self._txt2=wx.TextCtrl(self,value='')
        btn2=wx.Button(self,label='...')
        label31=wx.StaticText(self,label='Split Size')
        label32=wx.StaticText(self,label='Format')
        self._combo31=wx.ComboBox(self,choices=('14','26','42','62',
                                          '84','106','122','152',
                                          '180','213','251','287',
                                          '331','362','412','450',
                                          '504','560','624','666',
                                          '711','779','857','911',
                                          '997','1059','1125','1190',
                                          '1264','1370','1452','1538',
                                          '1628','1722','1809','1911',
                                          '1989','2099','2213','2331')
                                          ,value='560',style=wx.CB_READONLY)
        self._combo32=wx.ComboBox(self,choices=('png','svg'),value='png',style=wx.CB_READONLY)
        label4=wx.StaticText(self,label='Prefix')
        self._txt4=wx.TextCtrl(self,value='quick')
        btn4=wx.Button(self,label='Split')
        sizer.Add(label1,(0,0),flag=wx.EXPAND)
        sizer.Add(self._txt1,(0,1),(1,3),flag=wx.EXPAND)
        sizer.Add(btn1,(0,4),flag=wx.EXPAND)
        sizer.Add(label2,(1,0),flag=wx.EXPAND)
        sizer.Add(self._txt2,(1,1),(1,3),flag=wx.EXPAND)
        sizer.Add(btn2,(1,4),flag=wx.EXPAND)
        sizer.Add(label31,(2,0),flag=wx.EXPAND)
        sizer.Add(self._combo31,(2,1),flag=wx.EXPAND)
        sizer.Add(label32,(2,3),flag=wx.EXPAND)
        sizer.Add(self._combo32,(2,4),flag=wx.EXPAND)
        sizer.Add(label4,(3,0),flag=wx.EXPAND)
        sizer.Add(self._txt4,(3,1),(1,3),flag=wx.EXPAND)
        sizer.Add(btn4,(3,4),flag=wx.EXPAND)
        sizer.SetFlexibleDirection(wx.HORIZONTAL)
        sizer.AddGrowableCol(2)
        self.SetSizer(sizer)
        self.Bind(wx.EVT_BUTTON,self.OnInBtn,btn1)
        self.Bind(wx.EVT_BUTTON,self.OnOutBtn,btn2)
        self.Bind(wx.EVT_BUTTON,self.OnActBtn,btn4)
    def OnProgress(self,curcnt,totalcnt):
        self._log.info('Callback(%d/%d)'%(curcnt,totalcnt))
        self.GetParent().SetStatusText("%d/%d"%(curcnt,totalcnt),2)
        if curcnt>=totalcnt:
            msgbox=wx.MessageDialog(self,message='Split Done!',style=wx.OK|wx.CENTER)
            msgbox.ShowModal()
    def OnInBtn(self,event):
        self._log.info('ButtonPressed')
        infile=self._txt1.GetValue()
        if infile:
            pathname,filename=os.path.split(infile)
            fd=wx.FileDialog(self,message='Select file to split...',defaultDir=pathname,defaultFile=filename)
        else:
            fd=wx.FileDialog(self,message='Select file to split...')
        if fd.ShowModal()==wx.ID_OK:
            fullname=fd.GetPath()
            self._log.debug('FileDialog:%s'%(fullname,))
            pathname,filename=os.path.split(fullname)
            filesize=os.path.getsize(fullname)
            self._txt1.SetValue(fullname)
            self._txt2.SetValue(pathname)
            self.GetParent().SetStatusText(filename,0)
            self.GetParent().SetStatusText("%d Bytes"%(filesize,),1)
            self.GetParent().SetStatusText("",2)
    def OnOutBtn(self,event):
        self._log.info('ButtonPressed')
        outpath=self._txt2.GetValue() or '.'
        fd=wx.DirDialog(self,message='Select output path...',defaultPath=outpath)
        if fd.ShowModal()==wx.ID_OK:
            pathname=fd.GetPath()
            self._log.debug('DirDialog:%s'%(pathname,))
            self._txt2.SetValue(pathname)
    def OnActBtn(self,event):
        self._log.info('ButtonPressed')
        infile=self._txt1.GetValue()
        outpath=self._txt2.GetValue()
        prefix=self._txt4.GetValue()
        splitsize=int(self._combo31.GetValue())
        method=self._combo32.GetValue()
        self._log.debug('InFile:%s SplitSize:%d OutPath:%s Prefix:%s Format:%s'%(infile,splitsize,outpath,prefix,method))
        self._tool.quickSplit(infile,splitsize,outpath,prefix,method)
예제 #6
0
class VcProj(object):
    def __init__(self):
        self._log = LogUtil().logger("TestManager")

    def autoVcproj(self, searchpath, tplfile, outfile, filelist):
        srcvcproj = self._findVcproj(searchpath)
        if srcvcproj:
            self.generateVcproj(srcvcproj, tplfile, outfile, filelist)

    def generateVcproj(self, infile, tplfile, outfile, filelist):
        if exists(infile):
            info = self._getVcprojInfo(infile)
            self.manualVcproj(info[0], info[1], tplfile, outfile, filelist)

    def manualVcproj(self, incpath, compileoption, tplfile, outfile, filelist):
        self._genVcproj(outfile, incpath, compileoption, filelist, tplfile)

    def _genVcproj(self, outfile, incpath, compileoption, filelist, tplfile):
        self._log.debug("Generate .vcproj file:%s" % (outfile,))
        incpath = incpath.strip(" ;")
        incpath = re.sub(r";+", r";", incpath)
        compileoption = compileoption.strip(" ;")
        compileoption = re.sub(r";+", r";", compileoption)
        fin = open(tplfile, "rU")
        fout = open(outfile, "w")
        for line in fin.readlines():
            if 'AdditionalIncludeDirectories=""' in line:
                self._log.debug("Set IncludePath:%s" % (incpath,))
                fout.write('\t\t\t\tAdditionalIncludeDirectories="%s"\n' % (incpath,))
            elif 'PreprocessorDefinitions=""' in line:
                self._log.debug("Set CompileOption:%s" % (compileoption,))
                fout.write('\t\t\t\tPreprocessorDefinitions="%s"\n' % (compileoption,))
            elif "<Files>" in line:
                self._log.debug("Set File:%s" % (str(filelist),))
                fout.write(line)
                for filename in filelist:
                    line = '\t\t<File\n\t\t\tRelativePath="%s"\n\t\t\t>\n\t\t</File>\n' % (filename,)
                    fout.write(line)
            else:
                fout.write(line)
        self._incpath = incpath
        self._compileoption = compileoption
        fout.close()
        fin.close()

    def _getVcprojInfo(self, vcprojfile, part="Debug|Win32"):
        self._log.debug("Read .vcproj file:%s, part:%s" % (vcprojfile, part))
        fin = open(vcprojfile, "rU")
        incpath = ""
        compileoption = ""
        flag = False
        for line in fin.readlines():
            if flag:
                if not incpath and "AdditionalIncludeDirectories" in line:
                    startidx = line.find('"')
                    stopidx = line.rfind('"')
                    incpath = line[startidx + 1 : stopidx]
                    self._log.debug("IncludePath:%s" % (incpath,))
                elif not compileoption and "PreprocessorDefinitions" in line:
                    startidx = line.find('"')
                    stopidx = line.rfind('"')
                    compileoption = line[startidx + 1 : stopidx]
                    self._log.debug("CompileOption:%s" % (compileoption,))
            else:
                if part in line:
                    flag = True
        fin.close()
        return incpath, compileoption

    def _findVcproj(self, startfolder):
        if exists(startfolder) and isdir(startfolder):
            sdir = abspath(startfolder)
            while True:
                self._log.debug("Find .vcproj file in folder:%s" % (sdir,))
                for curfile in listdir(sdir):
                    if curfile.upper().endswith(".VCPROJ"):
                        self._log.debug("Found .vcproj file:%s" % (join(sdir, curfile)))
                        return join(sdir, curfile)
                # move to parent dir
                while True:
                    parts = split(sdir)
                    if parts[0] == sdir:
                        # sdir is root dir(e.g d:/)
                        self._log.error("Cannot find .vcproj file until root folder")
                        return ""
                    sdir = parts[0]
                    if parts[1] == "":
                        # sdir endswith '/'
                        pass
                    else:
                        break
        else:
            return ""
예제 #7
0
def formatExcelText(funcname, finfo):
    """
    @param funcname:
    @param finfo: cparser.getTestFuncInfo()[funcname][idx]
    @ret   text for Excel
    """
    log = LogUtil().logger("DriverParser")
    outtxt = ""
    # target function
    fdecl = finfo["decl"]
    funcstr = " %s " % (funcname,)
    didx = fdecl.find(funcstr)
    functype = fdecl[0:didx]
    didx += len(funcstr)
    startidx = fdecl.find("(", didx)
    stopidx = fdecl.rfind(")")
    parts = fdecl[startidx + 1 : stopidx].strip().split(" ")
    params = []
    while "," in parts:
        didx = parts.index(",")
        params.append(parts[0:didx])
        parts = parts[didx + 1 :]
    outtxt += "%s\n" % (fdecl,)
    outtxt += "ret = %s(%s);\n\n" % (funcname, ",".join([x[-1] for x in params if len(x) > 1]))
    for x in params:
        if len(x) > 1:
            outtxt += "%s\t%s\tlocal\tmemset((char*)&%s,0x7c,sizeof(%s));\n" % (
                x[-1],
                " ".join(x[0:-1]),
                x[-1],
                " ".join(x[0:-1]),
            )
    outtxt += "\nret\t%s\tlocal\tmemset((char*)&ret,0x7c,sizeof(%s));\n\n" % (functype, functype)
    # dummy function
    fcalls = finfo["calls"]
    fothers = finfo["calldecl"]
    flog = {}
    for fcall in fcalls:
        parts = fcall.split(":")
        funcstr = " " + parts[0] + " "
        funccnt = int(parts[1])
        flog[fcall] = []
        for fother in fothers:
            if funcstr in fother:
                if len(flog[fcall]) < 1:
                    didx = fother.find(funcstr)
                    if funccnt > 1:
                        for i in range(funccnt):
                            outname = fother[0 : didx + 1] + "dummy" + str(i + 1) + "_" + fother[didx + 1 :]
                            outtxt += "%s\t%s\tfunction\n" % (outname, fother[0:didx])
                    else:
                        outname = fother
                        outtxt += "%s\t%s\tfunction\n" % (outname, fother[0:didx])
                else:
                    # multiple function body for one dummy function
                    pass
                flog[fcall].append(fother)
    for key, value in sorted(flog.items()):
        if len(value) == 0:
            log.debug("No Function Body[%s] Found" % (key,))
            outtxt += "%s\t\tfunction\n" % (key,)
        elif len(value) > 1:
            tmpset = set(value)
            if len(tmpset) > 1:
                log.debug("Muliple Function Bodies[%s] Found:%s" % (key, str(tmpset)))
    return outtxt