diff --git a/data/applications.xml b/data/applications.xml
index 33e1955..b225645 100644
--- a/data/applications.xml
+++ b/data/applications.xml
@@ -46,6 +46,19 @@
-
-
-
+ - Helpers:
+ - Obviously you can specify the helper and set the command for restarting
+ - the application. I.e. helper="myapp restart".
+ - What is actually more interesting is that you can add various arguments.
+ -
+ -
+ -
+ - Helper arguments:
+ - * {PNAME} - Name of the process
+ - * {NAME} - Name of the application
+ - * {PID} - Process ID
+ - * {EXE} - Process binary
+ -
-->
diff --git a/tracer/resources/applications.py b/tracer/resources/applications.py
index 078a112..485d4bc 100644
--- a/tracer/resources/applications.py
+++ b/tracer/resources/applications.py
@@ -25,6 +25,7 @@
from tracer.resources.lang import _
from tracer.resources.processes import Processes
import os
+import re
class Applications:
@@ -174,6 +175,7 @@ def update(self, values):
values = values._attributes
self._attributes.update(values)
+ # @TODO rename to helper_format
@property
def helper(self):
helper = self._attributes["helper"]
@@ -182,6 +184,36 @@ def helper(self):
helper = "sudo " + helper
return helper
+ @property
+ def helper_contains_formating(self):
+ return bool(re.search("\{.*\}", self.helper))
+
+ @property
+ def helper_contains_name(self):
+ return bool(re.search("\{NAME\}", self.helper))
+
+ @property
+ def helpers(self):
+ """
+ Return the list of helpers which describes how to restart the application.
+ When no ``helper_format`` was described, empty list will be returned.
+ If ``helper_format`` contains process specific arguments such a {PID}, etc.
+ list will contain helper for every application instance.
+ In other cases, there will be just one helper in the list.
+ """
+ helpers = []
+ if not self.helper_contains_formating:
+ helpers.append(self.helper)
+ else:
+ for process in self.instances:
+ helpers.append(self.helper.format(
+ NAME=self.name,
+ PNAME=process.name,
+ PID=process.pid,
+ EXE=process.exe,
+ ))
+ return helpers
+
@property
def instances(self):
return Processes.all().filtered(lambda process: process.name == self.name)
diff --git a/tracer/views/default.py b/tracer/views/default.py
index 8d438f3..9c5dae8 100644
--- a/tracer/views/default.py
+++ b/tracer/views/default.py
@@ -1,6 +1,7 @@
from . import View
from tracer.resources.lang import _
from tracer.views.note_for_hidden import NoteForHiddenView
+import re
class DefaultView(View):
@@ -16,7 +17,10 @@ def render(self):
if len(with_helpers):
print " " + _("restart_using_helpers")
for application in with_helpers.sorted("helper"):
- print " " + application.helper
+ 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 ""
diff --git a/tracer/views/helper.py b/tracer/views/helper.py
index 6fc51b2..71d7d92 100644
--- a/tracer/views/helper.py
+++ b/tracer/views/helper.py
@@ -44,7 +44,8 @@ def render(self):
if not self.args.affected_by:
print " {app_name} does not need restarting".format(app_name=self.args.application.name)
else:
- print " {how_to_restart}".format(how_to_restart=self.args.application.helper)
+ for helper in self.args.application.helpers:
+ print " {how_to_restart}".format(how_to_restart=helper)
def render_affected_by(self):