Esempio n. 1
0
scale = 1.
cmd = "/usr/bin/iostat %s" % (device)
refresh = 2.0 #not too low, may slow ios down
print(cmd)


max_speed_in_kB_per_s = 1024 * 1024 # 1GB/s
def scale_fun(speed_in_kB):
    norm_speed_in_kB = (speed_in_kB) / float(max_speed_in_kB_per_s)
    return int(round(Nbar * (1. - math.exp(-4 * norm_speed_in_kB))))
        
T, KR, KW = None, None, None
while True:
    #l = subprocess.Popen(cmd, stdout = subprocess.PIPE, shell = True).communicate()[0].split('\n')
    #print(cmd)
    l = execbash(cmd, shell=True)[0].split('\n')
    #print(l)
    #raise
    t  = time.time()
    tt = time.asctime().split()[3]
    while len(l):
        ll = l.pop(0)
        if not len(ll): 
            continue
        if ll.startswith("Device"):
            break
    if "kB_read" not in ll:
        raise Exception

    if "kB_wrtn" not in ll:
        raise Exception
Esempio n. 2
0
            dirtemp=dirtemp,
            i=i)
        i += 1

    script += ffmpeg_script.format(rate=rate, dirtemp=dirtemp)
    script += close_script.format(dirtemp=dirtemp)

    # ============ print on screen
    print(script)

    # ============ execute shell script
    if not dry_run:
        try:
            timeout = 60.
            start = time.time()
            stdout, stderr = execbash(script, shell=True)
            while time.time() - start <= timeout:
                if os.path.isfile(filename):
                    break
                time.sleep(1.0)
            else:
                raise OSError(
                    'Time out, could not find {} after {}s, error : {}'.format(
                        filename, timeout, stderr))
        except (OSError) as e:
            os.system('trash mov.mp4')
            raise
        finally:
            if os.path.isdir(dirtemp):
                # force clean up
                script = "trash {dirtemp}".format(dirtemp=dirtemp)
Esempio n. 3
0
import os, sys, glob, time
import numpy as np

TERMWIDTH = 160

def affiche(LLL):
    for l in LLL:
        if len(l) > TERMWIDTH:
            print(l[:TERMWIDTH])
        else:
            print(l.split('\n')[0])


if __name__ == "__main__":
    _user = whoami()
    L = execbash('ps -ef | grep {}'.format(_user), shell=True)[0].split('\n')

    # =====================
    Lpython = []
    Lpy = []
    Lgedit = []
    Lother = []
    for l in L:
        if "python " in l or "python2.7" in l:
            Lpython.append(l)
        elif ".py" in l:
            Lpy.append(l)
        elif "gedit" in l:
            Lgedit.append(l)
        else:
            Lother.append(l)
Esempio n. 4
0
#!/usr/bin/env python
from lintools.linuxcmds import execbash
import subprocess
import sys
import numpy as np
"""
same as du -sch but ordered by size
"""

#p = subprocess.Popen('du -sc ' + " ".join(sys.argv[1:]),
#shell = True, stdout = subprocess.PIPE)
#stdout, _ = p.communicate()
#stdout = str(stdout)

stdout = execbash('du -sc ' + " ".join(sys.argv[1:]), shell=True)[0]
s, d = zip(*[(int(_.split('\t')[0]), _.split('\t')[1])
             for _ in stdout.split('\n') if _.strip() != ''])
I = np.argsort(s)

cmd = 'du -sch ' + " ".join([d[i] for i in I if "total" not in d[i]])
subprocess.call(cmd, shell=True)  #, stdout = subprocess.PIPE)
#execbash(cmd, shell = True)#, stdout = subprocess.PIPE)
Esempio n. 5
0
        if os.path.isfile(item):
            extension = item.split('/')[-1]
            if "." in extension:
                extension = extension.split('.')[-1]
            else:
                continue
            if not extension in extensions:
                extensions.append(extension)
    print(extensions)
    sizes = []
    isizes = []
    for extension in extensions:
        cmd = "find {} -type f -name '*.{}' -print0 | xargs -0 du -ch | grep total | awk '{{print $1}}'".format(
            dirname, extension)
        #print(cmd)
        out, err = execbash(cmd)
        #print(out)
        sz = out.split()[0]
        sizes.append(sz)
        isz = eval(
            sz.replace('B', '').replace('K',
                                        '*1e3').replace('M', '*1e6').replace(
                                            'G', '*1e9').replace(',', '.'))
        isizes.append(isz)

    I = np.argsort(isizes)
    sizes = [sizes[i] for i in I]
    extensions = [extensions[i] for i in I]

    for ext, sz in zip(extensions, sizes):
        print('*.{:<20s} {}'.format(ext, sz))