'''
function [rtree_idx,timeGeoList] = get_historic_missions()
%GET_HISTORIC_MISSIONS Summary of this function goes here
%   Detailed explanation goes here
        mission_list=uigetdir2('/mnt/m/pipe/timgs/sonobot-generic', ...
                            'Select mission directories');
        py.importlib.import_module('rtree');
        rtree_idx=py.rtree.index.Index('mission');
        timeGeoList=[];
        for directory = mission_list
            [rtree_idx,timeGeoList]=read_timeGeo(rtree_idx,timeGeoList,directory{1});
        end

end
'''
import logging

from  rtree import index
import glob
#from src.select_dirs import select_dirs
from src.read_timeGeo import read_timeGeo
import src.global_settings as gl
from src.db_skeleton import dbs_class
def get_historic_missions() -> (index , list):
    #dir_list=select_dirs()
    dir_list=['/mnt/m/pipe/timgs/sonobot-generic/20230324', '/mnt/m/pipe/timgs/sonobot-generic/20230327']
    #dir_list=['/mnt/m/pipe/timgs/sonobot-generic/20230324']
    logging.debug(f"Creating r-tree")
    rtree_idx=index.Index()
    logging.debug(f"Creating db for {gl.args}")
    db=dbs_class(gl.args.db)
    timeGeoList=[]
    for directory in dir_list:
        logging.debug(f"selected: {directory}")
        rtree_idx,timeGeoList=read_timeGeo(rtree_idx,timeGeoList,db,directory)
    return rtree_idx,timeGeoList,db

if __name__ == "__main__":
    rtree_idx,timeGeoList=get_historic_missions()

