import requests, json, urllib3, datetime, sys
import os
import re
class Line:
def __init__(self, line):
self.no=0
self.line=line
dir_dump = "./dumps"
def main():
lst = []
dic = dict()
if os.path.isdir(dir_dump) == False:
print("\n dir [./dumps] not found. exit.")
exit(0)
filelist = os.listdir(dir_dump)
for li in filelist:
fullpath = dir_dump + "/" + li
f = open(fullpath, 'r')
lines = f.readlines()
for line in lines:
if 'No Such Object' in line or line[0] != '.':
print("[skip] not start dot(.) or failed oids: {}".format(line))
continue
tokens = line.split("=")
keys = tokens[0].strip()
keys = keys[1:]
o = Line(line)
dic[keys] = o
f.close()
# list로 변환
lst = [*dic]
# oid 문자열을 숫자 기반으로 정렬
lst = sorted(lst, key=lambda y: tuple(int(x) for x in y.split('.')))
print(lst)
for index, value in enumerate(lst):
if dic.get(value) is not None:
dic[value].no = index
# 키로 정렬
sorted_dict = sorted(dic.items(), key = lambda item: item[1].no, reverse = False)
print("\n")
i = 0
wf = open("result.txt", 'w')
for li in sorted_dict:
i = i+1
wf.write(li[1].line)
wf.close()
print('Total process lines : {}'.format(i))
if __name__ == "__main__":
start_time = datetime.datetime.now()
main()
end_time = datetime.datetime.now()
print('Duration: {}'.format(end_time - start_time))