def save_mapping_file(self, fpath): fpath = expand_path(fpath) try: f = open(fpath, 'w') f.write(self.ids.cmd_box.recorded) f.close() except IOError as err: toast(str(err), width='700dp')
def save_output(self, path): path = expand_path(path) try: # TODO: this is an error-prone step, are we catching all # reasonable exceptions? save_dict_as_csv(self.out_dict, path) except (IOError, OSError, IndexError) as e: toast(str(e), width='650dp') else: toast('merged output saved')
def apply_mapping_file(self, fpath): fpath = expand_path(fpath) try: with open(fpath, 'r') as f: for line in f.read().split('\n'): if not line: continue self.ids.cmd_box.text = line self.ids.cmd_box.dispatch('on_text_validate') except IOError as err: toast(str(err), width='700dp')
#!/usr/bin/env python from __future__ import print_function import os import logging from ToastItApi import ToastItApi from toaster import toast logging.basicConfig(level=logging.INFO) if __name__ == "__main__": logging.info('Test toasting') fullImage, thumbnail = toast("http://www.apple.com") logging.info('Done')
def err(m='unknown command or invalid syntax'): toast(m, width='275dp') Clock.schedule_once(sel_and_focus, .1)
def do_command(self, cmd): if len(cmd) < 1: toast('empty command') return def sel_and_focus(*ar): self.root.ids.cmd_box.focus = True self.root.ids.cmd_box.select_all() def err(m='unknown command or invalid syntax'): toast(m, width='275dp') Clock.schedule_once(sel_and_focus, .1) if cmd[0] == 'h': # hook spl = cmd.split(' ') if len(spl) < 4: err() return src = spl[1] dest = spl[3] if len(src) < 3 or src[1] != '.': err() return fidx = int(src[0]) sname = src[2:] src = self.srcs[fidx].find_src(sname) if src is None: err(m="input {} has no field {}".format(fidx, sname)) return src.set_dest(dest) elif cmd[0] == 'u': # unhook spl = cmd.split(' ') if len(spl) < 2: err() return dest = spl[1] if dest not in self.root.ids['dest_fields'].dests: err() return self.root.ids['dest_fields'].set_src(dest, None) else: err() return if self.root.ids.record_cmds.active: self.root.ids.cmd_box.recorded += self.root.ids.cmd_box.text + '\n' # Reset the text on a successful command. self.root.ids.cmd_box.text = '' Clock.schedule_once( lambda *ar: \ setattr(self.root.ids.cmd_box, 'focus', True), .1)
return "https://s3-ap-southeast-2.amazonaws.com/%s/%s" % (bucketName,k.key) if __name__ == "__main__": toastItApi = ToastItApi(apiLocation); while True: logging.info('Checking for new requests') items = toastItApi.GetAllNewForGenerator(generatorName) logging.info('Found %s new requests',len(items)) for item in items: try: toastItApi.StartProcessing(item) fullImage, thumbnail = toast(item.resourceURL) logging.info("Finished generating %s",item.id) item.resultURL=uploadItemToS3(fullImage,item.id) item.thumbnailURL=uploadItemToS3(thumbnail,"%s-thumbnail"%item.id) toastItApi.CompleteProcessing(item) logging.info('Generated result for %s. Found at %s',item.id,item.resultURL) except Exception as e: logging.exception(e) toastItApi.FailProcessing(item) logging.info("Sleeping for 10...") time.sleep(10)