Exemplo n.º 1
0
    def test_save_as(self):
        responses = indesign.save_as(os.path.join(IDMLFILES_DIR, "4-pages.idml"),
                                     [{"fmt": "indd"}],
                                     "http://url-to-indesign-server:8080",
                                     CLIENT_WORKDIR, SERVER_WORKDIR,
                                     indesign_server_path_style="posix")

        self.assertTrue(self.runscript_mock.called)
        self.assertEqual(responses, ['save_as.jsx, 4-pagesTMP.indd, {}'])

        responses = indesign.save_as(os.path.join(IDMLFILES_DIR, "4-pages.idml"),
                                     [{"fmt": "pdf",
                                       "params": {
                                           "colorSpace": "CMYK",
                                           "standartsCompliance": "1A2003",
                                       }},
                                      {"fmt": "jpeg"},
                                      {"fmt": "zip"}],
                                     "http://url-to-indesign-server:8080",
                                     CLIENT_WORKDIR, SERVER_WORKDIR,
                                     indesign_server_path_style="posix")
        self.assertTrue(self.runscript_mock.called)
        self.assertEqual(responses[:2], [
            "export.jsx, 4-pagesTMP.pdf, {'colorSpace': 'CMYK', 'standartsCompliance': '1A2003', 'format': 'pdf'}",
            "export.jsx, 4-pagesTMP.jpeg, {'format': 'jpeg'}"
        ])
        zip_buf = StringIO()
        zip_buf.write(responses[2])
        self.assertTrue(zipfile.is_zipfile(zip_buf))
Exemplo n.º 2
0
    def test_save_as(self):
        responses = indesign.save_as(os.path.join(IDMLFILES_DIR,
                                                  "4-pages.idml"),
                                     [{
                                         "fmt": "indd"
                                     }],
                                     "http://url-to-indesign-server:8080",
                                     CLIENT_WORKDIR,
                                     SERVER_WORKDIR,
                                     indesign_server_path_style="posix")

        self.assertTrue(self.runscript_mock.called)
        self.assertEqual(len(responses), 1)
        self.assertEqual(json.loads(responses[0].decode('utf-8')), {
            "script": "save_as.jsx",
            "extra_params": {},
            "dst": "4-pagesTMP.indd"
        })

        responses = indesign.save_as(os.path.join(IDMLFILES_DIR,
                                                  "4-pages.idml"),
                                     [{
                                         "fmt": "pdf",
                                         "params": {
                                             "colorSpace": "CMYK",
                                             "standartsCompliance": "1A2003",
                                         }
                                     }, {
                                         "fmt": "jpeg"
                                     }, {
                                         "fmt": "zip"
                                     }],
                                     "http://url-to-indesign-server:8080",
                                     CLIENT_WORKDIR,
                                     SERVER_WORKDIR,
                                     indesign_server_path_style="posix")
        self.assertTrue(self.runscript_mock.called)
        self.assertEqual(len(responses), 3)
        self.assertEqual(
            json.loads(responses[0].decode('utf-8')), {
                "extra_params": {
                    "colorSpace": "CMYK",
                    "format": "pdf",
                    "standartsCompliance": "1A2003"
                },
                "script": "export.jsx",
                "dst": "4-pagesTMP.pdf"
            })
        self.assertEqual(
            json.loads(responses[1].decode('utf-8')), {
                "dst": "4-pagesTMP.jpeg",
                "extra_params": {
                    "format": "jpeg"
                },
                "script": "export.jsx"
            })
        zip_buf = BytesIO()
        zip_buf.write(responses[2])
        self.assertTrue(zipfile.is_zipfile(zip_buf))
 def execute(self):
     super(InDesignSaveAsCommand, self).execute()
     destinations = self.args.destinations.split(";")
     formats = map(self.parse_destination_arg, destinations)
     responses = indesign.save_as(self.args.source, formats, self.args.url, self.args.client_workdir,
                                  self.args.server_workdir, self.args.server_path_style,
                                  not self.args.no_clean_workdir, self.ftp_params)
     for response, destination in zip(responses, destinations):
         self.save_as(response, destination)
