comparison env/lib/python3.9/site-packages/boto/pyami/scriptbase.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
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