Skip to content

Instantly share code, notes, and snippets.

@alexboche
Last active March 10, 2019 00:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexboche/d1d03e553b93c4149a2c16682cc778d0 to your computer and use it in GitHub Desktop.
Save alexboche/d1d03e553b93c4149a2c16682cc778d0 to your computer and use it in GitHub Desktop.
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