# 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: 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 datetime
import errno
import getpass
import json
import optparse
import os
import Queue
import threading
import string  # for lower case letters
import sys
import handlers
import tnet
from common import httpd
from common import util
from common import spy
  # scrolls go in the 's' dir, plugins in the 'plugins' dir
  parser.add_option(
      '--user-dir', dest='user_dir', type='str',
      default=util.GetUserDir(),
      help='Per-user directory for webpipe')

  return parser


def AppMain(argv):
  """Returns the length of the scroll created."""

  try:
    action = argv[1]
  except IndexError:
    raise Error('Action required')

  global _verbose
  (opts, _) = CreateOptionsParser().parse_args(argv[2:])
  if opts.verbose:
    _verbose = True

  # Other actions:
  # serve-rendered (or servehtml)
  # refresh

  if action == 'serve':  # TODO: rename to 'serve'
    scroll_path = argv[2]

    # Write index.html in the session dir.

# 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: 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/serve.py
import datetime
import errno
import getpass
import json
import optparse
import os
import Queue
import threading
import string  # for lower case letters
import sys
import handlers
import tnet
from common import httpd
from common import util
from common import spy

  # scrolls go in the 's' dir, plugins in the 'plugins' dir
  parser.add_option(
      '--user-dir', dest='user_dir', type='str',
      default=util.GetUserDir(),
      help='Per-user directory for webpipe')

  return parser


def AppMain(argv):
  """Returns the length of the scroll created."""

  try:
    action = argv[1]
  except IndexError:
    raise Error('Action required')

  global _verbose
  (opts, _) = CreateOptionsParser().parse_args(argv[2:])
  if opts.verbose:
    _verbose = True

  # Other actions:
  # serve-rendered (or servehtml)
  # refresh

  if action == 'serve':  # TODO: rename to 'serve'
    scroll_path = argv[2]

    # Write index.html in the session dir.

    package_dir = util.GetPackageDir()