@use_dedicated_working_directory
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 {}

    server_path_mod = os.path
    if indesign_server_path_style == "windows":
        server_path_mod = ntpath

    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", {})

        src_rootname = os.path.splitext(src_basename)[0]
        dst_basename = "%sTMP.%s" % (src_rootname, dst_format)
        javascript_basename = JS_SAVE_AS_SCRIPT
        if dst_format in ('idml', 'pdf', 'jpeg'):
            javascript_basename = JS_EXPORT_SCRIPT
        elif dst_format == 'zip':
            javascript_basename = JS_PACKAGE_SCRIPT
            dst_basename = src_rootname  # a directory.

        javascript_master_filename = os.path.join(SCRIPTS_DIR, javascript_basename)
        javascript_client_copy_filename = os.path.join(indesign_client_workdir, javascript_basename)
        response_client_copy_filename = os.path.join(indesign_client_workdir, dst_basename)

        javascript_server_copy_filename = server_path_mod.join(indesign_server_workdir, javascript_basename)
        response_server_copy_filename = server_path_mod.join(indesign_server_workdir, dst_basename)

        _copy(javascript_master_filename, javascript_client_copy_filename, ftp_params, src_open_mode="r")

        params = cl.factory.create("ns0:RunScriptParameters")
        params.scriptLanguage = 'javascript'
        params.scriptFile = javascript_server_copy_filename

        src = cl.factory.create("ns0:IDSP-ScriptArg")
        src.name = "source"
        src.value = src_server_copy_filename

        dst = cl.factory.create("ns0:IDSP-ScriptArg")
        dst.name = "destination"
        dst.value = response_server_copy_filename

        params.scriptArgs = [src, dst]

        # Extra parameters
        extra_params = []
        for k, v in js_params.items():
            param = cl.factory.create("ns0:IDSP-ScriptArg")
            param.name = k
            param.value = v
            extra_params.append(param)
        params.scriptArgs.extend(extra_params)

        if dst_format in ('idml', 'pdf', 'jpeg'):
            fmt = cl.factory.create("ns0:IDSP-ScriptArg")
            fmt.name = "format"
            fmt.value = dst_format
            params.scriptArgs.append(fmt)

        logger.debug(params % 'Calling SOAP "RunScript" service... (params: %s)', extra=logger_extra)
        response = cl.service.RunScript(params)
        logger.debug('"RunScript" successful! Response: %s' % response, extra=logger_extra)

        if dst_format == 'zip':
            # Zip the tree generated in response_client_copy_filename and
            # make that variable point on that zip file.
            zip_filename = "%s.zip" % response_client_copy_filename
            _zip_dir(response_client_copy_filename, zip_filename, ftp_params)
            response_client_copy_filename = zip_filename

        logger.debug('Reading response...')
        response = _read(response_client_copy_filename, ftp_params)
        logger.debug('Reading response done!')

        if clean_workdir:
            logger.debug('Cleaning workir...')
            _unlink(response_client_copy_filename, ftp_params)
            _unlink(javascript_client_copy_filename, ftp_params)
            logger.debug('Cleaning workir done!')

        return response

    ##

    src_basename = os.path.basename(src_filename)
    src_client_copy_filename = os.path.join(indesign_client_workdir, src_basename)
    src_server_copy_filename = server_path_mod.join(indesign_server_workdir, src_basename)
    _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 = map(lambda fmt: _save_as(fmt), dst_formats_params)

    if clean_workdir:
        _unlink(src_client_copy_filename, ftp_params)

    return responses
dataset/ETHPy150Open Starou/SimpleIDML/src/simple_idml/indesign/indesign.py/save_as/swapped operands of `%`