Ejemplo n.º 1
0
def normalize_string(string_old):
    string_new = string_old
    re_compile = re.compile("^(.*)\s(\d{1,3}),(\d.*)$")
    while _search(re_compile, string_new):
        findall = _findall(re_compile, string_new)
        if len(findall) > 0:
            string_new = '%s  %s%s' % findall[0]
    return (string_new)
Ejemplo n.º 2
0
def get_row_error_range(file_last, line_range_init=0, line_range_done=1):
    line_find = []
    line_read = []

    with open_file(file_last) as file:
        line_read = file.readlines()
        file.close()

    okif_regx = False
    for i in range(0, len(line_read)):
        line = line_read[i]
        if args.debug >=3: logs.info("Line file: [%s" % line, end='')

        if _search(end_grep_regx, line):
            if args.debug >=2: logs.info("Find tag_okif_regex=[%s]" % end_grep_regx)
            okif_regx = True

        if _search(tag_grep_regx, line):
            if args.debug >=2: logs.info("Line find: [%s" % line, end='')

        #CZ#line_find.append(line)
            if _search(tag_line_regx, line):
                line_list = get_line_range(i, line_range_init, line_range_done, line_read)
                line_find.extend(line_list)
            else:
            #CZ#line_find.append(line)
            #CZ#line_list = get_line_range(i, line_range_init)
                line_list = get_line_range(i, line_range_init, 0)
                line_find.extend(line_list)

    if not okif_regx:
        line_list = get_line_range(len(line_read)-end_line_back, 0, end_line_back, line_read)
        line_find.extend(line_list)
        line_find.extend("\n")
        line_find.extend(end_grep_ifno)

    row_error = ''.join(line_find)

    return(row_error)
Ejemplo n.º 3
0
def get_row_error_line(file_last):
    line_find = []

    with open_file(file_last) as file:
        for line in file:
            if args.debug >=2: logs.info("Line file: [%s" % line, end='')

            if _search(tag_grep_regx, line):
                if args.debug >=1: logs.info("Line find: [%s" % line, end='')

                line_find.append(line)

        file.close()

    row_error = ''.join(line_find)

    return(row_error)
Ejemplo n.º 4
0
def get_list_last_name_regx(path_find):
    list_last = []
    time_last = 0

#CZ#for file_find in _os_file._fileListDir(path_find):
    for name_find in _nameListDir(path_find):
        if _search(tag_name_regx, name_find):
            file_find = path_find + name_find
            if args.debug >=1: logs.info("Read file: [%s]" % file_find)

            if tag_find_last:
                # read time file creation
            #CZ#sta_time = os.stat(file_find).st_atime # st_atime = time of most recent access
                stm_time = os.stat(file_find).st_mtime # st_mtime = time of most recent content modification
            #CZ#stc_time = os.stat(file_find).st_ctime # st_ctime = platform dependent: time of most recent metadata change on Unix,
                                                       #                         or the time of creation on Windows

                # get max time
                max_time = 0
            #CZ#if sta_time > max_time:
            #CZ#    max_time = sta_time
                if stm_time > max_time:
                    max_time = stm_time
            #CZ#if stc_time > max_time:
            #CZ#    max_time = stc_time

                # get max file
                if max_time > time_last:
                    if len(list_last) == 0:
                        list_last.append(file_find)
                    else:
                        list_last[0] = file_find
                    time_last = max_time
            else:
                list_last.append(file_find)

    return(list_last)
Ejemplo n.º 5
0
def manipulate_av8p(txt_lines):
    tmp_lines = []
    dat_lines = []

    dat_head_0 = True
    dat_body_1 = False
    dat_body_2 = False

    row_head_0 = None
    row_body_1 = None
    row_body_2 = None

    fld_first = 45
    fld_code = 10
    fld_name = fld_first - fld_code
    frm_first = '%' + str(fld_code) + 's' + csv_delimiter + '%-' + str(
        fld_name) + 's'

    reg_head_0 = 'DAL .* TOTALI'
    reg_body_1 = '\d{1,' + str(fld_code) + '}\s\s?\w'

    #rec_head_0 = re.compile(reg_head_0, re.I|re.L|re.M|re.U|re.S)
    #rec_body_1 = re.compile(reg_body_1, re.I|re.L|re.M|re.U|re.S)

    #__________________________________________________________________________
    for txt_line in txt_lines:
        txt_line = _remove(txt_line, "\f\r\n")
        txt_line = normalize_string(txt_line)

        if args.debug >= 2:
            print("#-|" + txt_line)
        #______________________________________________________________________
    #if dat_head_0 and rec_head_0.search(txt_line):
        if dat_head_0 and _search(reg_head_0, txt_line):
            dat_head_0 = False
            dat_body_1 = True

            row_head_0 = (frm_first % ('Codice', 'Prodotto')) + txt_line

            tmp_lines.append(row_head_0)
            if args.debug >= 1:
                print("#1#" + row_head_0)
        #______________________________________________________________________
        if dat_body_2:
            dat_body_1 = True
            dat_body_2 = False

            row_body_2 = row_body_1 + txt_line

            tmp_lines.append(row_body_2)
            if args.debug >= 1:
                print("#1|" + row_body_2)
        #______________________________________________________________________
    #if dat_body_1 and rec_body_1.search(txt_line) and len(txt_line)<=fld_first:
        if dat_body_1 and _search(reg_body_1,
                                  txt_line) and len(txt_line) <= fld_first:
            dat_body_1 = False
            dat_body_2 = True

            list = _stringToListOnSpace(_trim(txt_line))

            code = list[0] if len(list) > 0 else None
            name = _trim(_joinSpace(list[1:])) if len(list) > 1 else None

            row_body_1 = frm_first % (code, name)

    #__________________________________________________________________________
    for txt_line in tmp_lines:
        txt_line = string_to_csv(txt_line, csv_delimiter, fld_first, 6, 14)
        if args.debug >= 1:
            print("#2|" + txt_line)
        cvs_line = _stringToList(txt_line, csv_delimiter)
        cvs_line = _trimList(cvs_line)
        dat_lines.append(cvs_line)
    return (dat_lines)