diff env/lib/python3.7/site-packages/boto/pyami/scriptbase.py @ 2:6af9afd405e9 draft

"planemo upload commit 0a63dd5f4d38a1f6944587f52a8cd79874177fc1"
author shellac
date Thu, 14 May 2020 14:56:58 -0400
parents 26e78fe6e8c4
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/env/lib/python3.7/site-packages/boto/pyami/scriptbase.py	Thu May 14 14:56:58 2020 -0400
@@ -0,0 +1,43 @@
+import os
+import sys
+from boto.utils import ShellCommand, get_ts
+import boto
+import boto.utils
+
+class ScriptBase(object):
+
+    def __init__(self, config_file=None):
+        self.instance_id = boto.config.get('Instance', 'instance-id', 'default')
+        self.name = self.__class__.__name__
+        self.ts = get_ts()
+        if config_file:
+            boto.config.read(config_file)
+
+    def notify(self, subject, body=''):
+        boto.utils.notify(subject, body)
+
+    def mkdir(self, path):
+        if not os.path.isdir(path):
+            try:
+                os.mkdir(path)
+            except:
+                boto.log.error('Error creating directory: %s' % path)
+
+    def umount(self, path):
+        if os.path.ismount(path):
+            self.run('umount %s' % path)
+
+    def run(self, command, notify=True, exit_on_error=False, cwd=None):
+        self.last_command = ShellCommand(command, cwd=cwd)
+        if self.last_command.status != 0:
+            boto.log.error('Error running command: "%s". Output: "%s"' % (command, self.last_command.output))
+            if notify:
+                self.notify('Error encountered',
+                            'Error running the following command:\n\t%s\n\nCommand output:\n\t%s' % \
+                            (command, self.last_command.output))
+            if exit_on_error:
+                sys.exit(-1)
+        return self.last_command.status
+
+    def main(self):
+        pass