import os
import time
import ast
import copy
import numpy
import inspect
from collections import deque,defaultdict
from collections import OrderedDict
from casatasks import casalog, flagdata
from casatools import table,quanta,ms,agentflagger
from .parallel.parallel_task_helper import ParallelTaskHelper
tblocal = table()
mslocal = ms()
qalocal = quanta()
'''
A set of helper functions for the tasks flagdata and flagcmd.
Class Parser: to parse flag commands
I/O functions:
get_flag_cmd_list
readFile
readFiles
readAndParse
parseDictionary
parseXML
readAntennaList
writeAntennaList
writeFlagCommands
writeRflagThresholdFile
Parameter handling
compressSelectionList
evalParams
selectReason
parseSelectionPars
parseUnion
purgeEmptyPars
purgeParameter
parseAgents
Others
backupFlags
convertDictToString
convertStringToDict
extractAntennaInfo
save_rflag_consolidated_files
parseRflagOutputFromSummary
'''
debug = False
def get_task_arg_default( func, arg ):
spec = inspect.getfullargspec(func.__call__)
if arg not in spec.args:
raise Exception("cannot find '%s' among the function arguments" % arg)
return spec.defaults[spec.args.index(arg)-1]
class Parser():
''' Parser for input files.
primarydivider --> first split the string by this character
secondarydivider --> next split the string by this character
The constructor takes two separators.
It first splits the string by the 'primarydivider'. It
then loops through each entry after the first split and
verifies if the 'secondarydivider' is in the string. If yes,
the string is added to a list. If not, it removes the
whitespace of the initial split, by bringing back two
strings together. This will allow the primarydivider to be
part of the string itself. Last thing, it returns an ordered
dictionary using the imported class OrderedDict.
'''
def __init__(self,primarydivider,secondarydivider):
self.prime = primarydivider
self.second = secondarydivider
def parse2Dictionary(self,string):
res = self.initialsplit(string)
new = []
for entry in res:
if self.second not in entry:
new[-1] += ' ' + entry
else:
new.append(entry)