# Path: killMS/Parset/ReadCFG.py
# def test():
# def FormatDico(DicoIn):
# def FormatValue(ValueIn,StrMode=False):
#     def __init__(self,File="../Parset/DefaultParset.cfg"):
#     def update (self, other):
#     def Read(self):
#     def ConfigSectionMap(self,section):
#     P=Parset()
#         L=config.read(self.File)
# class Parset():
# 
# Path: killMS/Parset/MyOptParse.py
# class MyOptParse():
#     def __init__(self,usage='Usage: %prog --ms=somename.MS <options>',version=report_version(),
#                  description="""Questions and suggestions: cyril.tasse@obspm.fr""",
#                  DefaultDict=None):
#         self.opt = OptParse.OptionParser(usage=usage,version=version,description=description)
#         self.DefaultDict=DefaultDict
#         self.CurrentGroup=None
#         self.DicoGroupDesc=collections.OrderedDict()
# 
#     def OptionGroup(self,Name,key=None):
#         if self.CurrentGroup!=None:
#             self.Finalise()
#         self.CurrentGroup = OptParse.OptionGroup(self.opt, Name)
#         self.CurrentGroupKey=key
#         self.DicoGroupDesc[key]=Name
# 
# 
#     def GiveOptionObject(self):
#         DC=self.GiveDicoConfig()
#         class Object(object):
#             pass
# 
#         options=Object()
#         for Field in DC.keys():
#             D=DC[Field]
#             for key in D.keys():
#                 setattr(options, key, D[key])
#         return options
# 
#     def add_option(self,Name='Mode',help='Default %default',type="str",default=None):
#         if default==None:
#             default=self.DefaultDict[self.CurrentGroupKey][Name]
#         
#         self.CurrentGroup.add_option('--%s'%Name,help=help,type=type,default=default,dest=self.GiveKeyDest(self.CurrentGroupKey,Name))
# 
#     def GiveKeyDest(self,GroupKey,Name):
#         return "_".join([GroupKey,Name])
# 
#     def GiveKeysOut(self,KeyDest):
#         return KeyDest.split("_")
# 
#     def Finalise(self):
#         self.opt.add_option_group(self.CurrentGroup)
# 
#     def ReadInput(self):
#         self.options, self.arguments = self.opt.parse_args()
#         self.GiveDicoConfig()
#         self.DicoConfig=self.DefaultDict
#         
#     def GiveDicoConfig(self):
#         DicoDest=vars(self.options)
#         for key in DicoDest.keys():
#             GroupName,Name=self.GiveKeysOut(key)
#             val=DicoDest[key]
#             if type(val)==str:
#                 val=ReadCFG.FormatValue(val)
#             self.DefaultDict[GroupName][Name]=val
# 
#         return self.DefaultDict
# 
#     def ToParset(self,ParsetName):
#         Dico=self.GiveDicoConfig()
#         f=open(ParsetName,"w")
#         for MainKey in Dico.keys():
#             f.write('[%s]\n'%MainKey)
#             D=Dico[MainKey]
#             for SubKey in D.keys():
#                 f.write('%s = %s \n'%(SubKey,str(D[SubKey])))
#             f.write('\n')
#         f.close()
# 
#     def Print(self,RejectGroup=[]):
#         P=ClassPrint.ClassPrint(HW=50)
#         print(ModColor.Str(" Selected Options:"))
#     
#         for Group,V in self.DefaultDict.items():
#             Skip=False
#             for Name in RejectGroup:
#                 if Name in Group:
#                     Skip=True
#             if Skip: continue
#             try:
#                 GroupTitle=self.DicoGroupDesc[Group]
#             except:
#                 GroupTitle=Group
#             print(ModColor.Str(GroupTitle,col="green"))
#     
#             option_list=self.DefaultDict[Group]
#             for oname in option_list:
#                 V=self.DefaultDict[Group][oname]
#                 
#                 if True:#V!="":
#                     if V=="": V="''"
#                     P.Print(oname,V)
#             print()


import sys,os
import time
import subprocess
import killMS
    import matplotlib
import multiprocessing
    import killMS.Other.MyPickle
    import resource
        import killMS.Other.MyPickle
    import time
    import numpy as np
    import pickle
        import DDFacet.Other.MyPickle
        import traceback, pdb
    import glob
    import os
from DDFacet.Other import logger, ModColor
from killMS.Parset import ReadCFG, MyOptParse
    from killMS.Array import NpShared
    from killMS.Data import ClassJonesDomains
    from SkyModel.Sky import ClassSM
    from killMS.Wirtinger.ClassWirtingerSolver import ClassWirtingerSolver
    from killMS.Data import ClassVisServer
    from DDFacet.Data import ClassVisServer as ClassVisServer_DDF
    from killMS.Predict.PredictGaussPoints_NumExpr5 import ClassPredictParallel as ClassPredict
    from killMS.Array import ModLinAlg
    from killMS.Array import NpShared
    from killMS.Other import reformat
        from DDFacet.Other import AsyncProcessPool
        from DDFacet.Other import Multiprocessing
        from killMS.Predict import ClassImageSM2 as ClassImageSM
    from killMS.Other import logo
    from killMS.Other import ModColor
    from killMS.Other import MyPickle
        from DDFacet.Other.progressbar import ProgressBar
            from killMS.Array import NpShared

def _exc_handler(type, value, tb):
    if hasattr(sys, 'ps1') or not sys.stderr.isatty() or type is SyntaxError:
    # we are in interactive mode or we don't have a tty-like
    # device, so we call the default hook
        sys.__excepthook__(type, value, tb)
    else:
        # we are NOT in interactive mode, print the exception...
        traceback.print_exception(type, value, tb)
        print
        # ...then start the debugger in post-mortem mode.
        # pdb.pm() # deprecated
        pdb.post_mortem(tb) # more "modern"


    sys.excepthook = _exc_handler


if __name__=="__main__":


    tic = time.time()
    #os.system('clear')

    logo.print_logo()
    if len(sys.argv)<2:
        raise RuntimeError('At least one parset name or option must be supplied')
        
    ParsetFile=sys.argv[1]


# Path: killMS/Parset/ReadCFG.py
# def test():
# def FormatDico(DicoIn):
# def FormatValue(ValueIn,StrMode=False):
#     def __init__(self,File="../Parset/DefaultParset.cfg"):
#     def update (self, other):
#     def Read(self):
#     def ConfigSectionMap(self,section):
#     P=Parset()
#         L=config.read(self.File)
# class Parset():
# 
# Path: killMS/Parset/MyOptParse.py
# class MyOptParse():
#     def __init__(self,usage='Usage: %prog --ms=somename.MS <options>',version=report_version(),
#                  description="""Questions and suggestions: cyril.tasse@obspm.fr""",
#                  DefaultDict=None):
#         self.opt = OptParse.OptionParser(usage=usage,version=version,description=description)
#         self.DefaultDict=DefaultDict
#         self.CurrentGroup=None
#         self.DicoGroupDesc=collections.OrderedDict()
# 
#     def OptionGroup(self,Name,key=None):
#         if self.CurrentGroup!=None:
#             self.Finalise()
#         self.CurrentGroup = OptParse.OptionGroup(self.opt, Name)
#         self.CurrentGroupKey=key
#         self.DicoGroupDesc[key]=Name
# 
# 
#     def GiveOptionObject(self):
#         DC=self.GiveDicoConfig()
#         class Object(object):
#             pass
# 
#         options=Object()
#         for Field in DC.keys():
#             D=DC[Field]
#             for key in D.keys():
#                 setattr(options, key, D[key])
#         return options
# 
#     def add_option(self,Name='Mode',help='Default %default',type="str",default=None):
#         if default==None:
#             default=self.DefaultDict[self.CurrentGroupKey][Name]
#         
#         self.CurrentGroup.add_option('--%s'%Name,help=help,type=type,default=default,dest=self.GiveKeyDest(self.CurrentGroupKey,Name))
# 
#     def GiveKeyDest(self,GroupKey,Name):
#         return "_".join([GroupKey,Name])
# 
#     def GiveKeysOut(self,KeyDest):
#         return KeyDest.split("_")
# 
#     def Finalise(self):
#         self.opt.add_option_group(self.CurrentGroup)
# 
#     def ReadInput(self):
#         self.options, self.arguments = self.opt.parse_args()
#         self.GiveDicoConfig()
#         self.DicoConfig=self.DefaultDict
#         
#     def GiveDicoConfig(self):
#         DicoDest=vars(self.options)
#         for key in DicoDest.keys():
#             GroupName,Name=self.GiveKeysOut(key)
#             val=DicoDest[key]
#             if type(val)==str:
#                 val=ReadCFG.FormatValue(val)
#             self.DefaultDict[GroupName][Name]=val
# 
#         return self.DefaultDict
# 
#     def ToParset(self,ParsetName):
#         Dico=self.GiveDicoConfig()
#         f=open(ParsetName,"w")
#         for MainKey in Dico.keys():
#             f.write('[%s]\n'%MainKey)
#             D=Dico[MainKey]
#             for SubKey in D.keys():
#                 f.write('%s = %s \n'%(SubKey,str(D[SubKey])))
#             f.write('\n')
#         f.close()
# 
#     def Print(self,RejectGroup=[]):
#         P=ClassPrint.ClassPrint(HW=50)
#         print(ModColor.Str(" Selected Options:"))
#     
#         for Group,V in self.DefaultDict.items():
#             Skip=False
#             for Name in RejectGroup:
#                 if Name in Group:
#                     Skip=True
#             if Skip: continue
#             try:
#                 GroupTitle=self.DicoGroupDesc[Group]
#             except:
#                 GroupTitle=Group
#             print(ModColor.Str(GroupTitle,col="green"))
#     
#             option_list=self.DefaultDict[Group]
#             for oname in option_list:
#                 V=self.DefaultDict[Group][oname]
#                 
#                 if True:#V!="":
#                     if V=="": V="''"
#                     P.Print(oname,V)
#             print()


