# 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/httpd.py
# class ThreadedHTTPServer(SocketServer.ThreadingMixIn,
#                          BaseHTTPServer.HTTPServer):
# class BaseRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
#   def url_to_fs_path(self, url):
#   def send_head(self):


import os
import re
import sys
import threading
import jsontemplate
from common import util
from common import httpd
{.repeated section package}
  <li>{name} {.if test static} <a href="{name}/static/">static</a> {.end} </li>
{.end}
</ul>
""", default_formatter='html')


# /s//<session>/<partnum>.html
PATH_RE = re.compile(r'/s/(\S+)/(\d+).html$')


def _ListPlugins(root_dir):
  """
  Returns a template data dictionary.  Plugins are directories.  Plugins with
  'static' dirs are marked.
  """
  plugin_root = os.path.join(root_dir, 'plugins')
  data = []
  for name in os.listdir(plugin_root):
    path = os.path.join(plugin_root, name)
    if not os.path.isdir(path):
      continue
    p = os.path.join(path, 'static')
    s = os.path.isdir(p)
    # e.g. {name: csv, static: True}
    data.append({'name': name, 'static': s})
  data.sort(key=lambda d: d['name'])
  return data



# 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/httpd.py
# class ThreadedHTTPServer(SocketServer.ThreadingMixIn,
#                          BaseHTTPServer.HTTPServer):
# class BaseRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
#   def url_to_fs_path(self, url):
#   def send_head(self):


# Path: webpipe/handlers.py
import os
import re
import sys
import threading
import jsontemplate
from common import util
from common import httpd

{.repeated section package}
  <li>{name} {.if test static} <a href="{name}/static/">static</a> {.end} </li>
{.end}
</ul>
""", default_formatter='html')


# /s//<session>/<partnum>.html
PATH_RE = re.compile(r'/s/(\S+)/(\d+).html$')


def _ListPlugins(root_dir):
  """
  Returns a template data dictionary.  Plugins are directories.  Plugins with
  'static' dirs are marked.
  """
  plugin_root = os.path.join(root_dir, 'plugins')
  data = []
  for name in os.listdir(plugin_root):
    path = os.path.join(plugin_root, name)
    if not os.path.isdir(path):
      continue
    p = os.path.join(path, 'static')
    s = os.path.isdir(p)
    # e.g. {name: csv, static: True}
    data.append({'name': name, 'static': s})
  data.sort(key=lambda d: d['name'])
  return data



class WaitingRequestHandler(httpd.BaseRequestHandler):