-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Print blocks of session and static applications when `-a`; Fix #23
- Loading branch information
Showing
3 changed files
with
81 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from . import View | ||
import sys | ||
|
||
print_ = sys.stdout.write | ||
|
||
|
||
class BlocksView(View): | ||
|
||
""" | ||
Assign ``blocks`` with this list | ||
[ | ||
{ | ||
"title": "...", | ||
"content": "some text", | ||
}, | ||
... | ||
] | ||
""" | ||
|
||
def render(self): | ||
for index, block in enumerate(self.args.blocks): | ||
if block["content"]: | ||
if "title" in block: | ||
print block["title"] | ||
print_(block["content"]) | ||
|
||
if self.next(index): | ||
print "" | ||
|
||
def next(self, index): | ||
"""Return True if there is any nonempty block after given index""" | ||
for block in self.args.blocks[index+1:]: | ||
if block["content"]: | ||
return True | ||
return False |
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 |
---|---|---|
@@ -1,45 +1,64 @@ | ||
from . import View | ||
from tracer.resources.lang import _ | ||
from tracer.resources.applications import Applications | ||
from tracer.views.note_for_hidden import NoteForHiddenView | ||
from tracer.views.blocks import BlocksView | ||
import sys | ||
import StringIO | ||
import re | ||
|
||
|
||
class DefaultView(View): | ||
def render(self): | ||
|
||
with_helpers = self.args.applications.with_helpers() | ||
without_helpers = self.args.applications.without_helpers() | ||
note = self.args.session_count or self.args.static_count | ||
|
||
if with_helpers or without_helpers: | ||
print _("you_should_restart") | ||
|
||
if len(with_helpers): | ||
print " " + _("restart_using_helpers") | ||
for application in with_helpers.sorted("helper"): | ||
def with_helpers_content(): | ||
content = "" | ||
types = [Applications.TYPES["SESSION"], Applications.TYPES["STATIC"]] | ||
applications = self.args.applications.with_helpers().exclude_types(types).sorted("helper") | ||
for application in applications: | ||
helpers = "; ".join(application.helpers) | ||
if application.helper_contains_formating and not application.helper_contains_name: | ||
helpers += " # {}".format(application.name) | ||
print " " + helpers | ||
|
||
if without_helpers: | ||
print "" | ||
|
||
if len(without_helpers): | ||
print " " + _("restart_manually") | ||
for application in without_helpers.sorted("name"): | ||
print " " + application.name | ||
content += " " + helpers + "\n" | ||
return content | ||
|
||
if note: | ||
print "" | ||
def without_helpers_content(): | ||
content = "" | ||
for application in self.args.applications.without_helpers().sorted("name"): | ||
content += " " + application.name + "\n" | ||
return content | ||
|
||
if with_helpers and not without_helpers and note: | ||
print "" | ||
def unrestartable_content(app_type): | ||
content = "" | ||
applications = self.args.applications.with_helpers().filter_types([app_type]).sorted("name") | ||
for application in applications: | ||
content += " " + application.name + "\n" | ||
return content | ||
|
||
if not self.args.args.all: | ||
def note_content(): | ||
content = StringIO.StringIO() | ||
sys.stdout = content | ||
view = NoteForHiddenView() | ||
view.assign("args", self.args.args) | ||
view.assign("total_count", self.args.total_count) | ||
view.assign("session_count", self.args.session_count) | ||
view.assign("static_count", self.args.static_count) | ||
view.render() | ||
sys.stdout = sys.__stdout__ | ||
return content.getvalue() | ||
|
||
blocks = [ | ||
{"title": " " + _("restart_using_helpers"), "content": with_helpers_content()}, | ||
{"title": " " + _("restart_manually"), "content": without_helpers_content()}, | ||
] | ||
|
||
if self.args.args.all: | ||
blocks.append({"title": " " + _("restart_session"), "content": unrestartable_content(Applications.TYPES["SESSION"])}) | ||
blocks.append({"title": " " + _("restart_rebooting"), "content": unrestartable_content(Applications.TYPES["STATIC"])}) | ||
else: | ||
blocks.append({"content": note_content()}) | ||
|
||
print _("you_should_restart") | ||
view = BlocksView() | ||
view.assign("blocks", blocks) | ||
view.render() |