25
25
write = sys.stdout.write
30
usage = '%prog [options]'
36
self.parser = OptionParser(usage=self.usage,
38
'%s\n%s' % (__version__, __license__))
40
(self.options, self.args) = self.parser.parse_args(args)
43
def before_parse(self):
46
def after_parse(self):
30
usage = '%prog [options]'
36
self.parser = OptionParser(usage=self.usage,
38
'%s\n%s' % (__version__, __license__))
40
(self.options, self.args) = self.parser.parse_args(args)
43
def before_parse(self):
46
def after_parse(self):
49
49
class BackupCommand(Command):
51
help = 'Starts the backup process'
52
usage = '%prog backup [options] host'
54
def before_parse(self):
55
self.parser.add_option('-a', '--all',
57
action='store_true', dest='all',
58
#TRANSLATORS: command line option
59
help=('Backup all hosts'))
60
self.parser.add_option('-f', '--force',
62
action='store_true', dest='force',
63
#TRANSLATORS: command line option
64
help=('Force the backup to run'))
66
def after_parse(self):
67
main.backup(hosts=self.args,
69
force=self.options.force)
51
help = 'Starts the backup process'
52
usage = '%prog backup [options] host'
54
def before_parse(self):
55
self.parser.add_option('-a', '--all',
57
action='store_true', dest='all',
58
#TRANSLATORS: command line option
59
help=('Backup all hosts'))
60
self.parser.add_option('-f', '--force',
62
action='store_true', dest='force',
63
#TRANSLATORS: command line option
64
help=('Force the backup to run'))
66
def after_parse(self):
67
main.backup(hosts=self.args,
69
force=self.options.force)
70
70
__commands__.append(BackupCommand)
72
72
class DeployCommand(Command):
74
help = 'Deploys configuration files'
75
usage = '%prog deploy [options] host:path'
77
def before_parse(self):
78
self.parser.add_option('-a', '--all',
80
action='store_true', dest='all',
81
#TRANSLATORS: command line option
82
help=('Deploy files for all hosts'))
84
def after_parse(self):
85
main.deploy(self.args, all=self.options.all)
74
help = 'Deploys configuration files'
75
usage = '%prog deploy [options] host:path'
77
def before_parse(self):
78
self.parser.add_option('-a', '--all',
80
action='store_true', dest='all',
81
#TRANSLATORS: command line option
82
help=('Deploy files for all hosts'))
84
def after_parse(self):
85
main.deploy(self.args, all=self.options.all)
86
86
__commands__.append(DeployCommand)
88
88
class DisableCommand(Command):
90
help = 'Disables a host config file'
91
usage = '%prog disable [options] [host]'
93
def after_parse(self):
94
if len(self.args) > 0:
95
for host in self.args:
96
self.disable_host(host)
98
enabled = os.listdir(config.enabled_path)
99
available = os.listdir(config.available_path)
101
if len(available) == 0:
102
print 'No hosts exist!'
105
if len(enabled) == 0:
106
print 'No hosts enabled!'
109
print 'Which host would you like to disable?'
110
write('Your choices are: ')
112
if enabled.index(host) == 0:
116
write('\nHost name: ')
118
self.disable_host(host)
120
def disable_host(self, name):
121
available = os.path.join(config.available_path, name)
122
enabled = os.path.join(config.enabled_path, name)
123
if not os.path.exists(available):
124
print >> sys.stderr, 'This host does not exist!'
127
if not os.path.exists(enabled):
128
print 'This host is already disabled!'
132
print 'Host %s disabled' % name
90
help = 'Disables a host config file'
91
usage = '%prog disable [options] [host]'
93
def after_parse(self):
94
if len(self.args) > 0:
95
for host in self.args:
96
self.disable_host(host)
98
enabled = os.listdir(config.enabled_path)
99
available = os.listdir(config.available_path)
101
if len(available) == 0:
102
print 'No hosts exist!'
105
if len(enabled) == 0:
106
print 'No hosts enabled!'
109
print 'Which host would you like to disable?'
110
write('Your choices are: ')
112
if enabled.index(host) == 0:
116
write('\nHost name: ')
118
self.disable_host(host)
120
def disable_host(self, name):
121
available = os.path.join(config.available_path, name)
122
enabled = os.path.join(config.enabled_path, name)
123
if not os.path.exists(available):
124
print >> sys.stderr, 'This host does not exist!'
127
if not os.path.exists(enabled):
128
print 'This host is already disabled!'
132
print 'Host %s disabled' % name
133
133
__commands__.append(DisableCommand)
135
135
class EnableCommand(Command):
137
help = 'Enables a host config file'
138
usage = '%prog enable [options] [host]'
140
def after_parse(self):
141
if len(self.args) > 0:
142
for host in self.args:
143
self.enable_host(host)
145
enabled = os.listdir(config.enabled_path)
146
available = os.listdir(config.available_path)
148
if len(available) == 0:
149
print 'No hosts exist!'
153
for host in available:
154
if not host.startswith('.') and host not in enabled:
157
print 'Which host would you like to enable?'
158
write('Your choices are: ')
160
if hosts.index(host) == 0:
164
write('\nHost name: ')
166
self.enable_host(host)
168
def enable_host(self, name):
169
available = os.path.join(config.available_path, name)
170
enabled = os.path.join(config.enabled_path, name)
171
if not os.path.exists(available):
172
print >> sys.stderr, 'This host does not exist!'
175
if os.path.exists(enabled):
176
print 'This host is already enabled!'
179
os.symlink(available, enabled)
180
print 'Host %s enabled' % name
137
help = 'Enables a host config file'
138
usage = '%prog enable [options] [host]'
140
def after_parse(self):
141
if len(self.args) > 0:
142
for host in self.args:
143
self.enable_host(host)
145
enabled = os.listdir(config.enabled_path)
146
available = os.listdir(config.available_path)
148
if len(available) == 0:
149
print 'No hosts exist!'
153
for host in available:
154
if not host.startswith('.') and host not in enabled:
157
print 'Which host would you like to enable?'
158
write('Your choices are: ')
160
if hosts.index(host) == 0:
164
write('\nHost name: ')
166
self.enable_host(host)
168
def enable_host(self, name):
169
available = os.path.join(config.available_path, name)
170
enabled = os.path.join(config.enabled_path, name)
171
if not os.path.exists(available):
172
print >> sys.stderr, 'This host does not exist!'
175
if os.path.exists(enabled):
176
print 'This host is already enabled!'
179
os.symlink(available, enabled)
180
print 'Host %s enabled' % name
181
181
__commands__.append(EnableCommand)
183
183
class RestoreCommand(Command):
185
help = 'Restores a hosts files'
186
usage = '%prog restore [options] host:path ...'
188
def before_parse(self):
189
self.parser.add_option('-a', '--all',
191
action='store_true', dest='all',
192
#TRANSLATORS: command line option
193
help=('Restore all files for all hosts'))
195
self.parser.add_option('--all-files',
197
action='store_true', dest='all_files',
198
#TRANSLATORS: command line option
199
help=('Restore all files for the host'))
201
self.parser.add_option('-r', '--revision',
203
action='store', dest='revision',
204
#TRANSLATORS: command line option
205
help=('Snapshot version to use for restore'))
207
def after_parse(self):
208
main.restore(self.args, all=self.options.all)
185
help = 'Restores a hosts files'
186
usage = '%prog restore [options] host:path ...'
188
def before_parse(self):
189
self.parser.add_option('-a', '--all',
191
action='store_true', dest='all',
192
#TRANSLATORS: command line option
193
help=('Restore all files for all hosts'))
195
self.parser.add_option('--all-files',
197
action='store_true', dest='all_files',
198
#TRANSLATORS: command line option
199
help=('Restore all files for the host'))
201
self.parser.add_option('-r', '--revision',
203
action='store', dest='revision',
204
#TRANSLATORS: command line option
205
help=('Snapshot version to use for restore'))
207
def after_parse(self):
208
main.restore(self.args, all=self.options.all)
209
209
__commands__.append(RestoreCommand)
211
211
class SetupCommand(Command):
213
help = 'Prepares the host for being backed up'
214
usage = '%prog setup [options] host'
216
def before_parse(self):
217
self.parser.add_option('-a', '--all',
219
action='store_true', dest='all',
220
#TRANSLATORS: command line option
221
help=('Deploy key for all hosts'))
222
self.parser.add_option('-p', '--pass',
224
action='store', dest='password',
225
#TRANSLATORS: command line option
226
help=('Set the password to use'))
228
def after_parse(self):
229
main.setup(self.args, self.options)
213
help = 'Prepares the host for being backed up'
214
usage = '%prog setup [options] host'
216
def before_parse(self):
217
self.parser.add_option('-a', '--all',
219
action='store_true', dest='all',
220
#TRANSLATORS: command line option
221
help=('Deploy key for all hosts'))
222
self.parser.add_option('-p', '--pass',
224
action='store', dest='password',
225
#TRANSLATORS: command line option
226
help=('Set the password to use'))
228
def after_parse(self):
229
main.setup(self.args, self.options)
230
230
__commands__.append(SetupCommand)
232
232
class StatusCommand(Command):
234
help = 'Report some usage statistics'
235
usage = '%prog status [options]'
236
def after_parse(self):
237
main.status(self.args, self.options)
234
help = 'Report some usage statistics'
235
usage = '%prog status [options]'
236
def after_parse(self):
237
main.status(self.args, self.options)
238
238
__commands__.append(StatusCommand)
240
240
def get_commands():
241
__commands__.sort(key=attrgetter('name'))
241
__commands__.sort(key=attrgetter('name'))
244
244
def get_command(name):
245
if name == '[notset]':
246
raise Exception('invalid command name')
245
if name == '[notset]':
246
raise Exception('invalid command name')
248
for command in __commands__:
249
if command.name == name:
251
raise Exception('command not found')
b'\\ No newline at end of file'
248
for command in __commands__:
249
if command.name == name:
251
raise Exception('command not found')
b'\\ No newline at end of file'