Commit 145d8551 authored by Betoule Marc's avatar Betoule Marc
Browse files

add a tool to delete tasks from a list

parent 7707e03c
......@@ -32,3 +32,53 @@ def change_root(sql_file,old_prefix, new_prefix):
with conn1:
conn1.execute('update segments set curr_dir = replace(curr_dir, ?,?)', (old_prefix, new_prefix))
conn1.execute('update tasks set str_input = replace(str_input, ?,?)', (old_prefix, new_prefix))
def deltask(db_file, lst_task, report_only=False):
""" Delete a tasks instances.
Delete all products directories of a tasks instance.
Parameters
----------
db_file: string name of the database
lst_task: list of task ids
"""
import shutil
# remove everyboby
conn = sqlite3.connect(db_file,check_same_thread=True)
taskid = lst_task[0]
with conn:
print "removing task %s from db"%taskid
str_input = conn.execute('select str_input from tasks where task_id = ?',(int(taskid),)).fetchone()[0]
lst_task.remove(taskid)
# delete from tasks_relations
if not report_only:
l = conn.execute('delete from task_relations where child_id = ? ',(int(taskid),))
# mark child tasks for deletion
children = conn.execute('select child_id from task_relations where father_id = ? ',(int(taskid),)).fetchall()
# delete from tasks
if not report_only:
l = conn.execute('delete from tasks where task_id = ?',(int(taskid),))
print 'Task %s removed from db'%taskid
else:
print 'Task %s would be removed from db'%taskid
conn.close()
try:
print "Removing directory %s"%str_input
if not report_only:
shutil.rmtree(str_input)
print "%s removed"%str_input
else:
print "%s would be removed"%str_input
except OSError:
print "Failed to remove %s"%str_input
if children:
print "Adding children of %s"%taskid
lst_task += [c[0] for c in children]
lst_task = list(set(lst_task))
lst_task.sort()
if lst_task:
deltask(db_file, lst_task, report_only=report_only)
......@@ -2,9 +2,13 @@
def main():
import optparse
parser = optparse.OptionParser(usage="\nTo create a new pipeline:\n %prog -c <pipename> [-p <prefix>]\nTo activate acl and setup a new user:\n %prog -a <username> [-l <access_level>] <sql_file>\nTo suppress an existing user:\n %prog -d <username> <sql_file>\nTo change the data root directory : %prod -r old_dir new_dir <sql_file>")
parser = optparse.OptionParser(usage="\nTo create a new pipeline:\n %prog -c <pipename> [-p <prefix>]\nTo activate acl and setup a new user:\n %prog -a <username> [-l <access_level>] <sql_file>\nTo suppress an existing user:\n %prog -d <username> <sql_file>\nTo change the data root directory :\n %prog -r old_dir new_dir <sql_file>\nTo delete a selection of task per id:\n %prog -t <sql_file> [-f] task_id1 [task_id2 ...]")
parser.add_option('-c', '--create-pipeline',
help='Create a new pipeline',)
parser.add_option('-t', '--delete-task',
help='Delete the given tasks (and their children if any)',)
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',)
parser.add_option('-a', '--add-user',
......@@ -20,9 +24,6 @@ def main():
(options, args) = parser.parse_args()
if len(args) < 0:
parser.print_usage()
exit(-1)
from pipelet import auth
......@@ -48,6 +49,18 @@ def main():
elif options.upgrade_config:
from pipelet import utils
utils.upgrade_webconfig()
elif options.delete_task:
from pipelet import db_utils
if not args:
parser.print_usage()
exit(-1)
db_utils.deltask(options.delete_task, args, report_only=not options.force)
else:
if len(args) < 0:
parser.print_usage()
exit(-1)
if __name__ == "__main__":
main()
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