forked from frappe/bench
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Each operation can be broken down to multiple jobs. For instance, the update operation can be broken down into: setting up bench dirs, env, backups, requirements, etc. Each step has a lot of output since Frappe requires a lot of complex stuff to be done as a pre-requisite. Bench tries to simplify a lot in a single command. Once, a step is completed, it's output is not really required. So, we can ignore it to reduce the noise. Here's where the `bench.cli.fancy` variable kicks in. Along with the refactored log and new step wrapper, it makes the above thing possible. At this point, there's no way to set this var from the end user...given I'm still developing this. In the later commits, the idea is to pass a flag similar to pip's --use-feature flag.
- Loading branch information
1 parent
3995b92
commit f117959
Showing
4 changed files
with
85 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# imports - standard imports | ||
import sys | ||
from io import StringIO | ||
|
||
# imports - third party imports | ||
import click | ||
|
||
|
||
class Capturing(list): | ||
""" | ||
Util to consume the stdout encompassed in it and push it to a list | ||
with Capturing() as output: | ||
subprocess.check_output("ls", shell=True) | ||
print(output) | ||
# ["b'Applications\\nDesktop\\nDocuments\\nDownloads\\n'"] | ||
""" | ||
|
||
def __enter__(self): | ||
self._stdout = sys.stdout | ||
sys.stdout = self._stringio = StringIO() | ||
return self | ||
|
||
def __exit__(self, *args): | ||
self.extend(self._stringio.getvalue().splitlines()) | ||
del self._stringio # free up some memory | ||
sys.stdout = self._stdout | ||
|
||
|
||
def step(title: str = None, success: str = None): | ||
"""Supposed to be wrapped around the smallest possible atomic step in a given operation. | ||
For instance, `building assets` is a step in the update operation. | ||
""" | ||
|
||
def innfn(fn): | ||
def wrapper_fn(*args, **kwargs): | ||
import bench.cli | ||
|
||
if bench.cli.from_command_line and bench.cli.fancy: | ||
kw = args[0].__dict__ | ||
|
||
_title = f"{click.style('⏼', fg='bright_yellow')} {title.format(**kw)}" | ||
click.secho(_title) | ||
|
||
retval = fn(*args) | ||
|
||
if bench.cli.from_command_line and bench.cli.fancy: | ||
click.clear() | ||
|
||
for l in bench.LOG_BUFFER: | ||
click.secho(l["message"], fg=l["color"]) | ||
|
||
_success = f"{click.style('✔', fg='green')} {success.format(**kw)}" | ||
click.echo(_success) | ||
|
||
bench.LOG_BUFFER.append( | ||
{"message": _success, "color": None,} | ||
) | ||
|
||
return retval | ||
|
||
return wrapper_fn | ||
|
||
return innfn |