# HG changeset patch # User Jeff Hammel # Date 1273256578 25200 # Node ID 85b5fe402ab4666c9e62baab1151a6c28499cdf2 # Parent dc9324b52c2aea376ccf01dc566083e04e34e1c2 finish backups functionality (to test) diff -r dc9324b52c2a -r 85b5fe402ab4 profilemanager/manager.py --- a/profilemanager/manager.py Fri May 07 09:59:08 2010 -0700 +++ b/profilemanager/manager.py Fri May 07 11:22:58 2010 -0700 @@ -161,18 +161,45 @@ parser.set(section, 'Backups', backups) self.write(parser) - def backups(self, profile=None): + def backups(self, profile=None, datestamp=None): """ list backups for a given profile, or all profiles if the profile is not given; returns a list of backups if profile is given or a dictionary of lists otherwise """ - if profile is None: - # all profiles + if profile is None: # all profiles + # XXX this should probably be recursive retval = {} + profiles_dict = self.profiles_dict() + for profile in profiles_dict: + if 'Backups' in profiles_dict[profile]: + retval[profile] = profiles_dict[profile].split(':') return retval - # TODO - raise NotImplementedError + + # single profile + profile_dict = self.profile_dict(profile) + if 'Backups' not in profile_dict: + return [] + backups = profile_dict['Backups'].split(':') + backup_dirs = [] + for backup in backups: + if os.path.isabs(backup): + backup_dir = backup + else: + backup_dir = os.path.join(self.profile_dir, self.backups_dir, backup) + backups_dirs.append((backup, int(os.path.getmtime(backup_dir)))) + # TODO: check if the getmtime == the datestamp for relative backups + + # sort by reverse datestamp + backups_dirs.sort(key=lambda x: x[1], reverse=True) + + # format to datestamps, if applicable + if datestamp: + backup_dirs = [ (i[0], time.strftime(datestamp, + time.localtime(int(i[1])))) + for i ni backup_dirs ] + + return backups_dirs def restore(self, profile, date=None, delete=False): """