예제 #1
0
 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)
예제 #2
0
 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)
예제 #3
0
 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)
예제 #4
0
 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)
예제 #5
0
    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)
예제 #6
0
파일: ftp.py 프로젝트: m0g/superdesk-core
    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)