Last active
March 10, 2019 00:57
-
-
Save alexboche/d1d03e553b93c4149a2c16682cc778d0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from dragonfly import ActionBase | |
from dragonfly import Context | |
from dragonfly import Text | |
class PositionalTexter(object): | |
def __init__(self, func, extra=()): | |
self.func = func | |
self.extra = extra | |
self._str = func.__name__ | |
def execute(self, data): | |
# argument = (data[self.extra[0]], data[self.extra[1]]) | |
arguments = [data[argument_name] for argument_name in self.extra] | |
if not arguments: | |
return | |
result = self.func(*arguments) | |
Text(str(result)).execute() | |
class MultiAppContext(Context): | |
# ---------------------------------------------------------------------- | |
# Initialization methods. \sqrt %(symbol)s | |
def __init__(self, relevant_apps=None, title=None, exclude=False): | |
super(MultiAppContext, self) | |
if relevant_apps is None: | |
self._relevant_apps = None | |
else: | |
self._relevant_apps = set(relevant_apps) | |
self._title = title | |
self._exclude = bool(exclude) | |
self._str = "%s, %s, %s" % (self._relevant_apps, self._title, | |
self._exclude) | |
# ---------------------------------------------------------------------- | |
# Matching methods. | |
def matches(self, executable, title, handle): | |
executable = executable.lower() | |
if not self._relevant_apps: | |
# If no apps are relevant, then all apps will match. | |
if self._log_match: | |
self._log_match.debug("%s: Match." % self) | |
return True | |
for app in self._relevant_apps: | |
if app.lower() in executable: | |
if self._log_match: | |
self._log_match.debug("%s: Match." % self) | |
return True | |
return False | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment