#!/usr/bin/env python

from pysas.wrapper import Wrapper as w
import os, sys
from os.path import dirname
import inspect
import glob

import arches
from arches.utils import *
from arches.config import *

root_path=dirname(dirname(dirname(inspect.getfile(arches))))
print("Arches root path: {}".format(root_path))

archive_dir=root_path+'/data/archive'
events_dir=root_path+'/data/processed'
products_dir=root_path+'/products'

create_folder(events_dir)

inargs = ['--version']
t = w('sasver', inargs)
t.run()


for obsid in good:
    
    local_ccf=f'{events_dir}/{obsid}/ccf.cif'
    work_dir=f'{events_dir}/{obsid}'
    os.environ['SAS_ODF'] = f'{archive_dir}'

    inargs = ['--version']
    t = w('sasver', [])
    t.run()

    inargs = [f'odfid={obsid}',f'workdir={archive_dir}']
    w('startsas', inargs).run()

    remove_file('ccf.cif')
    files=glob.glob("*.SAS")
    for fn in files:
        remove_file(fn)
    
