Commit d9671789 authored by Xavier Thompson's avatar Xavier Thompson

software/theia: Fix broken embedded URLs

Provide a script to fix the embedded SR URLs
broken by the upgrade to Theia tag 1.0.211.
parent 9a2fc120
# This is a script to fix embedded paths supplied and requested in theia proxy
# that were broken by upgrade to tag 1.0.211
import os
import logging
import sqlite3
import sys
if bytes is str:
from urlparse import urlparse
else:
from urllib.parse import urlparse
theia_url = "https://lab.nexedi.com/nexedi/slapos/raw/1.0.211/software/theia/software.cfg"
home = os.path.normpath(sys.argv[1])
logging.basicConfig(format='%(message)s', level=logging.INFO)
# Assert that ~/software_release/buildout.cfg is the expected theia version
buildout_cfg = os.path.join(home, 'software_release', 'buildout.cfg')
with open(buildout_cfg) as f:
assert(theia_url in f.read())
# Assert that the proxy exists
proxy_db = os.path.join(home, 'srv', 'runner', 'var', 'proxy.db')
assert(os.path.exists(proxy_db))
try:
con = sqlite3.connect(proxy_db)
cur = con.execute('SELECT * from local_software_release_root15')
local_sr_root, = cur.fetchone()
# Assert that the local sr root path is the partition root
assert(local_sr_root == home)
def fix_url(url):
if not url:
return url
logging.info('\nURL: %s', url)
if urlparse(url)[0]:
logging.info(' do not fix because it is not a path')
return url
rel = os.path.relpath(url, local_sr_root)
if rel.startswith(os.pardir + os.sep):
logging.info(' do not fix because it is not under %s', home)
return url
new = os.path.join(os.sep, rel)
if os.path.relpath(new, home).startswith(os.pardir + os.sep):
logging.info(' do not fix because without the prefix it is not under %s', home)
return url
if not os.path.isfile(new) and os.path.isfile(url):
logging.info(' do not fix because it exists but without the prefix it does not')
return url
logging.info(' fix into %s', new)
return new
con.create_function('fix_url', 1, fix_url)
con.execute('UPDATE software15 SET url=fix_url(url)')
con.execute('UPDATE partition15 SET software_release=fix_url(software_release)')
con.commit()
finally:
con.close()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment