Prefill was not working outside of dry-run
This commit is contained in:
parent
887d63caf0
commit
a264fdafbc
|
@ -51,6 +51,10 @@ def make_client_args_parser():
|
||||||
parser.add_argument('--socket')
|
parser.add_argument('--socket')
|
||||||
parser.add_argument('--answers')
|
parser.add_argument('--answers')
|
||||||
parser.add_argument('--server-pid')
|
parser.add_argument('--server-pid')
|
||||||
|
parser.add_argument('--prefill',
|
||||||
|
dest='prefill',
|
||||||
|
help='Prefills UI models with data provided in'
|
||||||
|
' a prefill.yaml file yet allowing overrides.')
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
|
@ -69,8 +73,8 @@ def main():
|
||||||
server_args = []
|
server_args = []
|
||||||
server_output_dir = "/var/log/installer"
|
server_output_dir = "/var/log/installer"
|
||||||
server_state_file = "/run/subiquity/server-state"
|
server_state_file = "/run/subiquity/server-state"
|
||||||
if '--dry-run' in args:
|
|
||||||
opts, unknown = parser.parse_known_args(args)
|
opts, unknown = parser.parse_known_args(args)
|
||||||
|
if '--dry-run' in args:
|
||||||
server_state_file = ".subiquity/run/subiquity/server-state"
|
server_state_file = ".subiquity/run/subiquity/server-state"
|
||||||
if opts.socket is None:
|
if opts.socket is None:
|
||||||
need_start_server = True
|
need_start_server = True
|
||||||
|
@ -78,14 +82,14 @@ def main():
|
||||||
sock_path = os.path.join(server_output_dir, 'socket')
|
sock_path = os.path.join(server_output_dir, 'socket')
|
||||||
opts.socket = sock_path
|
opts.socket = sock_path
|
||||||
server_args = ['--dry-run', '--socket=' + sock_path] + unknown
|
server_args = ['--dry-run', '--socket=' + sock_path] + unknown
|
||||||
else:
|
|
||||||
opts = parser.parse_args(args)
|
elif opts.socket is None:
|
||||||
else:
|
|
||||||
opts = parser.parse_args(args)
|
|
||||||
if opts.socket is None:
|
|
||||||
need_start_server = True
|
need_start_server = True
|
||||||
opts.socket = '/run/subiquity/socket'
|
opts.socket = '/run/subiquity/socket'
|
||||||
|
|
||||||
|
if opts.prefill:
|
||||||
|
server_args += ['--prefill='+opts.prefill]
|
||||||
|
|
||||||
os.makedirs(server_output_dir, exist_ok=True)
|
os.makedirs(server_output_dir, exist_ok=True)
|
||||||
server_output = open(os.path.join(server_output_dir, 'server-output'), 'w')
|
server_output = open(os.path.join(server_output_dir, 'server-output'), 'w')
|
||||||
|
|
||||||
|
|
|
@ -14,9 +14,7 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
from subiquity.server.controllers.locale import LocaleController
|
from subiquity.server.controllers.locale import LocaleController
|
||||||
from subiquitycore.utils import arun_command
|
|
||||||
|
|
||||||
log = logging.getLogger('system_setup.server.controllers.locale')
|
log = logging.getLogger('system_setup.server.controllers.locale')
|
||||||
|
|
||||||
|
@ -32,62 +30,3 @@ class WSLLocaleController(LocaleController):
|
||||||
.format(self.model.selected_language))
|
.format(self.model.selected_language))
|
||||||
|
|
||||||
super().start()
|
super().start()
|
||||||
|
|
||||||
async def _run_locale_support_cmds(self, lang: str):
|
|
||||||
""" Final commands to be ran when a valid language is POST'ed. """
|
|
||||||
|
|
||||||
env = os.environ.copy()
|
|
||||||
# Ensure minimal console translation is enabled.
|
|
||||||
cmds = (["locale-gen"],
|
|
||||||
["update-locale", "LANG={}".format(lang)],
|
|
||||||
["bash", "-c", "\"apt", "install", "$(check-language-support",
|
|
||||||
"-l", lang[0:2], ")\""])
|
|
||||||
if self.app.opts.dry_run:
|
|
||||||
for cmd in cmds:
|
|
||||||
log.debug('Would run: ' + ' '.join(cmd))
|
|
||||||
else:
|
|
||||||
for cmd in cmds:
|
|
||||||
cp = await arun_command(cmd, env=env)
|
|
||||||
if cp.returncode:
|
|
||||||
log.debug('Command \"%s\" failed with return code %d',
|
|
||||||
cp.args, cp.returncode)
|
|
||||||
|
|
||||||
async def POST(self, data: str):
|
|
||||||
if data == self.autoinstall_default or data == os.environ.get("LANG"):
|
|
||||||
await super().POST(data)
|
|
||||||
return
|
|
||||||
|
|
||||||
fileContents: str
|
|
||||||
fname = "locale.gen"
|
|
||||||
env = os.environ.copy()
|
|
||||||
if self.app.opts.dry_run:
|
|
||||||
# For debug purposes.
|
|
||||||
fname = ".subiquity/" + fname
|
|
||||||
await arun_command(['cp', '/etc/locale.gen', '.subiquity/'],
|
|
||||||
env=env)
|
|
||||||
else:
|
|
||||||
fname = "/etc/" + fname
|
|
||||||
|
|
||||||
pendingWrite = False
|
|
||||||
with open(fname, "r") as localeGen:
|
|
||||||
# locale.gen is not so big.
|
|
||||||
fileContents = localeGen.read()
|
|
||||||
lineFound = fileContents.find(data)
|
|
||||||
if lineFound == -1:
|
|
||||||
# An unsupported locale coming from our UI is a bug.
|
|
||||||
raise AssertionError("Selected language {} not supported."
|
|
||||||
" Rolling back.".format(data))
|
|
||||||
|
|
||||||
commented = "# {}".format(data)
|
|
||||||
lineFound = fileContents.find(commented)
|
|
||||||
if lineFound != -1:
|
|
||||||
fileContents = fileContents.replace(commented, data)
|
|
||||||
pendingWrite = True
|
|
||||||
|
|
||||||
if pendingWrite:
|
|
||||||
with open(fname, "wt") as f:
|
|
||||||
f.write(fileContents)
|
|
||||||
|
|
||||||
# If we arrive here, data is a supported language.
|
|
||||||
await self._run_locale_support_cmds(data)
|
|
||||||
await super().POST(data)
|
|
||||||
|
|
Loading…
Reference in New Issue