def _transmit(self, queue_item, subscriber): try: config = queue_item['destination']['config'] file_path = config['file_path'] if not path.isabs(file_path): file_path = "/" + file_path with open(path.join(file_path, PublishService.get_filename(queue_item)), 'wb') as f: f.write(queue_item['encoded_item']) except Exception as ex: raise PublishFileError.fileSaveError(ex, config)
def get_filename(cls, queue_item): orig = PublishService.get_filename(queue_item) name, ext = os.path.splitext(orig) try: item = etree.fromstring(queue_item['formatted_item'].encode('utf-8')) filename = item.find('ContentItem').find('FileName').text return '{}{}'.format(filename, ext) except (etree.XMLSyntaxError, AttributeError): pass return '{}{}'.format('-'.join(name.split('-')[:-2]), ext)
def _transmit(self, queue_item, subscriber): try: config = queue_item['destination']['config'] file_path = config['file_path'] if not path.isabs(file_path): file_path = "/" + file_path with open(path.join(file_path, PublishService.get_filename(queue_item)), 'wb') as f: f.write(queue_item['encoded_item']) except Exception as ex: raise PublishFileError.fileSaveError(ex, config)
def get_filename(cls, queue_item): orig = PublishService.get_filename(queue_item) name, ext = os.path.splitext(orig) try: item = etree.fromstring( queue_item["formatted_item"].encode("utf-8")) filename = item.find("ContentItem").find("FileName").text return "{}{}".format(filename, ext) except (etree.XMLSyntaxError, AttributeError): pass return "{}{}".format("-".join(name.split("-")[:-2]), ext)
def _transmit(self, queue_item, subscriber): config = queue_item.get('destination', {}).get('config', {}) try: with ftp_connect(config) as ftp: filename = PublishService.get_filename(queue_item) b = BytesIO(queue_item['encoded_item']) ftp.storbinary("STOR " + filename, b) except PublishFtpError: raise except Exception as ex: raise PublishFtpError.ftpError(ex, config)
def _transmit(self, queue_item, subscriber): config = queue_item.get('destination', {}).get('config', {}) try: with ftp_connect(config) as ftp: filename = PublishService.get_filename(queue_item) b = BytesIO(queue_item['encoded_item']) ftp.storbinary("STOR " + filename, b) except PublishFtpError: raise except Exception as ex: raise PublishFtpError.ftpError(ex, config)