Esempio n. 1
0
    def get_next_blk(self, f_log='', get_prmbl=False, skip_fBase=[], fd=''):
        # read the next entry from a log-file or alternatively from provided fd

        if 'str' in repr(type(fd)):
            is_fd_explicit=False

            # for having multiple log-files open
            try:
                self.dict_fd
            except:
                self.dict_fd = {}

            if f_log in self.dict_fd.keys():
                # a file is already open
                fd = self.dict_fd[f_log]
            elif len(fd):
                # new
                try:
                    fd = open(f_log)
                    self.dict_fd[f_log] = fd
                except:
                    print 'could not open file ' + f_log
                    return []  # False
        else:
            is_fd_explicit=True

        blk = []
        if len(skip_fBase):
            is_skip_fBase=True
        else:
            is_skip_fBase=False

        # read preamble when the file was just opened
        if fd.tell() == 0:
            self.blk_last_line=''

            # skip the preamble
            for line in fd:
                blk.append(line)

                if 'items:' in line:
                    self.blk_last_line = fd.next()
                    break

            if get_prmbl:
                return blk
            else:
                blk = []

        if len(self.blk_last_line):
            blk.append(self.blk_last_line)

        for line in fd:
            line = qa_util.s_rstrip(line, sep='\n')
            if len(line) == 0:
                continue

            if '- date:' in line:
                # eventually for the current block
                if len(blk):
                    # blk is reset for skip condition True
                    if is_skip_fBase:
                        self.check_for_skipping(blk, skip_fBase)

                    # Preserve the current line for next blk.
                    self.blk_last_line = line
                    return blk

            blk.append(line)

        # finalise after EOF.
        # If blk length > 0, then check the current blk,
        # which wasn't done in the loop

        # Another call would have blk = [].
        if is_skip_fBase:
            self.check_for_skipping(blk, skip_fBase)

        if is_fd_explicit:
            self.dict_fd[f_log].close()
            del self.dict_fd[f_log]

        return blk
Esempio n. 2
0
def clearInq(qa_var_path, fBase, logfile):
#    isFollowLink = False
    v_clear = qaOpts.getOpt('CLEAR')

    if repr(type(v_clear)).find('bool') > -1:
        return clear(qa_var_path, fBase, logfile)

    isClear=False

    for f in v_clear.split(','):
        if f == 't':
            break  # unconditional

        '''
        if f == 'follow_links':
            if not getOpts.isOpt('DEREFERENCE_SYM_LINKS'):

                isFollowLink = True
            isClear = True
        el'''

        if f == 'only':
            isClear = True
        elif f[0:4] == 'lock':
            # locked  files
            if len( glob.glob(os.path.join(qa_var_path, 'qa_lock_' + fBase +'*') ) ):
                isClear = True
        elif f[0:4] == 'note':
            if len( glob.glob(os.path.join(qa_var_path, 'qa_note_' + fBase +'*') ) ):
                isClear = True
        elif f[0:4] == 'mark':
            # only pass those that are locked; redo erroneous cases
            if len( glob.glob(os.path.join(qa_var_path, fBase + '.clear') )):
                isClear = True
        elif qa_util.s_rstrip(f, sep='=') == 'level':
            # clear specified level
            f=qa_util.s_lstrip(f, sep='=') + '-'
        elif f.find('=') > -1 and qa_util.s_rstrip(f, '=') == 'tag':
            # e.g. 'L1-${tag}: where tag=CF_12 would match CF_12, CF_12x etc.
            f='[\w]*-*' + qa_util.s_lstrip(f, sep='=') + '.*: '

            fls = glob.glob(os.path.join(qa_var_path, 'qa_note_' + fBase +'*') )
            fls.extend(glob.glob(os.path.join(qa_var_path, 'qa_lock_' + fBase +'*') ))

            for fl in fls:
                try:
                    subprocess.check_call('grep', '-q', f, fl)
                except:
                    pass
                else:
                    isClear = True
                    break
        else:
            # CLEAR=var=name
            pos = f.find('var=')
            if pos > -1:
                f = f[pos+4:]

            # else:
                # CLEAR=varName

            regExp = re.match(f, fBase)
            if regExp:
                tmp_ls = glob.glob(os.path.join(qa_var_path, '*_' + fBase + '*'))
                if len(tmp_ls):
                    isClear = True

        if isClear:
            # now do the clearance
            return clear(qa_var_path, fBase, logfile)

    return False