# Path: fiddle_extra/pymacs_request.py
# class Emacs():
#     def __init__(self):
#     def cleanup(self):
#     def receive(self):
#     def send(self, text):
# def ask_emacs(text, printer="prin1", execbuffer=""):
# def ask_emacs_in_buffer(cmd, bufname):


import os
import csv
import sys
import re
import glob
import numpy
import tables
import pytable_utils
import run_cmd
import StringIO
import pickle
import hashlib
import subprocess
import substages_parser
import db_info
import testsuite_utils as utils
import addr_space
import logging
from memory_tree import intervaltree
from collections import Iterable
from config import Main
from fiddle_extra import pymacs_request
            outf = open(path, "w")
            outf.write("(setq substages '(%s))\n" % " ".join([str(i) for i in substage_linenos]))
            outf.close()

    @classmethod
    def get_function_lineno(cls, fn, path, last=False):
        if last:
            out = run_cmd.Cmd().run_cmd("wc -l %s | awk '{print ($1);}'" % (path))
            return long(out)
        out = run_cmd.Cmd().run_cmd("egrep -no ' > %s( |$)' %s" % (fn, path))
        if len(out) == 0:
            return None
        else:
            return long(out.split(":")[0])

    def get_raw_files(self, noprepare):
        stage = self.stage
        substages = self._substage_numbers()
        name = self._substage_names()
        substageresultsdir = getattr(Main.raw.postprocess.consolidate_writes.files.fn_lists, stage.stagename)
        tracename = self.process_trace
        #calltrace_path = getattr(Main.raw.runtime.trace.calltrace.files.org, stage.stagename)
        calltrace_path = getattr(Main.raw.TraceMethod.calltrace.Files.org, stage.stagename)
        if calltrace_path and os.path.exists(calltrace_path) and substageresultsdir:
            pp = Main.raw.postprocess.consolidate_writes.files
            if not noprepare:
                el_path = getattr(pp.el_file, stage.stagename)
                if os.path.exists(substageresultsdir):
                    return {}
                try:

# Path: fiddle_extra/pymacs_request.py
# class Emacs():
#     def __init__(self):
#     def cleanup(self):
#     def receive(self):
#     def send(self, text):
# def ask_emacs(text, printer="prin1", execbuffer=""):
# def ask_emacs_in_buffer(cmd, bufname):


# Path: fiddle/substage.py
import os
import csv
import sys
import re
import glob
import numpy
import tables
import pytable_utils
import run_cmd
import StringIO
import pickle
import hashlib
import subprocess
import substages_parser
import db_info
import testsuite_utils as utils
import addr_space
import logging
from memory_tree import intervaltree
from collections import Iterable
from config import Main
from fiddle_extra import pymacs_request

            outf = open(path, "w")
            outf.write("(setq substages '(%s))\n" % " ".join([str(i) for i in substage_linenos]))
            outf.close()

    @classmethod
    def get_function_lineno(cls, fn, path, last=False):
        if last:
            out = run_cmd.Cmd().run_cmd("wc -l %s | awk '{print ($1);}'" % (path))
            return long(out)
        out = run_cmd.Cmd().run_cmd("egrep -no ' > %s( |$)' %s" % (fn, path))
        if len(out) == 0:
            return None
        else:
            return long(out.split(":")[0])

    def get_raw_files(self, noprepare):
        stage = self.stage
        substages = self._substage_numbers()
        name = self._substage_names()
        substageresultsdir = getattr(Main.raw.postprocess.consolidate_writes.files.fn_lists, stage.stagename)
        tracename = self.process_trace
        #calltrace_path = getattr(Main.raw.runtime.trace.calltrace.files.org, stage.stagename)
        calltrace_path = getattr(Main.raw.TraceMethod.calltrace.Files.org, stage.stagename)
        if calltrace_path and os.path.exists(calltrace_path) and substageresultsdir:
            pp = Main.raw.postprocess.consolidate_writes.files
            if not noprepare:
                el_path = getattr(pp.el_file, stage.stagename)
                if os.path.exists(substageresultsdir):
                    return {}
                try:

                    pymacs_request.ask_emacs('(create-substage-calltraces "%s" "%s" "%s")' %