# Path: swhlab/indexing/indexing.py
# class INDEX:
#     def __init__(self,ABFfolder):
#     def scan(self):
#     def convertImages(self):
#     def analyzeAll(self):
#     def analyzeABF(self,ID):
#     def htmlFor(self,fname):
#     def html_single_basic(self,abfID,launch=False,overwrite=False):
#     def html_single_plot(self,abfID,launch=False,overwrite=False):
#     def html_index(self,launch=True):
# def doStuff(ABFfolder,analyze=False,convert=False,index=True,overwrite=True,
#             launch=True):
# def analyzeSingle(abfFname):
#             ID="UNKNOWN"
#                 ID=fname[:8]
#             ID="UNKNOWN"
#                 ID=fname[:8]
#     IN=INDEX(ABFfolder)
#     IN=INDEX(ABFfolder)


import sys
import glob
import time
import os
import swhlab
import swhlab.core.common as cm #shorthand
from swhlab.indexing import standard
from swhlab.indexing import indexing
    standard.autoABF(fname)

def lazygo(watchFolder='../abfs/',reAnalyze=False,rebuildSite=False,
           keepGoing=True,matching=False):
    """
    continuously monitor a folder for new abfs and try to analyze them.
    This is intended to watch only one folder, but can run multiple copies.
    """
    abfsKnown=[]

    while True:
        print()
        pagesNeeded=[]
        for fname in glob.glob(watchFolder+"/*.abf"):
            ID=os.path.basename(fname).replace(".abf","")
            if not fname in abfsKnown:
                if os.path.exists(fname.replace(".abf",".rsv")): #TODO: or something like this
                    continue
                if matching and not matching in fname:
                    continue
                abfsKnown.append(fname)
                if os.path.exists(os.path.dirname(fname)+"/swhlab4/"+os.path.basename(fname).replace(".abf","_info.pkl")) and reAnalyze==False:
                    print("already analyzed",os.path.basename(fname))
                    if rebuildSite:
                        pagesNeeded.append(ID)
                else:
                    handleNewABF(fname)
                    pagesNeeded.append(ID)
        if len(pagesNeeded):
            print(" -- rebuilding index page")

# Path: swhlab/indexing/indexing.py
# class INDEX:
#     def __init__(self,ABFfolder):
#     def scan(self):
#     def convertImages(self):
#     def analyzeAll(self):
#     def analyzeABF(self,ID):
#     def htmlFor(self,fname):
#     def html_single_basic(self,abfID,launch=False,overwrite=False):
#     def html_single_plot(self,abfID,launch=False,overwrite=False):
#     def html_index(self,launch=True):
# def doStuff(ABFfolder,analyze=False,convert=False,index=True,overwrite=True,
#             launch=True):
# def analyzeSingle(abfFname):
#             ID="UNKNOWN"
#                 ID=fname[:8]
#             ID="UNKNOWN"
#                 ID=fname[:8]
#     IN=INDEX(ABFfolder)
#     IN=INDEX(ABFfolder)


# Path: doc/oldcode/indexing/monitor.py
import sys
import glob
import time
import os
import swhlab
import swhlab.core.common as cm #shorthand
from swhlab.indexing import standard
from swhlab.indexing import indexing

    standard.autoABF(fname)

def lazygo(watchFolder='../abfs/',reAnalyze=False,rebuildSite=False,
           keepGoing=True,matching=False):
    """
    continuously monitor a folder for new abfs and try to analyze them.
    This is intended to watch only one folder, but can run multiple copies.
    """
    abfsKnown=[]

    while True:
        print()
        pagesNeeded=[]
        for fname in glob.glob(watchFolder+"/*.abf"):
            ID=os.path.basename(fname).replace(".abf","")
            if not fname in abfsKnown:
                if os.path.exists(fname.replace(".abf",".rsv")): #TODO: or something like this
                    continue
                if matching and not matching in fname:
                    continue
                abfsKnown.append(fname)
                if os.path.exists(os.path.dirname(fname)+"/swhlab4/"+os.path.basename(fname).replace(".abf","_info.pkl")) and reAnalyze==False:
                    print("already analyzed",os.path.basename(fname))
                    if rebuildSite:
                        pagesNeeded.append(ID)
                else:
                    handleNewABF(fname)
                    pagesNeeded.append(ID)
        if len(pagesNeeded):
            print(" -- rebuilding index page")

            indexing.genIndex(os.path.dirname(fname),forceIDs=pagesNeeded)