Exemplo n.º 4
0
    def test_save_as(self):
        responses = indesign.save_as(os.path.join(IDMLFILES_DIR, "4-pages.idml"),
                                     [{"fmt": "indd"}],
                                     "http://url-to-indesign-server:8080",
                                     CLIENT_WORKDIR, SERVER_WORKDIR,
                                     indesign_server_path_style="posix")

        self.assertTrue(self.runscript_mock.called)
        self.assertEqual(len(responses), 1)
        self.assertEqual(json.loads(responses[0].decode('utf-8')), {
            "script": "save_as.jsx",
            "extra_params": {},
            "dst": "4-pagesTMP.indd"
        })

        responses = indesign.save_as(os.path.join(IDMLFILES_DIR, "4-pages.idml"),
                                     [{"fmt": "pdf",
                                       "params": {
                                           "colorSpace": "CMYK",
                                           "standartsCompliance": "1A2003",
                                       }},
                                      {"fmt": "jpeg"},
                                      {"fmt": "zip"}],
                                     "http://url-to-indesign-server:8080",
                                     CLIENT_WORKDIR, SERVER_WORKDIR,
                                     indesign_server_path_style="posix")
        self.assertTrue(self.runscript_mock.called)
        self.assertEqual(len(responses), 3)
        self.assertEqual(json.loads(responses[0].decode('utf-8')),
                         {"extra_params": {"colorSpace": "CMYK", "format": "pdf", "standartsCompliance": "1A2003"},
                          "script": "export.jsx", "dst": "4-pagesTMP.pdf"})
        self.assertEqual(json.loads(responses[1].decode('utf-8')),
                         {"dst": "4-pagesTMP.jpeg", "extra_params": {"format": "jpeg"}, "script": "export.jsx"})
        zip_buf = BytesIO()
        zip_buf.write(responses[2])
        self.assertTrue(zipfile.is_zipfile(zip_buf))
def main():
    usage = (
        "usage: %prog /path/to/source-file"
        " \"/path/to/destination-fileA|colorsBars=1,colorSpace=cRGB;/path/to/destination-fileB\""
    )
    version = "%prog 0.1"
    parser = OptionParser(usage=usage, version=version, description=__doc__)
    parser.add_option("-u",
                      "--url",
                      default="http://127.0.0.1:8082",
                      help=u"InDesign Server url.")
    parser.add_option(
        "--client-workdir",
        dest="client_workdir",
        default="/tmp",
        help=
        ("Directory where temporary files are written, as seen by the SOAP client."
         " This could be a FTP path."))
    parser.add_option(
        "--server-workdir",
        dest="server_workdir",
        default="/tmp",
        help=
        "Directory where temporary files are written, as seen by the InDesign server."
    )
    parser.add_option(
        "--server-path-style",
        dest="server_path_style",
        default="posix",
        help="[posix|windows] according to the OS running InDesign Server.")
    parser.add_option("--no-clean-workdir",
                      dest="no_clean_workdir",
                      action="store_true",
                      default=False,
                      help="Do not clean the working directory when finished.")
    parser.add_option(
        "--ftp-url",
        dest="ftp_url",
        default="",
        help=("The FTP server for the workir."
              " It must be on the filesystem of the InDesign Server."))
    parser.add_option("--ftp-user", dest="ftp_user", default="")
    parser.add_option("--ftp-password", dest="ftp_password", default="")
    parser.add_option("--ftp-passive",
                      dest="ftp_passive",
                      action="store_true",
                      default=False)
    parser.add_option("-v",
                      "--verbose",
                      action="store_true",
                      dest="verbose",
                      default=False)

    # Fix encoding first.
    encoding = locale.getpreferredencoding()
    for i, a in enumerate(sys.argv):
        sys.argv[i] = unicode(a.decode(encoding))

    (options, args) = parser.parse_args()

    if len(args) != 2:
        parser.error(
            "You must provide the source file and the destination file paths as parameters"
        )
    else:
        src, destinations = args[0], args[1].split(";")

        def parse_destination_arg(arg):
            try:
                dest, params = arg.split("|")
            except ValueError:
                dest = arg
                params = {}
            else:
                params = dict(
                    [keyval.split("=") for keyval in params.split(",")])
            return {
                "fmt": os.path.splitext(dest)[1].replace(".", ""),
                "params": params
            }

        formats = map(parse_destination_arg, destinations)

        ftp_params = None
        if options.ftp_url:
            ftp_params = {
                'auth':
                (options.ftp_url, options.ftp_user, options.ftp_password),
                'passive': options.ftp_passive,
            }

        if options.verbose:
            logging.basicConfig(level=logging.INFO)
            logging.getLogger('suds.client').setLevel(logging.DEBUG)

        responses = indesign.save_as(src, formats, options.url,
                                     options.client_workdir,
                                     options.server_workdir,
                                     options.server_path_style,
                                     not options.no_clean_workdir, ftp_params)

        def _save_as(response, dst):
            with open(dst.split("|")[0], mode="w+") as fobj:
                fobj.write(response)

        map(_save_as, responses, destinations)
