jamurai¶
Jinja wrapper for file and directory transformation and injection
As a single content:
import os
import yaml
import jamurai
with open("/tmp/from.txt", "w") as from_file:
from_file.write("{{ foo }}")
content = {
"source": "from.txt",
"destination": "to.txt"
}
values = {
"foo": "bar"
}
jamurai.build(content, values, "/tmp")
with open("/tmp/to.txt", "r") as to_file:
data = to_file.read()
data
# "bar"
For multiple content:
machine = jamurai.Machine("/tmp")
with open("/tmp/this.txt", "w") as from_file:
from_file.write("{{ this }}")
with open("/tmp/that.txt", "w") as from_file:
from_file.write("{{ that }}")
contents = [
{
"source": "this.txt",
"destination": "these.txt"
},
{
"source": "that.txt",
"destination": "those.txt"
}
]
values = {
"this": "yin",
"that": "yang"
}
for content in contents:
machine.build(content, values)
with open("/tmp/these.txt", "r") as to_file:
data = to_file.read()
data
# "yin"
with open("/tmp/those.txt", "r") as to_file:
data = to_file.read()
data
# "yang"
Look at the content docs at the ‘CnC Forge https://github.com/gaf3/cnc-forge/blob/main/Output.md#content’_
The only difference is the base is the same direcctory unlike transforming from one repo to enother.
- jamurai.build(content, values, base='', skip=None, inject='jamurai', engine=None)¶
Builds a content block
- Parameters:
content (dict) – What to transform, so
values (dict) – Yaes engine to use instead of the default
base (yaes.Engine) – base directory to transform files
skip (list) – list of files to skip for processing
inject – keyword to inject text at (text:)
engine – Yaes engine to use instead of the default
Usage
To process a single content block:
import os import yaml import jamurai with open("/tmp/from.txt", "w") as from_file: from_file.write("{{ foo }}") content = { "source": "from.txt", "destination": "to.txt" } values = { "foo": "bar" } jamurai.build(content, values, "/tmp") with open("/tmp/to.txt", "r") as to_file: data = to_file.read() data # "bar"
- class jamurai.Machine(base='', skip=None, inject='jamurai', engine=None)¶
Class for Jinja wrapper for file and directory transformation and injection
- Parameters:
base (yaes.Engine) – base directory to transform files
skip (list) – list of files to skip for processing
inject – keyword to inject text at (text:)
engine – Yaes engine to use instead of the default
- base: str¶
base directory to transform files
- engine: yaes.Engine¶
Yaes engine to use
- inject: str¶
keyword to inject text at (text:)
- skip: list¶
list of files to skip for processing
- build(content, values)¶
Builds a content block
- Parameters:
content (dict) – What to transform, so
values (dict) – Yaes engine to use instead of the default
Usage
For multiple content:
import os import yaml import jamurai machine = jamurai.Machine("/tmp") with open("/tmp/this.txt", "w") as from_file: from_file.write("{{ this }}") with open("/tmp/that.txt", "w") as from_file: from_file.write("{{ that }}") contents = [ { "source": "this.txt", "destination": "these.txt" }, { "source": "that.txt", "destination": "those.txt" } ] values = { "this": "yin", "that": "yang" } for content in contents: machine.build(content, values) with open("/tmp/these.txt", "r") as to_file: data = to_file.read() data # "yin" with open("/tmp/those.txt", "r") as to_file: data = to_file.read() data # "yang"
- copy(content)¶
Copies the content of source to desintation unchanged
- Parameters:
content – content
- craft(content, values)¶
Craft changes, the actual work of creating desitnations from sources
- Parameters:
content – content
values – values
- destination(content, data=None, path=False)¶
Retrieve or store the content of a destination file
- Parameters:
content – content
data – data
path – path
- directory(content, values)¶
Craft a directory
- Parameters:
content – content
values – values
- classmethod exclude(content)¶
Exclude content from being copied from source to destination based on pattern
- Parameters:
content – content
- file(content, values)¶
Craft a file
- Parameters:
content – content
values – values
- static json(source, destination, location, remove)¶
Inserts destination into source at location if not present
- Parameters:
source – source
destination – destination
location – location
remove – remove
- mode(content)¶
Have the desination mode match the source mode
- Parameters:
content – content
- classmethod place(content)¶
Get either source of destination
- Parameters:
content – content
- places(content, values)¶
Expands a place to sources or desintations
- Parameters:
content – content
values – values
- static placing(content)¶
Get either source of destination
- Parameters:
content – content
- static preserve(content)¶
Preserve content as is without transformation based on pattern
- Parameters:
content – content
- relative(path)¶
Gets the relative path based on base and whether source or destnation
- Parameters:
path – path
- remove(content)¶
Removes the content of desintation
- Parameters:
content – content
- source(content, path=False)¶
Retrieves the content of a source file
- Parameters:
content – content
path – path
- text(source, destination, location, remove)¶
Inserts destination into source at location if not present
- Parameters:
source – source
destination – destination
location – location
remove – remove
- static yaml(source, destination, location, remove)¶
Inserts destination into source at location if not present
- Parameters:
source – source
destination – destination
location – location
remove – remove