0

I have a bunch of Log Files (single liners), from these files I create a single file with their contents and update them them every n amount of time.

Example:
ID,PID  ,PERCENTAGE
0 ,55666,10
1 ,55667,25
2 ,55668,45
3 ,55669,50

this file gets updated until the main processes are done.Only consistent value is the first member of the array (ID)

I am trying to create a progress bar for each on of these entries. Also these values can increase over time, since more are added as pool limit gets freed from an async task. So below code creates the output file above.

mylist = os.listdir(logPath)
        mylist.remove('cmd.txt')
        mylist= [logPath + s for s in mylist]
        #print mylist , logPath

        with open(logPath + "progess.out", 'w') as outfile:
            for fname in sorted(mylist):
                with open(fname) as (infile):
                    outfile.write(infile.read())    

        f = open(logPath + "progess.out")
        lines = f.readlines()
        for line in lines:
            member = line.split(',')
            print "WEDGEID:" + member[0] + " %" + member[3] + " Frame:" + member[2] + " MB:" + member[6]    

        time.sleep(2)     

I thought about creating a table and populate it with these values, but I am kinda stuck.

2 Answers2

0

so I got it working, very tailored solution to my situation and probably not a good solution also but works

for line in lines:
            member = line.split(',')
            current= int(member[3])
            ProgressBar =  '\33[37m'+"Progress:"+"["+((current/bar_length) * "■" + ("-" * (34 - ((current/bar_length)+1))) ) + "]" +member[3]+ "%"
            print '\33[36m'+"Wedge:"+'\33[32m'+member[0] +"   "+'\33[36m'+" Frame:" +'\33[32m'+member[2]+"   "+'\33[36m'+" Mem Usage:" +'\33[32m' +member[6] ,   
            print ProgressBar
        time.sleep(0.5)

I already had what I needed, :) Although I would like to learn the pythonic way to do this very much.

0

you can use tqdm, if you do not have it installed pip install tqdm

from tqdm import tqdm

...

f = open(logPath + "progess.out")
       lines = f.readlines()
       for line in tqdm(lines):
           member = line.split(',')
           print "WEDGEID:" + member[0] + " %" + member[3] + " Frame:" + member[2] + "MB:" + member[6]
wishmaster
  • 1,437
  • 1
  • 10
  • 19