# Path: killMS/kMS.py
import sys,os
import time
import subprocess
import killMS
    import matplotlib
import multiprocessing
    import killMS.Other.MyPickle
    import resource
        import killMS.Other.MyPickle
    import time
    import numpy as np
    import pickle
        import DDFacet.Other.MyPickle
        import traceback, pdb
    import glob
    import os
from DDFacet.Other import logger, ModColor
from killMS.Parset import ReadCFG, MyOptParse
    from killMS.Array import NpShared
    from killMS.Data import ClassJonesDomains
    from SkyModel.Sky import ClassSM
    from killMS.Wirtinger.ClassWirtingerSolver import ClassWirtingerSolver
    from killMS.Data import ClassVisServer
    from DDFacet.Data import ClassVisServer as ClassVisServer_DDF
    from killMS.Predict.PredictGaussPoints_NumExpr5 import ClassPredictParallel as ClassPredict
    from killMS.Array import ModLinAlg
    from killMS.Array import NpShared
    from killMS.Other import reformat
        from DDFacet.Other import AsyncProcessPool
        from DDFacet.Other import Multiprocessing
        from killMS.Predict import ClassImageSM2 as ClassImageSM
    from killMS.Other import logo
    from killMS.Other import ModColor
    from killMS.Other import MyPickle
        from DDFacet.Other.progressbar import ProgressBar
            from killMS.Array import NpShared


def _exc_handler(type, value, tb):
    if hasattr(sys, 'ps1') or not sys.stderr.isatty() or type is SyntaxError:
    # we are in interactive mode or we don't have a tty-like
    # device, so we call the default hook
        sys.__excepthook__(type, value, tb)
    else:
        # we are NOT in interactive mode, print the exception...
        traceback.print_exception(type, value, tb)
        print
        # ...then start the debugger in post-mortem mode.
        # pdb.pm() # deprecated
        pdb.post_mortem(tb) # more "modern"


    sys.excepthook = _exc_handler


if __name__=="__main__":


    tic = time.time()
    #os.system('clear')

    logo.print_logo()
    if len(sys.argv)<2:
        raise RuntimeError('At least one parset name or option must be supplied')
        
    ParsetFile=sys.argv[1]


    TestParset=ReadCFG.Parset(ParsetFile)