comparison profilemanager/manager.py @ 8:7205cb6f5530

various flushing out, deleting old TODOs and making new ones
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 13 Apr 2010 19:24:52 -0700
parents d3b22d086934
children b1274abd1206
comparison
equal deleted inserted replaced
7:d3b22d086934 8:7205cb6f5530
40 if directories: 40 if directories:
41 values.append(self.path(name)) 41 values.append(self.path(name))
42 retval.append(values) 42 retval.append(values)
43 return format_tabular(retval) 43 return format_tabular(retval)
44 44
45 def clone(self, source, dest): 45 def backups(self, profile=None):
46 """
47 list backups for a given profile, or all profiles if the
48 profile is not given
49 """
50 # TODO
51
52 def clone(self, source, dest, hash=True):
46 """ 53 """
47 clones the profile `source` and output to `dest` 54 clones the profile `source` and output to `dest`
48 """ 55 """
49 source_path = self.path(source) # fs path of the `from` profile 56 source_path = self.path(source) # fs path of the `from` profile
50 57
51 dest_path = self.path(dest) # fs path to back up to 58 # dest: fs path to back up to
52 # TODO: prepend a hash key 59 relative = False
60 if not os.path.isabs(dest):
61 relative = True
62 if not os.path.dirname(dest):
63 dest = '%s.%s' % (self.hash(), dest)
64 dest = os.path.join(self.profile_dir, dest)
53 65
54 shutil.copytree(source_path, dest_path, symlinks=False) 66 shutil.copytree(source_path, dest, symlinks=False)
55 67
56 # update profiles.ini 68 # TODO: update profiles.ini
57 # TODO 69
58
59 70
60 def backup(self, profile, dest=None): 71 def backup(self, profile, dest=None):
61 """ 72 """
62 backup the profile 73 backup the profile
63 - profile: name of the profile to be backed up 74 - profile: name of the profile to be backed up
64 - dest: name of the destination (optional) 75 - dest: name of the destination (optional)
65 """ 76 """
66 # XXX should use `self.clone` !
67 if dest is None: 77 if dest is None:
68 dest = '' 78 dest = '%s.%d.bak' % (profile, int(time.time()))
69 self.clone(profile, dest) 79 self.clone(profile, dest, hash=False)
70 # TODO: add something like 80 # TODO: add something like
71 # `Backup=$(profile)s.$(datestamp)s.bak` 81 # `Backup=$(profile)s.$(datestamp)s.bak`
72 # to self.profiles 82 # to self.profiles
73 83
74 def restore(self, profile, date=None, delete=False): 84 def restore(self, profile, date=None, delete=False):
76 restore the profile from a backup 86 restore the profile from a backup
77 the most recent backup is used unless `date` is given 87 the most recent backup is used unless `date` is given
78 - date : date to restore from 88 - date : date to restore from
79 - delete : delete the backup after restoration 89 - delete : delete the backup after restoration
80 """ 90 """
81 if delete: 91
82 # delete the backup 92 # get the possible backups
93 # TODO
94
95 # restore the backup over ``profile``
96
97 if delete: # delete the backup
83 pass 98 pass
84 99
85 def merge(self, output, *profiles): 100 def merge(self, output, *profiles):
86 """merge a set of profiles (not trivial!)""" 101 """merge a set of profiles (not trivial!)"""
87 raise NotImplementedError 102 raise NotImplementedError
102 if not parser.has_option(section, 'name'): 117 if not parser.has_option(section, 'name'):
103 continue # not a profile 118 continue # not a profile
104 if parser.get(section, 'name') == profile: 119 if parser.get(section, 'name') == profile:
105 return dict(parser.items(section)) 120 return dict(parser.items(section))
106 raise ProfileNotFound('Profile %s not found in %s' % (profile, self.profiles)) 121 raise ProfileNotFound('Profile %s not found in %s' % (profile, self.profiles))
122
123 def hash(self):
124 """
125 generate a random hash for a new profile
126 """
127 # XXX right now this is completely fake
128 return 'FOO'