def save_as(src_path, formats_options, indesign_server_url, indesign_client_workdir, indesign_server_workdir, indesign_server_path_style="posix", clean_workdir=True, ftp_params=None, logger=None, logger_extra=None): """SOAP call to an InDesign Server to convert an InDesign file. """ if not logger: logger = logging.getLogger('simpleidml.indesign') logger.addHandler(logging.NullHandler()) logger_extra = logger_extra or {} src_name = os.path.basename(src_path) src_client_copy_filename = os.path.join(indesign_client_workdir, src_name) ftp.copy(src_path, src_client_copy_filename, ftp_params) responses = [ _save_as(src_name, format_options, indesign_server_url, indesign_client_workdir, indesign_server_workdir, indesign_server_path_style, ftp_params, clean_workdir, logger, logger_extra) for format_options in formats_options ] if clean_workdir: ftp.unlink(src_client_copy_filename, ftp_params) return responses
def runscript(self): self.logger.debug('Calling SOAP "RunScript" service (params: %s)' % self.params, extra=self.logger_extra) try: response = self.client.service.RunScript(self.params) except SAXParseException as e: response = None self.logger.error('SAXParseException: %s' % e.getMessage(), extra=self.logger_extra) else: if response.errorNumber: self.logger.error( "SOAP response: %s\nSOAP RunScript params: %s" % (response, self.params), extra=self.logger_extra) raise exceptions.InDesignSoapException(self.params, response) self.logger.debug('"RunScript" successful! Response: %s' % response, extra=self.logger_extra) finally: if self.clean_workdir: ftp.unlink(self.javascript_client_copy_filename, self.ftp_params) response = self.runscript_extra(response) return response
def runscript_extra(self, response): response = super(SaveAsBase, self).runscript_extra(response) if response: response = ftp.read(self.response_client_copy_filename, self.ftp_params) if self.clean_workdir: ftp.unlink(self.response_client_copy_filename, self.ftp_params) return response
def runscript_extra(self, response): response = super(SaveAsBase, self).runscript_extra(response) if response: response = ftp.read(self.response_client_copy_filename, self.ftp_params) if self.clean_workdir: ftp.unlink(self.response_client_copy_filename, self.ftp_params) return response
def save_as(src_filename, dst_formats_params, indesign_server_url, indesign_client_workdir, indesign_server_workdir, indesign_server_path_style="posix", clean_workdir=True, ftp_params=None, logger=None, logger_extra=None): """SOAP call to an InDesign Server to make one or more conversions. """ if not logger: logger = logging.getLogger('simpleidml.indesign') logger.addHandler(logging.NullHandler()) logger_extra = logger_extra or {} def _save_as(dst_format_params): """ o *_client_copy_filename : path/to/file as seen by the SOAP client. o *_server_copy_filename : localized/path/to/file as seen by the InDesign Server. """ dst_format = dst_format_params["fmt"] js_params = dst_format_params.get("params", {}) if dst_format in ('idml', 'pdf', 'jpeg'): klass = Export elif dst_format == 'zip': klass = PackageForPrint else: klass = SaveAs script = klass(src_filename, dst_format, js_params, indesign_server_url, indesign_client_workdir, indesign_server_workdir, indesign_server_path_style, ftp_params, clean_workdir, logger, logger_extra) return script.execute() src_basename = os.path.basename(src_filename) src_client_copy_filename = os.path.join(indesign_client_workdir, src_basename) ftp.copy(src_filename, src_client_copy_filename, ftp_params) cl = Client("%s/service?wsdl" % indesign_server_url) cl.set_options(location=indesign_server_url, timeout=90) responses = [_save_as(fmt) for fmt in dst_formats_params] if clean_workdir: ftp.unlink(src_client_copy_filename, ftp_params) return responses
def save_as(src_filename, dst_formats_params, indesign_server_url, indesign_client_workdir, indesign_server_workdir, indesign_server_path_style="posix", clean_workdir=True, ftp_params=None, logger=None, logger_extra=None): """SOAP call to an InDesign Server to make one or more conversions. """ if not logger: logger = logging.getLogger('simpleidml.indesign') logger.addHandler(logging.NullHandler()) logger_extra = logger_extra or {} def _save_as(dst_format_params): """ o *_client_copy_filename : path/to/file as seen by the SOAP client. o *_server_copy_filename : localized/path/to/file as seen by the InDesign Server. """ dst_format = dst_format_params["fmt"] js_params = dst_format_params.get("params", {}) if dst_format in ('idml', 'pdf', 'jpeg'): klass = Export elif dst_format == 'zip': klass = PackageForPrint else: klass = SaveAs script = klass(src_filename, dst_format, js_params, indesign_server_url, indesign_client_workdir, indesign_server_workdir, indesign_server_path_style, ftp_params, clean_workdir, logger, logger_extra) return script.execute() src_basename = os.path.basename(src_filename) src_client_copy_filename = os.path.join(indesign_client_workdir, src_basename) ftp.copy(src_filename, src_client_copy_filename, ftp_params) cl = Client("%s/service?wsdl" % indesign_server_url) cl.set_options(location=indesign_server_url, timeout=90) responses = [_save_as(fmt) for fmt in dst_formats_params] if clean_workdir: ftp.unlink(src_client_copy_filename, ftp_params) return responses
def runscript(self): self.logger.debug('Calling SOAP "RunScript" service (params: %s)' % self.params, extra=self.logger_extra) try: response = self.client.service.RunScript(self.params) except SAXParseException as e: response = None self.logger.error('SAXParseException: %s' % e.getMessage(), extra=self.logger_extra) else: if response.errorNumber: self.logger.error("SOAP response: %s\nSOAP RunScript params: %s" % (response, self.params), extra=self.logger_extra) raise exceptions.InDesignSoapException(self.params, response) self.logger.debug('"RunScript" successful! Response: %s' % response, extra=self.logger_extra) finally: if self.clean_workdir: ftp.unlink(self.javascript_client_copy_filename, self.ftp_params) response = self.runscript_extra(response) return response