Mercurial > repos > guerler > springsuite
comparison planemo/lib/python3.7/site-packages/boto/services/sonofmmm.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 # Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/ | |
2 # | |
3 # Permission is hereby granted, free of charge, to any person obtaining a | |
4 # copy of this software and associated documentation files (the | |
5 # "Software"), to deal in the Software without restriction, including | |
6 # without limitation the rights to use, copy, modify, merge, publish, dis- | |
7 # tribute, sublicense, and/or sell copies of the Software, and to permit | |
8 # persons to whom the Software is furnished to do so, subject to the fol- | |
9 # lowing conditions: | |
10 # | |
11 # The above copyright notice and this permission notice shall be included | |
12 # in all copies or substantial portions of the Software. | |
13 # | |
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- | |
16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | |
17 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |
18 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | |
20 # IN THE SOFTWARE. | |
21 | |
22 import boto | |
23 from boto.services.service import Service | |
24 from boto.services.message import ServiceMessage | |
25 import os | |
26 import mimetypes | |
27 | |
28 class SonOfMMM(Service): | |
29 | |
30 def __init__(self, config_file=None): | |
31 super(SonOfMMM, self).__init__(config_file) | |
32 self.log_file = '%s.log' % self.instance_id | |
33 self.log_path = os.path.join(self.working_dir, self.log_file) | |
34 boto.set_file_logger(self.name, self.log_path) | |
35 if self.sd.has_option('ffmpeg_args'): | |
36 self.command = '/usr/local/bin/ffmpeg ' + self.sd.get('ffmpeg_args') | |
37 else: | |
38 self.command = '/usr/local/bin/ffmpeg -y -i %s %s' | |
39 self.output_mimetype = self.sd.get('output_mimetype') | |
40 if self.sd.has_option('output_ext'): | |
41 self.output_ext = self.sd.get('output_ext') | |
42 else: | |
43 self.output_ext = mimetypes.guess_extension(self.output_mimetype) | |
44 self.output_bucket = self.sd.get_obj('output_bucket') | |
45 self.input_bucket = self.sd.get_obj('input_bucket') | |
46 # check to see if there are any messages queue | |
47 # if not, create messages for all files in input_bucket | |
48 m = self.input_queue.read(1) | |
49 if not m: | |
50 self.queue_files() | |
51 | |
52 def queue_files(self): | |
53 boto.log.info('Queueing files from %s' % self.input_bucket.name) | |
54 for key in self.input_bucket: | |
55 boto.log.info('Queueing %s' % key.name) | |
56 m = ServiceMessage() | |
57 if self.output_bucket: | |
58 d = {'OutputBucket' : self.output_bucket.name} | |
59 else: | |
60 d = None | |
61 m.for_key(key, d) | |
62 self.input_queue.write(m) | |
63 | |
64 def process_file(self, in_file_name, msg): | |
65 base, ext = os.path.splitext(in_file_name) | |
66 out_file_name = os.path.join(self.working_dir, | |
67 base+self.output_ext) | |
68 command = self.command % (in_file_name, out_file_name) | |
69 boto.log.info('running:\n%s' % command) | |
70 status = self.run(command) | |
71 if status == 0: | |
72 return [(out_file_name, self.output_mimetype)] | |
73 else: | |
74 return [] | |
75 | |
76 def shutdown(self): | |
77 if os.path.isfile(self.log_path): | |
78 if self.output_bucket: | |
79 key = self.output_bucket.new_key(self.log_file) | |
80 key.set_contents_from_filename(self.log_path) | |
81 super(SonOfMMM, self).shutdown() |