This is to get rid of a little of the indentation in install.py and make it look a bit neater. --- pyanaconda/install.py | 20 ++++++++------------ pyanaconda/progress.py | 11 +++++++---- 2 files changed, 15 insertions(+), 16 deletions(-)
diff --git a/pyanaconda/install.py b/pyanaconda/install.py index 4f83a15..087bfa8 100644 --- a/pyanaconda/install.py +++ b/pyanaconda/install.py @@ -89,9 +89,8 @@ def doConfiguration(storage, payload, ksdata, instClass): ksdata.xconfig.execute(storage, ksdata, instClass) ksdata.skipx.execute(storage, ksdata, instClass)
- if willWriteNetwork: - with progress_report(_("Writing network configuration")): - ksdata.network.execute(storage, ksdata, instClass) + with progress_report(_("Writing network configuration"), cond=lambda: willWriteNetwork): + ksdata.network.execute(storage, ksdata, instClass)
# Creating users and groups requires some pre-configuration. with progress_report(_("Creating users")): @@ -115,9 +114,8 @@ def doConfiguration(storage, payload, ksdata, instClass): and (not ksdata.bootloader.disabled and ksdata.bootloader != "none"): writeBootLoader(storage, payload, instClass, ksdata)
- if willRunRealmd: - with progress_report(_("Joining realm: %s") % ksdata.realm.discovered): - ksdata.realm.execute(storage, ksdata, instClass) + with progress_report(_("Joining realm: %s") % ksdata.realm.discovered, cond=lambda: willRunRealmd): + ksdata.realm.execute(storage, ksdata, instClass)
with progress_report(_("Running post-installation scripts")): runPostScripts(ksdata.scripts) @@ -209,9 +207,8 @@ def doInstall(storage, payload, ksdata, instClass):
# Discover information about realms to join, # to determine additional packages - if willRunRealmd: - with progress_report(_("Discovering realm to join")): - ksdata.realm.setup() + with progress_report(_("Discovering realm to join"), cond=lambda: willRunRealmd): + ksdata.realm.setup()
# Check for additional packages ksdata.authconfig.setup() @@ -243,9 +240,8 @@ def doInstall(storage, payload, ksdata, instClass): payload.writeStorageLate()
# Do bootloader. - if willInstallBootloader: - with progress_report(_("Installing boot loader")): - writeBootLoader(storage, payload, instClass, ksdata) + with progress_report(_("Installing boot loader"), cond=lambda: willInstallBootloader): + writeBootLoader(storage, payload, instClass, ksdata)
with progress_report(_("Performing post-installation setup tasks")): payload.postInstall() diff --git a/pyanaconda/progress.py b/pyanaconda/progress.py index f1d20ad..4594361 100644 --- a/pyanaconda/progress.py +++ b/pyanaconda/progress.py @@ -43,11 +43,14 @@ progressQ.addMessage("quit", 1) # exit_code # Surround a block of code with progress updating. Before the code runs, the # message is updated so the user can tell what's about to take so long. # Afterwards, the progress bar is updated to reflect that the task is done. +# An optional conditional can be given, in which case it must pass for the +# block to be executed. @contextmanager -def progress_report(message): - progress_message(message) - yield - progress_step(message) +def progress_report(message, cond=None): + if not cond or cond(): + progress_message(message) + yield + progress_step(message)
def progress_message(message): progressQ.send_message(message)
On Thu, Jun 25, 2015 at 11:10:46AM -0400, Chris Lumens wrote:
This is to get rid of a little of the indentation in install.py and make it look a bit neater.
pyanaconda/install.py | 20 ++++++++------------ pyanaconda/progress.py | 11 +++++++---- 2 files changed, 15 insertions(+), 16 deletions(-)
Ack!
On 06/25/2015 11:10 AM, Chris Lumens wrote:
This is to get rid of a little of the indentation in install.py and make it look a bit neater.
pyanaconda/install.py | 20 ++++++++------------ pyanaconda/progress.py | 11 +++++++---- 2 files changed, 15 insertions(+), 16 deletions(-)
As much as I like how it looks, it doesn't work. progress_report now raises an exception if cond() is False since the generator doesn't yield, and there's the greater problem that the conditional needs to skip the statements inside the with when the condition is false and not just skip the progress portion.
But it's already pushed and you're out tomorrow so I guess I just volunteered to try to figure out something better.
On 06/25/2015 05:03 PM, David Shea wrote:
On 06/25/2015 11:10 AM, Chris Lumens wrote:
This is to get rid of a little of the indentation in install.py and make it look a bit neater.
pyanaconda/install.py | 20 ++++++++------------ pyanaconda/progress.py | 11 +++++++---- 2 files changed, 15 insertions(+), 16 deletions(-)
As much as I like how it looks, it doesn't work. progress_report now raises an exception if cond() is False since the generator doesn't yield, and there's the greater problem that the conditional needs to skip the statements inside the with when the condition is false and not just skip the progress portion.
But it's already pushed and you're out tomorrow so I guess I just volunteered to try to figure out something better.
To follow up a bit, there was an idea allow contextmanagers to skip the with statement body in PEP 0377, but it was rejected. I thought about converting progress_report into a decorator and just making all the with bodies separate functions, but the "Joining realm: %s" message makes that difficult.
I think the best thing to do to avoid making install.py more complicated is to just revert this commit.
anaconda-patches@lists.fedorahosted.org