Commit 40e8b1e7 authored by rgaudin's avatar rgaudin
Browse files

Log now includes full configuration, version and is timestamped

parent d0989075
2.0.1
* Changed cache directory name from `cache` to `kiwix-hotspot.cache`
* Better etcher log output on macOS
* Log now timestamped
* Log now includes full configuration and version
2.0
* Updated python dependencies
......
......@@ -24,19 +24,10 @@ for catalog in CATALOGS:
def run(machine, tags, extra_vars={}, secret_keys=[]):
""" run ansiblecube in given machine with specified tags and extra-vars """
# predefined defaults we want to superseed whichever in ansiblecube
ansible_vars = {
"installer_version": get_version_str(),
"mirror": mirror,
"catalogs": CATALOGS,
"kernel_version": get_content("raspbian_image").get("kernel_version"),
}
ansible_vars.update(extra_vars)
# save extra_vars to a file on guest
extra_vars_path = posixpath.join(ansiblecube_path, "extra_vars.json")
with tempfile.NamedTemporaryFile("w", delete=False) as fp:
json.dump(ansible_vars, fp, indent=4)
json.dump(extra_vars, fp, indent=4)
fp.close()
machine.put_file(fp.name, extra_vars_path)
os.unlink(fp.name)
......@@ -54,7 +45,7 @@ def run(machine, tags, extra_vars={}, secret_keys=[]):
machine._logger.std("ansiblecube extra_vars")
machine._logger.raw_std(
json.dumps(
{k: "****" if k in secret_keys else v for k, v in ansible_vars.items()},
{k: "****" if k in secret_keys else v for k, v in extra_vars.items()},
indent=4,
)
)
......@@ -142,6 +133,11 @@ def build_extra_vars(
""" extra-vars friendly format of the ansiblecube configuration """
extra_vars = {
# predefined defaults we want to superseed whichever in ansiblecube
"installer_version": get_version_str(),
"mirror": mirror,
"catalogs": CATALOGS,
"kernel_version": get_content("raspbian_image").get("kernel_version"),
"root_partition_size": root_partition_size,
"disk_size": disk_size,
"project_name": name,
......@@ -169,7 +165,7 @@ def build_extra_vars(
"admin_password": admin_account["pwd"],
}
)
secret_keys = ["admin_account", "admin_password"]
secret_keys = ["admin_password"]
else:
secret_keys = []
......
......@@ -5,7 +5,6 @@ import os
import re
import sys
import time
import shlex
import signal
import ctypes
import tempfile
......@@ -351,8 +350,8 @@ def get_etcher_command(image_fpath, device_fpath, logger, from_cli):
]
# escape etcher-cli and image paths on OSX (to accomodate oascript)
if sys.platform == "darwin":
cmd[0] = shlex.quote(cmd[0])
cmd[-1] = shlex.quote(cmd[-1])
cmd[0] = '"{}"'.format(cmd[0])
cmd[-1] = '"{}"'.format(cmd[-1])
# handle sudo or GUI alternative for linux and macOS
if sys.platform in ("linux", "darwin"):
......
......@@ -121,6 +121,7 @@ class Logger(ProgressHelper):
def main_thread_text(self, text, end="\n", tag=None):
if not isinstance(text, str):
text = str(text)
text = self._add_time(text)
text += end
text_iter = self.text_buffer.get_end_iter()
if tag is None:
......
......@@ -3,8 +3,8 @@
import os
import sys
import re
import time
import json
import shutil
import traceback
from datetime import datetime
......@@ -117,10 +117,49 @@ def run_installation(
else:
previous_loop_mode = None
base_image = get_content("hotspot_master_image")
# harmonize options
packages = [] if zim_install is None else zim_install
kalite_languages = [] if kalite is None else kalite
wikifundi_languages = [] if wikifundi is None else wikifundi
aflatoun_languages = ["fr", "en"] if aflatoun else []
if edupi_resources and not isremote(edupi_resources):
logger.step("Copying EduPi resources into cache")
shutil.copy(edupi_resources, cache_folder)
# prepare ansible options
ansible_options = {
"name": name,
"timezone": timezone,
"language": language,
"language_name": dict(data.ideascube_languages)[language],
"edupi": edupi,
"edupi_resources": edupi_resources,
"wikifundi_languages": wikifundi_languages,
"aflatoun_languages": aflatoun_languages,
"kalite_languages": kalite_languages,
"packages": packages,
"wifi_pwd": wifi_pwd,
"admin_account": admin_account,
"disk_size": size,
"root_partition_size": base_image.get("root_partition_size"),
}
extra_vars, secret_keys = ansiblecube.build_extra_vars(**ansible_options)
# display config in log
logger.step("Dumping Hotspot Configuration")
logger.raw_std(
json.dumps(
{k: "****" if k in secret_keys else v for k, v in extra_vars.items()},
indent=4,
)
)
# Download Base image
logger.stage("master")
logger.step("Retrieving base image file")
base_image = get_content("hotspot_master_image")
rf = download_content(base_image, logger, build_dir)
if not rf.successful:
logger.err("Failed to download base image.\n{e}".format(e=rf.exception))
......@@ -147,16 +186,6 @@ def run_installation(
if not test_mount_procedure(image_building_path, logger, True):
raise ValueError("thorough mount procedure failed")
# harmonize options
packages = [] if zim_install is None else zim_install
kalite_languages = [] if kalite is None else kalite
wikifundi_languages = [] if wikifundi is None else wikifundi
aflatoun_languages = ["fr", "en"] if aflatoun else []
if edupi_resources and not isremote(edupi_resources):
logger.step("Copying EduPi resources into cache")
shutil.copy(edupi_resources, cache_folder)
# collection contains both downloads and processing callbacks
# for all requested contents
collection = get_collection(
......@@ -246,25 +275,6 @@ def run_installation(
emulator.resize_image(size)
# prepare ansible options
ansible_options = {
"name": name,
"timezone": timezone,
"language": language,
"language_name": dict(data.ideascube_languages)[language],
"edupi": edupi,
"edupi_resources": edupi_resources,
"wikifundi_languages": wikifundi_languages,
"aflatoun_languages": aflatoun_languages,
"kalite_languages": kalite_languages,
"packages": packages,
"wifi_pwd": wifi_pwd,
"admin_account": admin_account,
"disk_size": emulator.get_image_size(),
"root_partition_size": base_image.get("root_partition_size"),
}
extra_vars, secret_keys = ansiblecube.build_extra_vars(**ansible_options)
# Run emulation
logger.step("Starting-up VM")
with emulator.run(cancel_event) as emulation:
......
......@@ -66,6 +66,12 @@ class ProgressHelper(object):
progress percentage is kept by stage (0 to 1).
total percentage is calculated using current stage and its progress"""
@staticmethod
def _add_time(text):
return "{time} {text}".format(
time=datetime.datetime.now().strftime("[%X]"), text=text
)
def __init__(self):
self.reset()
......@@ -389,7 +395,9 @@ class CLILogger(ProgressHelper):
def p(self, text, color=None, end=None, flush=False):
if color is not None and sys.platform != 32:
text = "\033[00;{col}m{text}\033[00m".format(col=color, text=text)
text = "\033[00;{col}m{text}\033[00m".format(
col=color, text=self._add_time(text)
)
print(text, end=end, flush=flush)
def complete(self):
......
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