# Path: common/util.py
# ANSI_BLUE = '\033[36m'
# ANSI_GREEN = '\033[32m'
# ANSI_RESET = '\033[0;0m'
# class Logger(object):
#   def __init__(self, color):
#   def __call__(self, msg, *args):
# def GetPackageDir():
# def GetUserDir():
# 
# Path: common/spy.py
# class Error(Exception):
# class UsageReporter(object):
# class NullUsageReporter(object):
#   def __init__(self, host_port):
#   def Send(self, msg):
#   def SendDict(self, d):
#   def SendRecord(self, event, d):
#   def Send(self, msg):
#   def SendDict(self, d):
#   def SendRecord(self, event, d):
# def _GetUsageConfig():
# def _ReadAddressFile(address_file=None):
# def GetClientFromConfig(address_file=None):


import getopt
import json
import os
import re
import socket
import subprocess
import sys
import time
import tnet
from common import util
from common import spy
class Resources(object):
  def __init__(self, package_dir=None):
    self.package_dir = util.GetPackageDir()
    self.user_dir = util.GetUserDir()

  def GetPluginBin(self, file_type):
    # plugins dir is parallel to webpipe python dir.
    u = os.path.join(self.user_dir, 'plugins', file_type, 'render')
    p = os.path.join(self.package_dir, 'plugins', file_type, 'render')

    # TODO: test if it's executable.  Show clear error if not.
    if os.path.exists(u):
      return u
    if os.path.exists(p):
      return p
    return None


def PluginDispatchLoop(in_dir, out_dir):
  """
  Coroutine that passes its input to a rendering plugin.
  """

  # TODO:
  # - input is a single line for now.  Later it could be a message, if you want
  # people to specify an explicit file type.  I guess that can be done with a
  # file extension too, like typescript.ansi.  The problem is that you can't
  # get any other options with it.
  # - output is pointer to files/dirs written.


# Path: common/util.py
# ANSI_BLUE = '\033[36m'
# ANSI_GREEN = '\033[32m'
# ANSI_RESET = '\033[0;0m'
# class Logger(object):
#   def __init__(self, color):
#   def __call__(self, msg, *args):
# def GetPackageDir():
# def GetUserDir():
# 
# Path: common/spy.py
# class Error(Exception):
# class UsageReporter(object):
# class NullUsageReporter(object):
#   def __init__(self, host_port):
#   def Send(self, msg):
#   def SendDict(self, d):
#   def SendRecord(self, event, d):
#   def Send(self, msg):
#   def SendDict(self, d):
#   def SendRecord(self, event, d):
# def _GetUsageConfig():
# def _ReadAddressFile(address_file=None):
# def GetClientFromConfig(address_file=None):


# Path: webpipe/xrender.py
import getopt
import json
import os
import re
import socket
import subprocess
import sys
import time
import tnet
from common import util
from common import spy

class Resources(object):
  def __init__(self, package_dir=None):
    self.package_dir = util.GetPackageDir()
    self.user_dir = util.GetUserDir()

  def GetPluginBin(self, file_type):
    # plugins dir is parallel to webpipe python dir.
    u = os.path.join(self.user_dir, 'plugins', file_type, 'render')
    p = os.path.join(self.package_dir, 'plugins', file_type, 'render')

    # TODO: test if it's executable.  Show clear error if not.
    if os.path.exists(u):
      return u
    if os.path.exists(p):
      return p
    return None


def PluginDispatchLoop(in_dir, out_dir):
  """
  Coroutine that passes its input to a rendering plugin.
  """

  # TODO:
  # - input is a single line for now.  Later it could be a message, if you want
  # people to specify an explicit file type.  I guess that can be done with a
  # file extension too, like typescript.ansi.  The problem is that you can't
  # get any other options with it.
  # - output is pointer to files/dirs written.


  spy_client = spy.GetClientFromConfig()