Exemplo n.º 6
0
def main():
    usage = ("usage: %prog /path/to/source-file"
             " \"/path/to/destination-fileA|colorsBars=1,colorSpace=cRGB;/path/to/destination-fileB\"")
    version = "%prog 0.1"
    parser = OptionParser(usage=usage, version=version, description=__doc__)
    parser.add_option("-u", "--url", default="http://127.0.0.1:8082",
                      help=u"InDesign Server url.")
    parser.add_option("--client-workdir", dest="client_workdir", default="/tmp",
                      help=("Directory where temporary files are written, as seen by the SOAP client."
                            " This could be a FTP path."))
    parser.add_option("--server-workdir", dest="server_workdir", default="/tmp",
                      help="Directory where temporary files are written, as seen by the InDesign server.")
    parser.add_option("--server-path-style", dest="server_path_style", default="posix",
                      help="[posix|windows] according to the OS running InDesign Server.")
    parser.add_option("--no-clean-workdir", dest="no_clean_workdir", action="store_true", default=False,
                      help="Do not clean the working directory when finished.")
    parser.add_option("--ftp-url", dest="ftp_url", default="",
                      help=("The FTP server for the workir."
                            " It must be on the filesystem of the InDesign Server."))
    parser.add_option("--ftp-user", dest="ftp_user", default="")
    parser.add_option("--ftp-password", dest="ftp_password", default="")
    parser.add_option("--ftp-passive", dest="ftp_passive", action="store_true", default=False)
    parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
                      default=False)

    # Fix encoding first.
    encoding = locale.getpreferredencoding()
    for i, a in enumerate(sys.argv):
        sys.argv[i] = unicode(a.decode(encoding))

    (options, args) = parser.parse_args()

    if len(args) != 2:
        parser.error("You must provide the source file and the destination file paths as parameters")
    else:
        src, destinations = args[0], args[1].split(";")

        def parse_destination_arg(arg):
            try:
                dest, params = arg.split("|")
            except ValueError:
                dest = arg
                params = {}
            else:
                params = dict([keyval.split("=") for keyval in params.split(",")])
            return {"fmt": os.path.splitext(dest)[1].replace(".", ""),
                    "params": params}

        formats = map(parse_destination_arg, destinations)

        ftp_params = None
        if options.ftp_url:
            ftp_params = {
                'auth': (options.ftp_url, options.ftp_user, options.ftp_password),
                'passive': options.ftp_passive,
            }

        if options.verbose:
            logging.basicConfig(level=logging.INFO)
            logging.getLogger('suds.client').setLevel(logging.DEBUG)

        responses = indesign.save_as(src, formats, options.url, options.client_workdir,
                                     options.server_workdir, options.server_path_style,
                                     not options.no_clean_workdir, ftp_params)

        def _save_as(response, dst):
            with open(dst.split("|")[0], mode="w+") as fobj:
                fobj.write(response)

        map(_save_as, responses, destinations)