2019-04-11 17:49:20 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*-coding:UTF-8 -*
|
|
|
|
|
|
|
|
"""
|
|
|
|
Update AIL
|
|
|
|
============================
|
|
|
|
|
2019-04-12 16:07:40 +02:00
|
|
|
Update AIL in the background
|
2019-04-11 17:49:20 +02:00
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import redis
|
|
|
|
import subprocess
|
2019-11-05 15:18:03 +01:00
|
|
|
|
|
|
|
sys.path.append(os.path.join(os.environ['AIL_BIN'], 'lib/'))
|
|
|
|
import ConfigLoader
|
2019-04-11 17:49:20 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
2019-11-05 15:18:03 +01:00
|
|
|
config_loader = ConfigLoader.ConfigLoader()
|
|
|
|
|
|
|
|
r_serv = config_loader.get_redis_conn("ARDB_DB")
|
2019-11-11 14:54:12 +01:00
|
|
|
r_serv_onion = config_loader.get_redis_conn("ARDB_Onion")
|
2019-11-05 15:18:03 +01:00
|
|
|
config_loader = None
|
2019-04-11 17:49:20 +02:00
|
|
|
|
2019-04-24 16:19:35 +02:00
|
|
|
if r_serv.scard('ail:update_v1.5') != 5:
|
2019-04-16 17:24:59 +02:00
|
|
|
r_serv.delete('ail:update_error')
|
|
|
|
r_serv.set('ail:update_in_progress', 'v1.5')
|
|
|
|
r_serv.set('ail:current_background_update', 'v1.5')
|
|
|
|
if not r_serv.sismember('ail:update_v1.5', 'onions'):
|
2019-04-25 14:39:38 +02:00
|
|
|
update_file = os.path.join(os.environ['AIL_HOME'], 'update', 'v1.5', 'Update-ARDB_Onions.py')
|
2019-04-12 17:32:17 +02:00
|
|
|
process = subprocess.run(['python' ,update_file])
|
|
|
|
|
2019-04-16 17:24:59 +02:00
|
|
|
if not r_serv.sismember('ail:update_v1.5', 'metadata'):
|
2019-04-25 14:39:38 +02:00
|
|
|
update_file = os.path.join(os.environ['AIL_HOME'], 'update', 'v1.5', 'Update-ARDB_Metadata.py')
|
2019-04-12 17:32:17 +02:00
|
|
|
process = subprocess.run(['python' ,update_file])
|
|
|
|
|
2019-04-16 17:24:59 +02:00
|
|
|
if not r_serv.sismember('ail:update_v1.5', 'tags'):
|
2019-04-25 14:39:38 +02:00
|
|
|
update_file = os.path.join(os.environ['AIL_HOME'], 'update', 'v1.5', 'Update-ARDB_Tags.py')
|
2019-04-12 17:32:17 +02:00
|
|
|
process = subprocess.run(['python' ,update_file])
|
|
|
|
|
2019-04-17 17:07:09 +02:00
|
|
|
if not r_serv.sismember('ail:update_v1.5', 'tags_background'):
|
2019-04-25 14:39:38 +02:00
|
|
|
update_file = os.path.join(os.environ['AIL_HOME'], 'update', 'v1.5', 'Update-ARDB_Tags_background.py')
|
2019-04-12 17:32:17 +02:00
|
|
|
process = subprocess.run(['python' ,update_file])
|
2019-04-24 16:19:35 +02:00
|
|
|
if not r_serv.sismember('ail:update_v1.5', 'crawled_screenshot'):
|
2019-04-25 14:39:38 +02:00
|
|
|
update_file = os.path.join(os.environ['AIL_HOME'], 'update', 'v1.5', 'Update-ARDB_Onions_screenshots.py')
|
2019-04-24 16:19:35 +02:00
|
|
|
process = subprocess.run(['python' ,update_file])
|
|
|
|
if r_serv.scard('ail:update_v1.5') != 5:
|
2019-04-16 17:24:59 +02:00
|
|
|
r_serv.set('ail:update_error', 'Update v1.5 Failed, please relaunch the bin/update-background.py script')
|
|
|
|
else:
|
|
|
|
r_serv.delete('ail:update_in_progress')
|
2019-04-17 17:07:09 +02:00
|
|
|
r_serv.delete('ail:current_background_script')
|
|
|
|
r_serv.delete('ail:current_background_script_stat')
|
|
|
|
r_serv.delete('ail:current_background_update')
|
2019-11-05 16:44:10 +01:00
|
|
|
|
2019-11-08 16:00:42 +01:00
|
|
|
if r_serv.get('ail:current_background_update') == 'v2.4':
|
|
|
|
r_serv.delete('ail:update_error')
|
|
|
|
r_serv.set('ail:update_in_progress', 'v2.4')
|
|
|
|
r_serv.set('ail:current_background_update', 'v2.4')
|
|
|
|
r_serv.set('ail:current_background_script', 'domain update')
|
|
|
|
|
|
|
|
update_file = os.path.join(os.environ['AIL_HOME'], 'update', 'v2.4', 'Update_domain.py')
|
|
|
|
process = subprocess.run(['python' ,update_file])
|
|
|
|
|
|
|
|
|
2019-11-11 14:54:12 +01:00
|
|
|
if int(r_serv_onion.scard('domain_update_v2.4')) != 0:
|
2019-11-08 16:00:42 +01:00
|
|
|
r_serv.set('ail:update_error', 'Update v2.4 Failed, please relaunch the bin/update-background.py script')
|
|
|
|
else:
|
|
|
|
r_serv.delete('ail:update_in_progress')
|
|
|
|
r_serv.delete('ail:current_background_script')
|
|
|
|
r_serv.delete('ail:current_background_script_stat')
|
|
|
|
r_serv.delete('ail:current_background_update')
|
|
|
|
r_serv.delete('update:nb_elem_to_convert')
|
|
|
|
r_serv.delete('update:nb_elem_converted')
|
2019-12-17 15:13:36 +01:00
|
|
|
|
|
|
|
if r_serv.sismember('ail:to_update', 'v2.6'):
|
|
|
|
new_version = 'v2.6'
|
|
|
|
r_serv.delete('ail:update_error')
|
|
|
|
r_serv.delete('ail:current_background_script_stat')
|
|
|
|
r_serv.set('ail:update_in_progress', new_version)
|
|
|
|
r_serv.set('ail:current_background_update', new_version)
|
|
|
|
r_serv.set('ail:current_background_script', 'screenshot update')
|
|
|
|
|
|
|
|
update_file = os.path.join(os.environ['AIL_HOME'], 'update', new_version, 'Update_screenshots.py')
|
|
|
|
process = subprocess.run(['python' ,update_file])
|
|
|
|
|
2020-01-09 15:07:51 +01:00
|
|
|
update_progress = r_serv.get('ail:current_background_script_stat')
|
2019-12-17 15:13:36 +01:00
|
|
|
if update_progress:
|
|
|
|
if int(update_progress) == 100:
|
|
|
|
r_serv.delete('ail:update_in_progress')
|
|
|
|
r_serv.delete('ail:current_background_script')
|
|
|
|
r_serv.delete('ail:current_background_script_stat')
|
|
|
|
r_serv.delete('ail:current_background_update')
|
2020-01-09 15:07:51 +01:00
|
|
|
r_serv.srem('ail:to_update', new_version)
|
|
|
|
|
|
|
|
elif r_serv.sismember('ail:to_update', 'v2.7'):
|
|
|
|
new_version = 'v2.7'
|
|
|
|
r_serv.delete('ail:update_error')
|
|
|
|
r_serv.delete('ail:current_background_script_stat')
|
|
|
|
r_serv.set('ail:update_in_progress', new_version)
|
|
|
|
r_serv.set('ail:current_background_update', new_version)
|
|
|
|
r_serv.set('ail:current_background_script', 'domain tags update')
|
|
|
|
|
|
|
|
update_file = os.path.join(os.environ['AIL_HOME'], 'update', new_version, 'Update_domain_tags.py')
|
|
|
|
process = subprocess.run(['python' ,update_file])
|
|
|
|
|
|
|
|
update_progress = r_serv.get('ail:current_background_script_stat')
|
|
|
|
if update_progress:
|
|
|
|
if int(update_progress) == 100:
|
|
|
|
r_serv.delete('ail:update_in_progress')
|
|
|
|
r_serv.delete('ail:current_background_script')
|
|
|
|
r_serv.delete('ail:current_background_script_stat')
|
|
|
|
r_serv.delete('ail:current_background_update')
|
|
|
|
r_serv.srem('ail:to_update', new_version)
|