Ejemplo n.º 1
0
 def load_file(cls):
     counter=Counter()
     cls.drop()
     data=[]
     for line in read_file(cls.filename):
         if line:
             d=dict(zip(cls.projection,eval(line)))
             brno=d['brno']
             counter[brno]+=1
             d['no']='%03d'%(counter[brno])
             data.append(d)
     cls.insert_many(data)
Ejemplo n.º 2
0
 def split(self,in_file,cue_file):
     #将CUE_FILE转换成UTF8编码
     write_file(cue_file,read_file(cue_file))
     # 获取输出目录
     d=self.get_dir(cue_file)
     # 生成命令行
     cmds=[
         MKDIR_CMD%(d),
         SHNSPLIT_CMD%(self.format,cue_file,d,in_file),
         CUETAG_CMD%(cue_file,d,self.format),
         ]
     # 逐条执行命令
     [exec_shell(x) for x in cmds]
Ejemplo n.º 3
0
def parser(file_name=None,content=None):
    partten=compile(r'( *)(?:'
        r'([a-zA-Z_][a-zA-Z0-9_]*)\s*'
        r'(?:=\s*(".*?"'
        r"|'.*?'"
        r'|\[.*?\]'
        r'|0[xX][0-9a-fA-F]+|[+-]?\d+\.?\d*'
        r'|[a-zA-Z_][a-zA-Z0-9_]*(?:\.[a-zA-Z_][a-zA-Z0-9_]*)*'
        r'))?'
        r')?(#.*$)?'
        )    
    
    owner=[]
    owner_count=0
    if file_name:
        lines=read_file(file_name)
    elif content:
        lines=content.splitlines()
    for line in lines:
        t=partten.findall(line)
        if t:
            level=t[0][0].count('    ')
            attr={}
            tag=None
            for r in t:
                if r[1] and r[2]:
                    v=r[2]
                    if v[0]=='[':
                        v=v[1:-1]
                    attr[r[1]]=v
                elif r[1]:
                    tag=r[1]
                if(tag is None)and attr:
                    tag='property'
        if tag:
            node=element(data=[tag,attr,None])
            if level:
                owner[level-1].append(node)
            if level<owner_count:
                owner[level]=node
            else:
                owner.append(node)
                owner_count+=1
    return owner and owner[0] 
                
Ejemplo n.º 4
0
def parser(file_name=None,content=None):
    partten=compile(r'( *)(?:'
        r'([a-zA-Z_][a-zA-Z0-9_]*)\s*'
        r'(?:=\s*(".*?"'
        r"|'.*?'"
        r'|\[.*?\]'
        r'|0[xX][0-9a-fA-F]+|[+-]?\d+\.?\d*'
        r'|[a-zA-Z_][a-zA-Z0-9_]*(?:\.[a-zA-Z_][a-zA-Z0-9_]*)*'
        r'))?'
        r')?(#.*$)?'
        )    
    
    owner=[]
    owner_count=0
    if file_name:
        lines=read_file(file_name)
    elif content:
        lines=content.splitlines()
    for line in lines:
        t=partten.findall(line)
        if t:
            level=t[0][0].count('    ')
            attr={}
            tag=None
            for r in t:
                if r[1] and r[2]:
                    v=r[2]
                    if v[0]=='[':
                        v=v[1:-1]
                    attr[r[1]]=v
                elif r[1]:
                    tag=r[1]
                if(tag is None)and attr:
                    tag='property'
        if tag:
            node=element(data=[tag,attr,None])
            if level:
                owner[level-1].append(node)
            if level<owner_count:
                owner[level]=node
            else:
                owner.append(node)
                owner_count+=1
    return owner and owner[0] 
Ejemplo n.º 5
0
 def load_file(cls):
     cls.drop()
     cls.insert_many([dict(zip(cls.projection,eval(line))) for \
         line in read_file(cls.filename) if line])