mirror of
https://github.com/ail-project/ail-framework.git
synced 2024-11-10 08:38:28 +00:00
Changed os.system by os.mkdir + fixed bug during rotation
This commit is contained in:
parent
adc37ab50e
commit
5b7d047622
2 changed files with 17 additions and 8 deletions
|
@ -35,8 +35,7 @@ def check_index_size(indexname):
|
||||||
|
|
||||||
def move_index_into_old_index_folder(baseindexpath):
|
def move_index_into_old_index_folder(baseindexpath):
|
||||||
command_move = "mv {} {}"
|
command_move = "mv {} {}"
|
||||||
command_dir = "mkdir {}"
|
os.mkdir(join(baseindexpath, "old_index"))
|
||||||
os.system(command_dir.format(join(baseindexpath, "old_index")))
|
|
||||||
for files in os.listdir(baseindexpath):
|
for files in os.listdir(baseindexpath):
|
||||||
if not files == "old_index":
|
if not files == "old_index":
|
||||||
os.system(command_move.format(join(baseindexpath, files), join(join(baseindexpath, "old_index"), files)))
|
os.system(command_move.format(join(baseindexpath, files), join(join(baseindexpath, "old_index"), files)))
|
||||||
|
@ -56,7 +55,7 @@ if __name__ == "__main__":
|
||||||
indexRegister_path = join(os.environ['AIL_HOME'],
|
indexRegister_path = join(os.environ['AIL_HOME'],
|
||||||
p.config.get("Indexer", "register"))
|
p.config.get("Indexer", "register"))
|
||||||
indexertype = p.config.get("Indexer", "type")
|
indexertype = p.config.get("Indexer", "type")
|
||||||
INDEX_SIZE_THRESHOLD = p.config.get("Indexer", "index_max_size")
|
INDEX_SIZE_THRESHOLD = int(p.config.get("Indexer", "index_max_size"))
|
||||||
if indexertype == "whoosh":
|
if indexertype == "whoosh":
|
||||||
schema = Schema(title=TEXT(stored=True), path=ID(stored=True,
|
schema = Schema(title=TEXT(stored=True), path=ID(stored=True,
|
||||||
unique=True),
|
unique=True),
|
||||||
|
@ -73,7 +72,7 @@ if __name__ == "__main__":
|
||||||
with open(indexRegister_path, 'w') as f:
|
with open(indexRegister_path, 'w') as f:
|
||||||
f.write(str(time_now))
|
f.write(str(time_now))
|
||||||
#create dir
|
#create dir
|
||||||
os.system("mkdir "+join(baseindexpath, str(time_now)))
|
os.mkdir(join(baseindexpath, str(time_now)))
|
||||||
|
|
||||||
with open(indexRegister_path, "r") as f:
|
with open(indexRegister_path, "r") as f:
|
||||||
allIndex = f.read()
|
allIndex = f.read()
|
||||||
|
@ -113,14 +112,17 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
if time.time() - last_refresh > TIME_WAIT: #avoid calculating the index's size at each message
|
if time.time() - last_refresh > TIME_WAIT: #avoid calculating the index's size at each message
|
||||||
last_refresh = time.time()
|
last_refresh = time.time()
|
||||||
if check_index_size(indexname) > INDEX_SIZE_THRESHOLD*(1000*1000):
|
if check_index_size(indexname) >= INDEX_SIZE_THRESHOLD*(1000*1000):
|
||||||
timestamp = int(time.time())
|
timestamp = int(time.time())
|
||||||
|
print("Creating new index", timestamp)
|
||||||
indexpath = join(baseindexpath, str(timestamp))
|
indexpath = join(baseindexpath, str(timestamp))
|
||||||
ix = create_in(indexpath, schema)
|
|
||||||
indexname = str(timestamp)
|
indexname = str(timestamp)
|
||||||
## Correctly handle the file
|
#update all_index
|
||||||
with open(indexRegister_path, "a") as f:
|
with open(indexRegister_path, "a") as f:
|
||||||
f.write(","+str(timestamp))
|
f.write(","+str(timestamp))
|
||||||
|
#create new dir
|
||||||
|
os.mkdir(indexpath)
|
||||||
|
ix = create_in(indexpath, schema)
|
||||||
|
|
||||||
|
|
||||||
if indexertype == "whoosh":
|
if indexertype == "whoosh":
|
||||||
|
|
|
@ -44,6 +44,7 @@ def get_current_index():
|
||||||
return indexpath
|
return indexpath
|
||||||
|
|
||||||
def get_index_list(selected_index=""):
|
def get_index_list(selected_index=""):
|
||||||
|
temp = []
|
||||||
index_list = []
|
index_list = []
|
||||||
for dirs in os.listdir(baseindexpath):
|
for dirs in os.listdir(baseindexpath):
|
||||||
if os.path.isdir(os.path.join(baseindexpath, dirs)):
|
if os.path.isdir(os.path.join(baseindexpath, dirs)):
|
||||||
|
@ -52,8 +53,14 @@ def get_index_list(selected_index=""):
|
||||||
str(get_dir_size(dirs) / (1000*1000)) + " Mb " + \
|
str(get_dir_size(dirs) / (1000*1000)) + " Mb " + \
|
||||||
"(" + str(get_item_count(dirs)) + " Items" + ")"
|
"(" + str(get_item_count(dirs)) + " Items" + ")"
|
||||||
flag = dirs==selected_index.split('/')[-1]
|
flag = dirs==selected_index.split('/')[-1]
|
||||||
index_list.append([ value, name, flag])
|
if dirs == "old_index":
|
||||||
|
temp = [value, name, flag]
|
||||||
|
else:
|
||||||
|
index_list.append([value, name, flag])
|
||||||
|
|
||||||
|
index_list.sort(reverse=True, key=lambda x: x[0])
|
||||||
|
if len(temp) != 0:
|
||||||
|
index_list.append(temp)
|
||||||
return index_list
|
return index_list
|
||||||
|
|
||||||
def get_dir_size(directory):
|
def get_dir_size(directory):
|
||||||
|
|
Loading…
Reference in a new issue