comparison profilemanager/manager.py @ 75:a63dd19807c8

* actually write the file * dont fatally err if a backup isnt actually there
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 07 May 2010 17:20:13 -0700
parents b6bb59b79525
children e091caa41075
comparison
equal deleted inserted replaced
74:b6bb59b79525 75:a63dd19807c8
3 """ 3 """
4 4
5 import os 5 import os
6 import shutil 6 import shutil
7 import string 7 import string
8 import sys
8 import tempfile 9 import tempfile
9 import time 10 import time
10 import ConfigParser 11 import ConfigParser
11 from datetime import datetime 12 from datetime import datetime
12 from dateutil.parser import parse 13 from dateutil.parser import parse
193 for backup in backups: 194 for backup in backups:
194 if os.path.isabs(backup): 195 if os.path.isabs(backup):
195 backup_dir = backup 196 backup_dir = backup
196 else: 197 else:
197 backup_dir = os.path.join(self.profile_dir, self.backups_dir, backup) 198 backup_dir = os.path.join(self.profile_dir, self.backups_dir, backup)
198 backups_dirs.append((backup, int(os.path.getmtime(backup_dir)))) 199 try:
200 backups_dirs.append((backup, int(os.path.getmtime(backup_dir))))
201 except OSError:
202 print >> sys.stderr, "%s specified in %s, but the directory %s does not exist" % (backup, self.profiles, backup_dir)
199 # TODO: check if the getmtime == the datestamp for relative backups 203 # TODO: check if the getmtime == the datestamp for relative backups
200 204
201 # sort by reverse datestamp 205 # sort by reverse datestamp
202 backups_dirs.sort(key=lambda x: x[1], reverse=True) 206 backups_dirs.sort(key=lambda x: x[1], reverse=True)
203 207
295 parser.remove_option(section, 'Backups') 299 parser.remove_option(section, 'Backups')
296 backups_dir = os.path.join(self.profile_dir, self.backups_dir) 300 backups_dir = os.path.join(self.profile_dir, self.backups_dir)
297 if not os.listdir(backups_dir): 301 if not os.listdir(backups_dir):
298 shutil.rmtree(backups_dir) 302 shutil.rmtree(backups_dir)
299 303
304 self.write(parser)
305
300 # return which backup is restored 306 # return which backup is restored
301 return backup 307 return backup
302 308
303 def temporary(self): 309 def temporary(self):
304 """make a temporary profile""" 310 """make a temporary profile"""