From 807241bc4f322edc6f95782291900362484263df Mon Sep 17 00:00:00 2001 From: ben Date: Fri, 10 May 2002 23:14:35 +0000 Subject: Lots of changes, see changelog for 0.7.4. git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup/trunk@72 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109 --- rdiff-backup/rdiff_backup/manage.py | 79 +++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 29 deletions(-) (limited to 'rdiff-backup/rdiff_backup/manage.py') diff --git a/rdiff-backup/rdiff_backup/manage.py b/rdiff-backup/rdiff_backup/manage.py index c0f4a85..0c08872 100644 --- a/rdiff-backup/rdiff_backup/manage.py +++ b/rdiff-backup/rdiff_backup/manage.py @@ -12,37 +12,53 @@ class Manage: """Return Increments objects given the rdiff-backup data directory""" return map(IncObj, Manage.find_incrps_with_base(datadir, "increments")) - def find_incrps_with_base(dir_rp, basename): - """Return list of incfiles with given basename in dir_rp""" - rps = map(dir_rp.append, dir_rp.listdir()) - incrps = filter(RPath.isincfile, rps) - result = filter(lambda rp: rp.getincbase_str() == basename, incrps) - Log("find_incrps_with_base: found %d incs" % len(result), 6) - return result + def get_file_type(rp): + """Returns one of "regular", "directory", "missing", or "special".""" + if not rp.lstat(): return "missing" + elif rp.isdir(): return "directory" + elif rp.isreg(): return "regular" + else: return "special" - def describe_root_incs(datadir): + def get_inc_type(inc): + """Return file type increment represents""" + assert inc.isincfile() + type = inc.getinctype() + if type == "dir": return "directory" + elif type == "diff": return "regular" + elif type == "missing": return "missing" + elif type == "snapshot": return Manage.get_file_type(inc) + else: assert None, "Unknown type %s" % (type,) + + def describe_incs_parsable(incs, mirror_time, mirrorrp): + """Return a string parsable by computer describing the increments + + Each line is a time in seconds of the increment, and then the + type of the file. It will be sorted oldest to newest. For example: + + 10000 regular + 20000 directory + 30000 special + 40000 missing + 50000 regular <- last will be the current mirror + + """ + incpairs = [(Time.stringtotime(inc.getinctime()), inc) for inc in incs] + incpairs.sort() + result = ["%s %s" % (time, Manage.get_inc_type(inc)) + for time, inc in incpairs] + result.append("%s %s" % (mirror_time, Manage.get_file_type(mirrorrp))) + return "\n".join(result) + + def describe_incs_human(incs, mirror_time, mirrorrp): """Return a string describing all the the root increments""" - result = [] - currentrps = Manage.find_incrps_with_base(datadir, "current_mirror") - if not currentrps: - Log("Warning: no current mirror marker found", 1) - elif len(currentrps) > 1: - Log("Warning: multiple mirror markers found", 1) - for rp in currentrps: - result.append("Found mirror marker %s" % rp.path) - result.append("Indicating latest mirror taken at %s" % - Time.stringtopretty(rp.getinctime())) - result.append("---------------------------------------------" - "-------------") - - # Sort so they are in reverse order by time - time_w_incobjs = map(lambda io: (-io.time, io), - Manage.get_incobjs(datadir)) - time_w_incobjs.sort() - incobjs = map(lambda x: x[1], time_w_incobjs) - result.append("Found %d increments:" % len(incobjs)) - result.append("\n------------------------------------------\n".join( - map(IncObj.full_description, incobjs))) + incpairs = [(Time.stringtotime(inc.getinctime()), inc) for inc in incs] + incpairs.sort() + + result = ["Found %d increments:" % len(incpairs)] + for time, inc in incpairs: + result.append(" %s %s" % + (inc.dirsplit()[1], Time.timetopretty(time))) + result.append("Current mirror: %s" % Time.timetopretty(mirror_time)) return "\n".join(result) def delete_earlier_than(baserp, time): @@ -53,6 +69,11 @@ class Manage: rdiff-backup-data directory should be the root of the tree. """ + baserp.conn.Manage.delete_earlier_than_local(baserp, time) + + def delete_earlier_than_local(baserp, time): + """Like delete_earlier_than, but run on local connection for speed""" + assert baserp.conn is Globals.local_connection def yield_files(rp): yield rp if rp.isdir(): -- cgit v1.2.1