From 756b4fff23b0183940fb9dafc01da6e92cf2f94b Mon Sep 17 00:00:00 2001 From: Prashant Date: Tue, 7 Nov 2023 20:55:48 -0600 Subject: [PATCH] Fixed rm issue --- sciunit2/command/mixin.py | 14 ++++++++------ sciunit2/command/rm.py | 31 ++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/sciunit2/command/mixin.py b/sciunit2/command/mixin.py index 3951a33..6e87f85 100644 --- a/sciunit2/command/mixin.py +++ b/sciunit2/command/mixin.py @@ -17,11 +17,13 @@ def do_commit(self, pkgdir, rev, emgr, repo): # adds the execution to de-duplication engine sz = repo.checkin(rev, pkgdir, sp) # adds the execution to the database - return (repo.location,) + emgr.commit(sz) + commit = emgr.commit(sz) + last_id = emgr.get_last_id() + return (last_id, repo,) + commit def note(self, aList): - return "\n[%s %s] %s\n Date: %s\n" % ( - sciunit2.workspace.project(aList[0]), - aList[1], - quoted(aList[2].cmd), - timestamp.fmt_rfc2822(aList[2].started)) + return "\n[%s e%s] %s\n Date: %s\n" % ( + sciunit2.workspace.project(aList[1].location), + aList[0], + quoted(aList[3].cmd), + timestamp.fmt_rfc2822(aList[3].started)) diff --git a/sciunit2/command/rm.py b/sciunit2/command/rm.py index 5b6ca6b..90aeaad 100644 --- a/sciunit2/command/rm.py +++ b/sciunit2/command/rm.py @@ -21,6 +21,16 @@ def usage(self): @staticmethod def __to_rev(id_): return 'e%d' % id_ + + @staticmethod + def __to_get_current_missing(ids): + + ids = [int(i.lstrip('e')) for i in ids] + ids.sort() + missing_ids = [x for x in range(ids[0], ids[-1] + 1) if x not in ids] + + return missing_ids + @staticmethod def __to_id_range(revrange): @@ -48,15 +58,26 @@ def run(self, args): else: arg = args[0] + ids = [rev for rev, _ in emgr.list()] + + id_bound = self.__to_id_range(arg) + + if ids: + ids = ids + ['e' + str(i) for i in id_bound]+ ['e0'] + ids.append('e0') + + repo_to_unlink = [self.__to_rev(i) for i in self.__to_get_current_missing(ids)] + for rev in repo_to_unlink: + repo.unlink(rev) + + else: + for i in range(1, max(id_bound[0], id_bound[1]) + 1): + repo.unlink(self.__to_rev(i)) + emgr.deletemany(arg) # TODO: see if deletemany could return bounds bounds = self.__to_id_range(arg) - # for id_b in range(bounds[0], bounds[1]): - # repo.unlink(self.__to_rev(id_b)) - # - # for id_a in bounds: - # repo.unlink(self.__to_rev(id_a)) for _id in range(bounds[0], bounds[1]+1): repo.unlink(self.__to_rev(_id))