Commit 3055d7cf authored by Betoule Marc's avatar Betoule Marc
Browse files

implement a the tag-last utility

parent 2a761817
......@@ -169,7 +169,19 @@ def add_tag (db_file, segid, tag):
fn = glob(os.path.join(l[1], "*.meta"))
_update_meta(fn, str_tag)
def get_last(db_file):
""" Return the last computed segment in a given database.
Return a seg-id
Parameters
----------
db_file: string. Database file name.
"""
conn = sqlite3.connect(db_file, check_same_thread=True)
conn.text_factory=str
l = conn.execute('select seg_id,max(ended_on) from tasks').fetchone()
return l[0]
def _update_meta(fn, str_tag):
""" Update meta file with current tag value.
......
......@@ -2,11 +2,26 @@
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 :\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 = optparse.OptionParser(usage="""
To create a new pipeline:
%prog -c <pipename> [-p <prefix>]
To activate acl and setup a new user:
%prog -a <username> [-l <access_level>] <sql_file>
To suppress an existing user:
%prog -d <username> <sql_file>
To change the data root directory:
%prog -r old_dir new_dir <sql_file>
To delete a selection of task per id:
%prog -t <sql_file> [-f] task_id1 [task_id2 ...]
To tag the last computed segment:
%prog --tag-last <sql_file> tag
""")
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('--tag-last',
help='tag the last computed segment',)
parser.add_option('-f', '--force', action='store_true', default=False,
help='Actually perform dangerous actions (such as delete-task)',)
parser.add_option('-p', '--prefix',
......@@ -56,6 +71,16 @@ def main():
exit(-1)
db_utils.deltask(options.delete_task, args, report_only=not options.force)
elif options.tag_last:
if not args:
parser.print_usage()
exit(-1)
from pipelet import db_utils
seg_id = db_utils.get_last(options.tag_last)
print 'tag segment %d as %s'%(seg_id, args[0])
db_utils.add_tag(options.tag_last, "%d"%seg_id, args[0])
#db_utils.deltask(options.delete_task, args, report_only=not options.force)
else:
if len(args) < 0:
parser.print_usage()
......
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