2019-07-25 17:26:32 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*-coding:UTF-8 -*
|
|
|
|
|
|
|
|
import os
|
2019-11-05 15:18:03 +01:00
|
|
|
import sys
|
2019-07-26 14:28:02 +02:00
|
|
|
import uuid
|
2019-07-25 17:26:32 +02:00
|
|
|
import redis
|
|
|
|
|
2019-11-05 15:18:03 +01:00
|
|
|
sys.path.append(os.path.join(os.environ['AIL_BIN'], 'lib/'))
|
|
|
|
import ConfigLoader
|
2019-07-25 17:26:32 +02:00
|
|
|
|
2019-11-05 15:18:03 +01:00
|
|
|
config_loader = ConfigLoader.ConfigLoader()
|
|
|
|
r_serv_db = config_loader.get_redis_conn("ARDB_DB")
|
|
|
|
r_serv_log_submit = config_loader.get_redis_conn("Redis_Log_submit")
|
|
|
|
config_loader = None
|
2019-07-25 17:26:32 +02:00
|
|
|
|
2019-07-26 14:28:02 +02:00
|
|
|
def is_valid_uuid_v4(UUID):
|
|
|
|
UUID = UUID.replace('-', '')
|
|
|
|
try:
|
|
|
|
uuid_test = uuid.UUID(hex=UUID, version=4)
|
|
|
|
return uuid_test.hex == UUID
|
|
|
|
except:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def create_import_queue(tags, galaxy, paste_content, UUID, password=None, isfile = False):
|
2019-07-25 17:26:32 +02:00
|
|
|
|
|
|
|
# save temp value on disk
|
2019-07-26 14:28:02 +02:00
|
|
|
for tag in tags:
|
|
|
|
r_serv_db.sadd(UUID + ':ltags', tag)
|
|
|
|
for tag in galaxy:
|
|
|
|
r_serv_db.sadd(UUID + ':ltagsgalaxies', tag)
|
|
|
|
|
2019-07-25 17:26:32 +02:00
|
|
|
r_serv_db.set(UUID + ':paste_content', paste_content)
|
2019-07-26 14:28:02 +02:00
|
|
|
|
|
|
|
if password:
|
|
|
|
r_serv_db.set(UUID + ':password', password)
|
|
|
|
|
2019-07-25 17:26:32 +02:00
|
|
|
r_serv_db.set(UUID + ':isfile', isfile)
|
|
|
|
|
2019-07-26 14:28:02 +02:00
|
|
|
r_serv_log_submit.set(UUID + ':end', 0)
|
|
|
|
r_serv_log_submit.set(UUID + ':processing', 0)
|
|
|
|
r_serv_log_submit.set(UUID + ':nb_total', -1)
|
|
|
|
r_serv_log_submit.set(UUID + ':nb_end', 0)
|
|
|
|
r_serv_log_submit.set(UUID + ':nb_sucess', 0)
|
2019-07-25 17:26:32 +02:00
|
|
|
|
|
|
|
# save UUID on disk
|
|
|
|
r_serv_db.sadd('submitted:uuid', UUID)
|
|
|
|
return UUID
|
|
|
|
|
2019-07-26 14:28:02 +02:00
|
|
|
def check_import_status(UUID):
|
|
|
|
if not is_valid_uuid_v4(UUID):
|
|
|
|
return ({'status': 'error', 'reason': 'Invalid uuid'}, 400)
|
|
|
|
|
|
|
|
processing = r_serv_log_submit.get(UUID + ':processing')
|
|
|
|
if not processing:
|
2019-08-01 09:45:59 +02:00
|
|
|
return ({'status': 'error', 'reason': 'Unknown uuid'}, 404)
|
2019-07-26 14:28:02 +02:00
|
|
|
|
|
|
|
# nb_total = r_serv_log_submit.get(UUID + ':nb_total')
|
|
|
|
# nb_sucess = r_serv_log_submit.get(UUID + ':nb_sucess')
|
|
|
|
# nb_end = r_serv_log_submit.get(UUID + ':nb_end')
|
|
|
|
items_id = list(r_serv_log_submit.smembers(UUID + ':paste_submit_link'))
|
|
|
|
error = r_serv_log_submit.get(UUID + ':error')
|
|
|
|
end = r_serv_log_submit.get(UUID + ':end')
|
|
|
|
|
|
|
|
dict_import_status = {}
|
|
|
|
if items_id:
|
|
|
|
dict_import_status['items'] = items_id
|
|
|
|
if error:
|
|
|
|
dict_import_status['error'] = error
|
|
|
|
|
|
|
|
if processing == '0':
|
|
|
|
status = 'in queue'
|
|
|
|
else:
|
|
|
|
if end == '0':
|
|
|
|
status = 'in progress'
|
|
|
|
else:
|
|
|
|
status = 'imported'
|
|
|
|
dict_import_status['status'] = status
|
|
|
|
|
|
|
|
return (dict_import_status, 200)
|