# Path: jubakit/_stdio.py
# class _StandardIO(object):
#   def get(cls):
#   def set(cls, stdin=None, stdout=None, stderr=None):
#   def print(cls, *args, **kwargs):
#   def printe(cls, *args, **kwargs):
#   def devnull(cls):
# 
# Path: jubakit/_process.py
# class JubaProcess(object):
#   @classmethod
#   def get_process(cls, cmdline, env=None, *args, **kwargs):
#     """
#     Returns subprocess.Popen instance.
#     """
#     envvars = env if env else dict(os.environ)
#     if platform.system() == 'Darwin' and 'DYLD_FALLBACK_LIBRARY_PATH' not in envvars:
#       """
#       Due to homebrew-jubatus issue #15, when using Homebrew with locations other than
#       the standard installation path (/usr/local), Jubatus processes built on OS X cannot
#       be run without DYLD_FALLBACK_LIBRARY_PATH.  However, on El Capitan or later,
#       DYLD_FALLBACK_LIBRARY_PATH are not propagated from parent process.  We workaround
#       the problem by automatically estimating DYLD_FALLBACK_LIBRARY_PATH based on PATH.
#       """
#       cmdpath = distutils.spawn.find_executable(cmdline[0])
#       if cmdpath is None:
#         raise RuntimeError('{0} command not found; confirm that PATH is properly set'.format(cmdline[0]))
#       libpath = os.sep.join(cmdpath.split(os.sep)[:-2] + ['lib'])
#       if os.path.isfile(os.sep.join([libpath, 'libjubatus_core.dylib'])):
#         # If the estimated libpath is already in the default DYLD_FALLBACK_LIBRARY_PATH,
#         # we don't have to add it.  See ``man 1 dyld`` for the list of default search paths.
#         if libpath not in [os.path.expanduser('~/lib'), '/usr/local/lib', '/lib', '/usr/lib']:
#           envvars['DYLD_FALLBACK_LIBRARY_PATH'] = libpath
#           _logger.info('setting DYLD_FALLBACK_LIBRARY_PATH to %s', libpath)
#     return subprocess.Popen(cmdline, env=envvars, *args, **kwargs)


import sys
import copy
import struct
import base64
import subprocess
import tempfile
import optparse
import msgpack
import json
from binascii import crc32
from io import BytesIO
from .compat import *
from ._stdio import print, printe, get_stdio
from ._process import JubaProcess
# -*- coding: utf-8 -*-

"""
This module provides features to manipulate model files.
"""

from __future__ import absolute_import, division, print_function, unicode_literals




class JubaDump(object):
  """
  ``JubaDump`` provides a high-level dump of Jubatus models.
  ``jubadump`` command must be installed.
  """

  @classmethod
  def dump_file(cls, target):
    """
    Returns the dumped model data structure of the model file path ``target``.
    """

# Path: jubakit/_stdio.py
# class _StandardIO(object):
#   def get(cls):
#   def set(cls, stdin=None, stdout=None, stderr=None):
#   def print(cls, *args, **kwargs):
#   def printe(cls, *args, **kwargs):
#   def devnull(cls):
# 
# Path: jubakit/_process.py
# class JubaProcess(object):
#   @classmethod
#   def get_process(cls, cmdline, env=None, *args, **kwargs):
#     """
#     Returns subprocess.Popen instance.
#     """
#     envvars = env if env else dict(os.environ)
#     if platform.system() == 'Darwin' and 'DYLD_FALLBACK_LIBRARY_PATH' not in envvars:
#       """
#       Due to homebrew-jubatus issue #15, when using Homebrew with locations other than
#       the standard installation path (/usr/local), Jubatus processes built on OS X cannot
#       be run without DYLD_FALLBACK_LIBRARY_PATH.  However, on El Capitan or later,
#       DYLD_FALLBACK_LIBRARY_PATH are not propagated from parent process.  We workaround
#       the problem by automatically estimating DYLD_FALLBACK_LIBRARY_PATH based on PATH.
#       """
#       cmdpath = distutils.spawn.find_executable(cmdline[0])
#       if cmdpath is None:
#         raise RuntimeError('{0} command not found; confirm that PATH is properly set'.format(cmdline[0]))
#       libpath = os.sep.join(cmdpath.split(os.sep)[:-2] + ['lib'])
#       if os.path.isfile(os.sep.join([libpath, 'libjubatus_core.dylib'])):
#         # If the estimated libpath is already in the default DYLD_FALLBACK_LIBRARY_PATH,
#         # we don't have to add it.  See ``man 1 dyld`` for the list of default search paths.
#         if libpath not in [os.path.expanduser('~/lib'), '/usr/local/lib', '/lib', '/usr/lib']:
#           envvars['DYLD_FALLBACK_LIBRARY_PATH'] = libpath
#           _logger.info('setting DYLD_FALLBACK_LIBRARY_PATH to %s', libpath)
#     return subprocess.Popen(cmdline, env=envvars, *args, **kwargs)


# Path: jubakit/model.py
import sys
import copy
import struct
import base64
import subprocess
import tempfile
import optparse
import msgpack
import json
from binascii import crc32
from io import BytesIO
from .compat import *
from ._stdio import print, printe, get_stdio
from ._process import JubaProcess

# -*- coding: utf-8 -*-

"""
This module provides features to manipulate model files.
"""

from __future__ import absolute_import, division, print_function, unicode_literals




class JubaDump(object):
  """
  ``JubaDump`` provides a high-level dump of Jubatus models.
  ``jubadump`` command must be installed.
  """

  @classmethod
  def dump_file(cls, target):
    """
    Returns the dumped model data structure of the model file path ``target``.
    """

    proc = JubaProcess.get_process(['jubadump', '-i', target], stdout=subprocess.PIPE, stderr=subprocess.PIPE)