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
|
|
|
|
import configparser
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
|
|
configfile = os.path.join(os.environ['AIL_BIN'], 'packages/config.cfg')
|
|
|
|
if not os.path.exists(configfile):
|
|
|
|
raise Exception('Unable to find the configuration file. \
|
|
|
|
Did you set environment variables? \
|
|
|
|
Or activate the virtualenv.')
|
|
|
|
cfg = configparser.ConfigParser()
|
|
|
|
cfg.read(configfile)
|
|
|
|
|
|
|
|
r_serv = redis.StrictRedis(
|
|
|
|
host=cfg.get("ARDB_DB", "host"),
|
|
|
|
port=cfg.getint("ARDB_DB", "port"),
|
|
|
|
db=cfg.getint("ARDB_DB", "db"),
|
|
|
|
decode_responses=True)
|
|
|
|
|
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')
|