Examples & More
The Fire Guide Group Example
The Fire Guide has an example of grouping. With FiredUp this grouping is even improved upon:
Given a few alterations, the same and a lot more is possible:
from fired_up import FiredUp, Group
class IngestionStage(Group):
def run(self):
return 'Ingesting! Nom nom nom...'
class DigestionStage(Group):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._volume = 1
def volume(self, new_volume):
self._volume = new_volume
def run(self):
return ' '.join(['Burp!'] * self._volume)
def status(self):
return 'Satiated.'
class Pipeline(FiredUp):
def run(self):
self.ingestion.run()
ingestion_output = self.paste()
self.digestion.run()
digestion_output = self.paste()
self.copy([ ingestion_output, digestion_output ])
return self
if __name__ == "__main__":
Pipeline(ingestion=IngestionStage, digestion=DigestionStage)
I’m not happy yet with the required changes, so improvements will be imminent ;-)
For now, it runs the same and offers improved chaining possibilities:
% python examples/fire-group.py ingestion run
Ingesting! Nom nom nom...
% python examples/fire-group.py digestion run
Burp!
% python examples/fire-group.py digestion status
Satiated.
% python examples/fire-group.py ingestion run then digestion run status
Satiated.
% python examples/fire-group.py --all ingestion run then digestion run status
Ingesting! Nom nom nom...
Burp!
Satiated.
% python examples/fire-group.py --all ingestion run then digestion volume 2 run status
Ingesting! Nom nom nom...
Burp! Burp!
Satiated.
Globals and Arguments
Besides the versioned clipboard, you can also use globals and pass arguments to the constructors of the Groups:
from fired_up import FiredUp, Group
class Left(Group):
def __init__(self, write, *args, **kwargs):
super().__init__(*args, **kwargs)
self._write = write
def write(self):
if self._write:
self._globals["message"] = "left was here"
def read(self):
print("left>", self._globals["message"])
class Right(Group):
def readwrite(self):
print("right>", self._globals["message"])
self._globals["message"] = "right was here too"
FiredUp(left=(Left, { "write" : True }), right=Right)
% python examples/globals.py left write then right readwrite then left read
right> left was here
left> right was here too
Simple Commands
Besides objects with commands and menus, you can also simply provide a function, which will be handled as a command:
from fired_up import FiredUp, __version__
def get_hello():
return "hello"
def get_version():
return __version__
FiredUp(hello=get_hello, version=get_version)
% python examples/version.py --all hello then version
hello
0.0.7
Public Functions and Output
Since FiredUp makes all public functions chainable, public functions that return some value can’t be used directly by other functions. To access the original return value one can use .paste() in a chaining way:
from fired_up import FiredUp, Group
class Test(Group):
def public1(self):
return "abc" # return value is "copied", self is returned
def public2(self):
print(self.public1().paste()) # returns the return value of public
def public3(self):
return self.public1() # returns self, which is "pasted" as last result
FiredUp(test=Test)
% python examples/public.py test public1
abc
% python examples/public.py test public2
abc
% python examples/public.py test public3
NAME
public.py test public3
SYNOPSIS
public.py test public3 GROUP | COMMAND
GROUPS
GROUP is one of the following:
globals
COMMANDS
COMMAND is one of the following:
copy
paste
public1
public2
public3
then