Package: aina
ainaAina is a general-purpose stream processing framework. It includes
a simple but powerful templating system which powers a versitle command
line utility.NOTE: This is new code. Master is in flux and docs are lacking,
but it is in a point where it could be useful to someone. If
it is useful to you, help us get to 1.0.0. You can start by reading
the contributing guide athttps://github.com/ilovetux/aina/CONTRIBUTING.rst.Free software: GNU General Public License v3Documentation:https://aina.readthedocs.io.FeaturesSimple, Powerful templating systemCommand line utilitiesAll the power of PythonNo hacks or magicApproachable source codeTestedTODO: Web UITODO: Many default use cases coveredTODO: –no-overwrite optionInstallingYou can install the latest stable version with the following command:$ pip install ainaAlternately, to clone the latest development version:$ git clone https://github.com/ilovetux/aina
$ cd aina
# Optional
$ python setup.py test
$ pip install .ConceptsThe built-in templating engine is very simple, it consists
of a namespace and a template. The template is rendered within
the context of the namespace.Rendering involves two stages:scanning the template for strings matching the pattern{%<Source>%}where<Source>is Python source code which is executed (exec)
within the context of the namespace. During execution, stdout is
captured. After execution,{%<Source>%}is replaced with a string
containing the output.scanning the remaining output for strings matching the pattern{{<Expression>}}where<Expression>is a Python expression which
is replaced with the value to which it evaluates (eval)As an example, let’s look at the following template:{%
me = "iLoveTux"
name = "Bill"
age = 35
%}
hello {{name}}:

I heard that you just turned {{str(age)}}. Congratulations!

Sincerely:

{% print(me) %}If this were rendered, the output would be as follows:Hello Bill,

I heard that you just turned 35. Congratulations!

Sincerely:

iLoveTuxThis concept is applied to a variety of use cases and embodied in the form of
command line utilities which cover a number of common use cases.UsageAina can be used directly from within Python, like so:from aina import render

namespace = {"foo": "bar"}
template = "The value of foo is {{foo}}"

result = render(template, namespace)This usage has first-class support, but a much handier solution is to use
the provided CLI.The command line utility, aina, can be run in two modes:Streaming mode: Data is streamed through and used to populate templatesDocument mode: Render files src and write the results to dstStreaming modeStreaming mode runs in the following manner:Accept a list offilenames(wildcards are accepted), which defaults to stdinAt this point any expressions passed to–beginsare executedThe files specified are processed in orderAny expressions passed to–begin-filesare executedThe data from the current file is read line-by-lineAny statements passed to–testsare evaluatedIff all tests pass, the following process is performed.Any expressions passed to–begin-linesare executedAny templates are rendered through the python logging systemAny expressions passed to–end-linesare executedAny expressions passed to–end-filesare executedAny expressions passed to–endsare executedBelow are a few examples. See the documentation for more details:# Like grep
$ aina stream --test "'error' in line.lower()" --template "{{line}}" *.log

# Like wc -l
$ aina stream --end-files "print(fnr, filename)" *.log

# Like wc -wl
$ aina stream --begins "words=0" --begin-lines "words += nf" --end-files "print(words, fnr, filename)"

# Find all numbers "\d+" for each line
$ aina stream --begins "import re" --begin-lines "print(re.findall(r'\d+', line))" *.log

# Run an XPath
$ aina stream --begins "from lxml import etree" --begin-lines "tree = etree.fromstring(line)" --templates "{{"\n".join(tree.xpath("./*"))}}"Please see the documentation for more as well as trying:$ aina stream --helpImportant Note:If anything passed to any of the hooks is determined to exist byos.path.existsthen it will be read and executed as if that text was passed in on the CLI. This
is useful for quickly solving character escaping issues.Document modeDocument mode renders one or more files and/or directoriessrcto
another locationdst. It is used like this:$ aina doc <src> <dst>There are options to control behavior, but the gist of it is:if src is a fileif dst is a filename, src is rendered and written to dstif dst is a directory, src is rendered and written to a file in dst with the same basename as srcif src is a directorydst must be a directory and every file in src is rendered into a file in dst with the same basename as the file from srcIf–recursiveis specified, the subdirectories will be reproduced in dstSome important notes:If–intervalis passed an integer value, the program will sleep for that many seconds and check for changes to your templates (based on the file’s mtime) in which case they will be re-renderedUse CasesStreaming mode is great for processing incoming log files withtail –follow=nameor for ad-hoc analysis of text files.Document mode is incredibly useful for a powerful configuration templating
system. The–intervaloption is incredibly useful as it will only re-render
on a file change, so is great for developing your templates as you can view
the results in near-real-time.Document mode is also useful for near-real-time rendering of static
web resources such as charts, tables, dashboards and more.If you find any more use cases, please open an issue or pull request to add it
here and in the wikiCreditsAuthor: iLoveTux
This package was created withCookiecutterand theaudreyr/cookiecutter-pypackageproject template.History0.1.1 (2018-07-05)Improved test-suiteExecution blocks are now replaced with whatever is sent to stdoutaina docnow respects the–intervalargumentaina doc –intervalis fixed and now only re-renders templates which have changedaina docwith–recursivenow processes files in a top-down mannerLots of bug fixesImproved documentationvalues of expressions are now automatically coerced into stringsDrop support for Python 3.4 and add support for Python 3.7Improved logging0.1.0 (2018-06-20)First release on PyPI.