comparison profilemanager/manager.py @ 52:85b5fe402ab4

finish backups functionality (to test)
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 07 May 2010 11:22:58 -0700
parents dc9324b52c2a
children c279d2797d45
comparison
equal deleted inserted replaced
51:dc9324b52c2a 52:85b5fe402ab4
159 else: 159 else:
160 backups = name 160 backups = name
161 parser.set(section, 'Backups', backups) 161 parser.set(section, 'Backups', backups)
162 self.write(parser) 162 self.write(parser)
163 163
164 def backups(self, profile=None): 164 def backups(self, profile=None, datestamp=None):
165 """ 165 """
166 list backups for a given profile, or all profiles if the 166 list backups for a given profile, or all profiles if the
167 profile is not given; returns a list of backups if 167 profile is not given; returns a list of backups if
168 profile is given or a dictionary of lists otherwise 168 profile is given or a dictionary of lists otherwise
169 """ 169 """
170 if profile is None: 170 if profile is None: # all profiles
171 # all profiles 171 # XXX this should probably be recursive
172 retval = {} 172 retval = {}
173 profiles_dict = self.profiles_dict()
174 for profile in profiles_dict:
175 if 'Backups' in profiles_dict[profile]:
176 retval[profile] = profiles_dict[profile].split(':')
173 return retval 177 return retval
174 # TODO 178
175 raise NotImplementedError 179 # single profile
180 profile_dict = self.profile_dict(profile)
181 if 'Backups' not in profile_dict:
182 return []
183 backups = profile_dict['Backups'].split(':')
184 backup_dirs = []
185 for backup in backups:
186 if os.path.isabs(backup):
187 backup_dir = backup
188 else:
189 backup_dir = os.path.join(self.profile_dir, self.backups_dir, backup)
190 backups_dirs.append((backup, int(os.path.getmtime(backup_dir))))
191 # TODO: check if the getmtime == the datestamp for relative backups
192
193 # sort by reverse datestamp
194 backups_dirs.sort(key=lambda x: x[1], reverse=True)
195
196 # format to datestamps, if applicable
197 if datestamp:
198 backup_dirs = [ (i[0], time.strftime(datestamp,
199 time.localtime(int(i[1]))))
200 for i ni backup_dirs ]
201
202 return backups_dirs
176 203
177 def restore(self, profile, date=None, delete=False): 204 def restore(self, profile, date=None, delete=False):
178 """ 205 """
179 restore the profile from a backup 206 restore the profile from a backup
180 the most recent backup is used unless `date` is given 207 the most recent backup is used unless `date` is given