From 98be0c2bfe58087d865e5426b3e749f169af3ce1 Mon Sep 17 00:00:00 2001 From: Dan Mosedale Date: Wed, 8 Aug 2018 17:51:30 -0700 Subject: [PATCH] Bug 1481693 - Factor out try_to_create_state_dir from mach_bootstrap, r=gps MozReview-Commit-ID: H6DhV56n3Cc --- python/mozboot/mozboot/bootstrap.py | 42 ++++++++++++++++------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/python/mozboot/mozboot/bootstrap.py b/python/mozboot/mozboot/bootstrap.py index 58de2c335c3f..09f03ce53dea 100644 --- a/python/mozboot/mozboot/bootstrap.py +++ b/python/mozboot/mozboot/bootstrap.py @@ -264,6 +264,28 @@ class Bootstrapper(object): continue return '' + # The state directory code is largely duplicated from mach_bootstrap.py. + # We can't easily import mach_bootstrap.py because the bootstrapper may + # run in self-contained mode and only the files in this directory will + # be available. We /could/ refactor parts of mach_bootstrap.py to be + # part of this directory to avoid the code duplication. + def try_to_create_state_dir(self): + state_dir, _ = get_state_dir() + + if not os.path.exists(state_dir): + if not self.instance.no_interactive: + choice = self.instance.prompt_int( + prompt=STATE_DIR_INFO.format(statedir=state_dir), + low=1, + high=2) + + if choice == 1: + print('Creating global state directory: %s' % state_dir) + os.makedirs(state_dir, mode=0o770) + + state_dir_available = os.path.exists(state_dir) + return state_dir_available, state_dir + def bootstrap(self): if self.choice is None: # Like ['1. Firefox for Desktop', '2. Firefox for Android Artifact Mode', ...]. @@ -286,25 +308,7 @@ class Bootstrapper(object): self.instance.ensure_python_modern() self.instance.ensure_rust_modern() - # The state directory code is largely duplicated from mach_bootstrap.py. - # We can't easily import mach_bootstrap.py because the bootstrapper may - # run in self-contained mode and only the files in this directory will - # be available. We /could/ refactor parts of mach_bootstrap.py to be - # part of this directory to avoid the code duplication. - state_dir, _ = get_state_dir() - - if not os.path.exists(state_dir): - if not self.instance.no_interactive: - choice = self.instance.prompt_int( - prompt=STATE_DIR_INFO.format(statedir=state_dir), - low=1, - high=2) - - if choice == 1: - print('Creating global state directory: %s' % state_dir) - os.makedirs(state_dir, mode=0o770) - - state_dir_available = os.path.exists(state_dir) + state_dir_available, state_dir = self.try_to_create_state_dir() # We need to enable the loading of hgrc in case extensions are # required to open the repo.