Mercurial > repos > guerler > springsuite
comparison planemo/lib/python3.7/site-packages/boto/pyami/scriptbase.py @ 0:d30785e31577 draft
"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author | guerler |
---|---|
date | Fri, 31 Jul 2020 00:18:57 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d30785e31577 |
---|---|
1 import os | |
2 import sys | |
3 from boto.utils import ShellCommand, get_ts | |
4 import boto | |
5 import boto.utils | |
6 | |
7 class ScriptBase(object): | |
8 | |
9 def __init__(self, config_file=None): | |
10 self.instance_id = boto.config.get('Instance', 'instance-id', 'default') | |
11 self.name = self.__class__.__name__ | |
12 self.ts = get_ts() | |
13 if config_file: | |
14 boto.config.read(config_file) | |
15 | |
16 def notify(self, subject, body=''): | |
17 boto.utils.notify(subject, body) | |
18 | |
19 def mkdir(self, path): | |
20 if not os.path.isdir(path): | |
21 try: | |
22 os.mkdir(path) | |
23 except: | |
24 boto.log.error('Error creating directory: %s' % path) | |
25 | |
26 def umount(self, path): | |
27 if os.path.ismount(path): | |
28 self.run('umount %s' % path) | |
29 | |
30 def run(self, command, notify=True, exit_on_error=False, cwd=None): | |
31 self.last_command = ShellCommand(command, cwd=cwd) | |
32 if self.last_command.status != 0: | |
33 boto.log.error('Error running command: "%s". Output: "%s"' % (command, self.last_command.output)) | |
34 if notify: | |
35 self.notify('Error encountered', | |
36 'Error running the following command:\n\t%s\n\nCommand output:\n\t%s' % \ | |
37 (command, self.last_command.output)) | |
38 if exit_on_error: | |
39 sys.exit(-1) | |
40 return self.last_command.status | |
41 | |
42 def main(self): | |
43 pass |