Docker-in-Docker (DinD) capabilities of public runners deactivated. More info

Commit 792f19e5 authored by Maude Le Jeune's avatar Maude Le Jeune
Browse files

add disk usage tool

parent 15dbd3f2
......@@ -147,4 +147,8 @@ h1{
font-weight: bold;
font-family:Helvetica,Arial,sans-serif;
font-variant: small-caps
}
.dutag{
text-shadow:2px 2px #AFEEEE;
}
\ No newline at end of file
......@@ -32,6 +32,8 @@ from contextlib import closing
import pickle
import os
import sys
import subprocess
import threading
try:
from pipelet.ctools import clean_string
except ImportError:
......@@ -322,7 +324,39 @@ def parse_disk(pipedir):
return lstpipe
def show_disk_usage(pipedir, sqlfile=None, hide=False):
""" Show disk usage for each pipe instance
"""
lstpipe = parse_disk(pipedir)
if not hide:
ddu = dict()
for pipe in lstpipe:
p = subprocess.Popen(["du", "-sh", pipe], stdout=subprocess.PIPE)
out, err = p.communicate()
du = out.split('\t')[0]
ddu[pipe] = du
if sqlfile is None:
sqlfile = os.path.join(pipedir, ".sqlstatus")
conn_lock = threading.Lock()
conn = sqlite3.connect(sqlfile)
conn.text_factory=str
with conn_lock:
with conn:
for pipe in lstpipe:
seg_id,param = conn.execute('select seg_id,param from segments where curr_dir = ?',(pipe,)).fetchone()
if param:
already = len(param.split('<span class="dutag">'))>1
if already:
param = param.split('<span class="dutag">')[0]
if not hide:
param += '<span class="dutag"> %s </span>'%ddu[pipe]
elif not hide:
param = param + '<span class="dutag"> %s </span>'%ddu[pipe]
conn.execute('update segments set param=? where seg_id =?',(param, seg_id))
def rebuild_db_from_disk(pipedir, sqlfile=None):
""" Rebuild db from disk.
......
......@@ -17,6 +17,10 @@ To tag the last computed segment:
%prog --tag-last <sql_file> tag
To remove a tag
%prog --del-tag <sql_file> tag
To show disk usage
%prog --show-disk-usage=<root_dir>
To hide disk usage
%prog --hide-disk-usage=<root_dir>
""")
parser.add_option('-c', '--create-pipeline',
help='Create a new pipeline',)
......@@ -29,7 +33,9 @@ To remove a tag
parser.add_option('-f', '--force', action='store_true', default=False,
help='Actually perform dangerous actions (such as delete-task)',)
parser.add_option('-p', '--prefix',
help='Prefix of the pipeline',)
help='Prefix of the pipeline', default=None)
parser.add_option('--sql-file',
help='sql_file of the pipeline',)
parser.add_option('-a', '--add-user',
help='Setup acl, add a new user',)
parser.add_option('-d', '--del-user',
......@@ -40,7 +46,10 @@ To remove a tag
help='When creating a new user give him this level', default=1, type='int')
parser.add_option('-u', '--upgrade-config',
help='Upgrade config file for v1.1', default=False, action='store_true')
parser.add_option('--show-disk-usage',
help='Show disk usage of each pipeline instance under root', default=None, type='str')
parser.add_option('--hide-disk-usage',
help='Hide disk usage of each pipeline instance under root', default=None, type='str')
(options, args) = parser.parse_args()
......@@ -92,6 +101,13 @@ To remove a tag
seg_id = db_utils.del_tag(options.del_tag, args[0])
#print 'tag segment %d as %s'%(seg_id, args[0])
#db_utils.add_tag(options.tag_last, "%d"%seg_id, args[0])
elif options.show_disk_usage:
from pipelet import utils
utils.show_disk_usage(options.show_disk_usage, sqlfile=options.sql_file)
elif options.hide_disk_usage:
from pipelet import utils
utils.show_disk_usage(options.hide_disk_usage, sqlfile=options.sql_file, hide=True)
else:
if len(args) < 0:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment