Use flagfile (first) or flaglist (alternately) to run CASA flagging tool.

def flagdata(self, msfile, flagfile='', flaglist=[]):
        """ Use flagfile (first) or flaglist (alternately) to run CASA flagging tool.
        """

        if not flagfile:
            # write flag data to text file
            flagfile = os.path.join(self.workdir, 'flags.txt')
            print 'Writing flaglist to %s.' % flagfile

            if not flaglist:
                flaglist = ["mode='unflag'", "mode='shadow'", "mode='clip' clipzeros=True",
                            "mode='rflag' freqdevscale=4 timedevscale=5",
                            "mode='extend' growaround=True growtime=60 growfreq=40 extendpols=True",
                            "mode='quack' quackinterval=20", "mode='summary'"]

            with open(flagfile, 'w') as flfile:
                for flag in flags:
                    flfile.write(flag + '\n')

        else:
            print 'Using flags in %s.' % flagfile

        print 'Flagging with these commands:'
        for ff in enumerate(open(flagfile)): print ff[1].rstrip()

        cfg = tl.FlaglistConfig()  # configure split
        cfg.vis = msfile
        cfg.inpfile = flagfile
        tl.flaglist(cfg)