Commit a823365b authored by norvell's avatar norvell
Browse files

Update label_files.py

parent 98b139a6
Loading
Loading
Loading
Loading
+659 −0

File added.

Preview size limit exceeded, changes collapsed.

+16 −26
Original line number Diff line number Diff line
#!/usr/bin/python3

import argparse
import pandas as pd
import collections
import os
import hashlib
import yaml
import shutil
import subprocess



modules = {'stereo_','ism_','mc_','spar_','dirac_','masa_','sba_'}

# Main routine
if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Label c-files in IVAS project and estimate size')
    parser = argparse.ArgumentParser(description='Label c-files in IVAS project and produce Gitlab import CSV file')
    parser.add_argument('--input', action='store', type=str, help='Input path')
    parser.add_argument('--output', action='store', type=str, help='Output xlsx file name')
    parser.add_argument('--output', action='store', type=str, help='Output csv file name')
    args = parser.parse_args()

    indir = args.input
    outfile  = args.output
    
    
    libs = {'apps':'Lib:Apps','lib_com':'Lib:Common','lib_dec':'Lib:Decoder','lib_enc':'Lib:Encoder','lib_rend':'Lib:Renderer','lib_util':'Lib:Utilities','lib_debug':'Lib:Debug'}
    
    filesdict = {'EVS':[],'Framework':[],'Apps':[],'Stereo':[],'ISM':[],'Multichannel':[],'SBA':[],'MASA':[],'Utilities':[],'Renderer':[],'EVSTableROM':[],'IVASTableROM':[]}
    total = 0
    for root, dirs, files in os.walk(indir):
        for filename in files:
            path = os.path.join(root, filename)
        
            root_trim = os.path.split(root)[-1] # Get only parent folder of root (lib_enc etc)        
            path = os.path.join(root_trim, filename)
            
            if filename.endswith('.c') or filename.endswith('.h'):             
                # Sort files into modules
@@ -65,19 +59,15 @@ if __name__ == '__main__':
                                else:
                                    filesdict['EVS'].append(path)
            
            
    columns = ['Path','Size']
    
    with pd.ExcelWriter(outfile) as writer:
    total = 0
    with open(outfile,'w') as fout:
        fout.write('Title;Description\n')
        for mod in filesdict:
            sheet = {'Path':[],'Size':[]}    
            for file in filesdict[mod]:
                with open(file,'r') as fp:
                    lines = len(fp.readlines())
                sheet['Path'].append(file)
                sheet['Size'].append(lines)
                lib = [libs[m] for m in libs if m in file][0]
                
                line = "{};/label ~Status::ToDo ~Type:BASOPFileConversion ~{} ~Module:{}\n".format(file, lib, mod)
                total = total + 1
            data = pd.DataFrame(sheet,columns=columns)
            data.to_excel (writer, sheet_name=mod, index=False)    
                fout.write(line)
     
    print("Sorted {} files".format(total))