# -*- coding: utf-8 -*-
#------------------------------------------------------------------------------
#  Package: Pikos toolkit
#  File: api.py
#  License: LICENSE.TXT
#
#  Copyright (c) 2012, Enthought, Inc.
#  All rights reserved.
#------------------------------------------------------------------------------

from pikos.monitor import Monitor

def baserecorder(filter_=None):
    """ Factory function that returns a basic recorder.
    """
    import sys
    from pikos.recorders.text_stream_recorder import TextStreamRecorder
    return TextStreamRecorder(sys.stdout, filter_=filter_,
                               auto_flush=True, formated=True)

def monitor_functions(filter_=None):
    """ Factory function that returns a basic function monitor.
    """
    from pikos.monitors.function_monitor import FunctionMonitor
    return Monitor(FunctionMonitor(baserecorder(filter_=filter_)))

def monitor_lines(filter_=None):
    """ Factory function that returns a basic line monitor.
    """
    from pikos.monitors.line_monitor import LineMonitor
    return Monitor(LineMonitor(baserecorder(filter_=filter_)))

def memory_on_functions(filter_=None):
    """ Factory function that returns a basic function memory monitor.
    """
    from pikos.monitors.function_memory_monitor import FunctionMemoryMonitor
    return Monitor(FunctionMemoryMonitor(baserecorder(filter_=filter_)))

def memory_on_lines(filter_=None):
    """ Factory function that returns a basic line memory monitor.
    """
    from pikos.monitors.line_memory_monitor import LineMemoryMonitor
    return Monitor(LineMemoryMonitor(baserecorder(filter_=filter_)))

def yappi_profile(buildins=None):
    """ Factory function that returns a yappi monitor.
    """
    from pikos.external.yappi_profiler import YappiProfiler
    return Monitor(YappiProfiler(buildins))

def line_profile(*args, **kwrds):
    """ Factory function that returns a line profiler.

    Please refer to
    `<http://packages.python.org/line_profiler/ for more information>_`
    for initialization options.
    """
    from pikos.external.line_profiler import LineProfiler
    return Monitor(LineProfiler(*args, **kwrds))


#: Easy to find placeholder for the Monitor decorator class.
monitor = Monitor

@@ -323,24 +323,40 @@
 ikos.monitor
+s.monitor_attach
  import Moni
@@ -358,16 +358,22 @@
  Monitor
+Attach
 %0A%0Adef ba
@@ -855,32 +855,38 @@
   return Monitor
+Attach
 (FunctionMonitor
@@ -1090,24 +1090,30 @@
 turn Monitor
+Attach
 (LineMonitor
@@ -1359,16 +1359,22 @@
  Monitor
+Attach
 (Functio
@@ -1614,24 +1614,30 @@
 turn Monitor
+Attach
 (LineMemoryM
@@ -1851,16 +1851,22 @@
  Monitor
+Attach
 (YappiPr
@@ -2182,16 +2182,22 @@
  Monitor
+Attach
 (LinePro
@@ -2289,16 +2289,23 @@
 %0Amonitor
+_attach
  = Monit
@@ -2302,13 +2302,19 @@
 ch = Monitor
+Attach
 %0A

update api to use MonitorAttach