Skip to content

Instantly share code, notes, and snippets.

@birkin
Last active December 18, 2015 10:19
Show Gist options
  • Save birkin/5767344 to your computer and use it in GitHub Desktop.
Save birkin/5767344 to your computer and use it in GitHub Desktop.
Shows how to call the kakadu library with envoy; handles paths with spaces and a source-path with apostrophes.
# -*- coding: utf-8 -*-
""" Shows how to call the kakadu library with envoy.
In particular, shows how to handle paths containing spaces.
Updated to show how to handle apostrophe in source path.
- kakadu is a jpeg2000 library
- envoy is a wrapper around the subprocess module
- kakadu: http://en.wikipedia.org/wiki/Kakadu_(software)
- envoy: https://github.com/kennethreitz/envoy
"""
import envoy
KAKADU_COMMAND_PATH = u'/opt/local/djatoka/bin/Linux-x86-32/kdu_compress' # example
k_source_file_path = u"'%s'" % u'/the/source/file path'.replace( u' ', u'\ ' )
k_source_file_path2 = k_source_file_path.replace( u"'", u"\\'" )
k_destination_file_path = u"'%s'" % u'/the/destination/file path'.replace( u' ', u'\ ' )
cmd = u'%s -i %s -o %s Creversible=yes -rate -,1,0.5,0.25 Clevels=5' % (
KAKADU_COMMAND_PATH,
k_source_file_path2,
k_destination_file_path
)
r = envoy.run( cmd.encode(u'utf-8', u'replace') ) # envoy requires a non-unicode string
# print r.std_out
# print r.std_err
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment