This README provides a comprehensive guide to the project, including its features, installation steps and usage.
pyaml is a simple command-line tool written in C for parsing YAML files and retrieving values based on keys.
- Introduction
- Features
- Updates
- Dependencies
- Prerequisites
- Installation
- Uninstallation
- Usage
- Help
- Files
- Customize
- Examples
- Advantages
- License
pyaml is a lightweight and efficient C program for parsing YAML files. It enables the extraction of values based on specific keys and is therefore ideal for configuration management and automation scripts.
It also shows you the contents of your YAML files with syntax highlighting if you only pass the file name as an argument.
- Minimal Dependencies: Only requires the
libyamllibrary. - High Performance: Written in C for speed and efficiency.
- Ease of Use: Simple command-line interface for easy integration.
- Parse YAML files.
- Retrieve nested values using dot notation for keys.
- Syntax highlighting file content.
- Changeable color themes for syntax highlighting.
- supports the nested structure of embedded keywords
- distinguishes in the spelling of the keywords
-
hosted on GitHub
-
Version history control
-
Markdown Documentary
-
Installationroutine
-
runs on Raspberry
This release is currently in version:
Please refer to the changelog for all information on current changes.
You can view it here.
The libyaml library is required to compile this project. It can be installed as follows:
sudo apt-get update
sudo apt-get install libyaml-devsudo dnf install libyaml-develsudo pacman -S libyamlIn addition, pyaml uses the Python program pygmentize to output the file content with syntax highlighting.
Make sure that pygmentize is available on your system.
It can be installed as follows:
pip install PygmentsTo compile the C program, you need to have the GCC compiler installed on your system. Below are the instructions for installing GCC on different Linux distributions:
sudo apt-get update
sudo install gccsudo dnf install gccsudo pacman -S gccYou can use the following line with extended rights to perform a fully automated express installation as a shell script on Debian-based systems.
Check the source code for the express-installer shell script here, if you do not have enough trust to run the script with root privileges
curl -sSL https://gist.githubusercontent.com/AntiSecTech/79d34b3e5e049d37323c3267d136a4d5/raw/7bcfb55ff2b186f3d960eb7366497fc4025cd532/pyaml-deb_installer.sh -o pyaml-installer.sh && chmod +x ./pyaml-installer.sh && sudo ./pyaml-installer.shwget -q https://gist.githubusercontent.com/AntiSecTech/79d34b3e5e049d37323c3267d136a4d5/raw/7bcfb55ff2b186f3d960eb7366497fc4025cd532/pyaml-deb_installer.sh -O pyaml-installer.sh && chmod +x ./pyaml-installer.sh && sudo ./pyaml-installer.shor take the following steps for the classic route
git clone https://github.com/AntiSecTech/pyaml.git
cd pyamlmake compilesudo make installIf you do not install the program and only compile the shared library, you must create a link for the configuration file so that it can be read by the binary
sudo ln -s -r pyaml.yml /etcIf you have any further questions about the Make process, please refer to the source code of the Makefile.
cd pyaml
sudo make uninstall pyaml <file.yml> [<key>]
pyaml -v | --version
pyaml -h | --helpThe following options are available to help you use pyaml.
- Buildin documentation
- Manpage ( issue #2 )
- Online documentation on
github.com - Online documentation on
readthedocs.com
Buildin
pyaml --helpBuildin overview
| command | switch | argument | optional argument | result |
|---|---|---|---|---|
| pyaml | <filename> | <key> | outputs the current value of the key | |
| <filename> | displays the contents of the specified file using less |
|||
| -h | --help | displays this screen | |||
| -v | shows the current version number of the build in the short version | |||
| --version | shows the current version number of the build and the current release in the long version | |||
| --- | --- | --- | --- | --- |
| man | pyaml | displays the pyaml manpage in groff format |
||
| --- | --- | --- | --- | --- |
| make | has the same effect as make all |
|||
| make | all | compile | Compiles the program from the source code and generates the executable file | ||
| make | clean | removes only the executable file recursively | ||
| sudo make | install | Compiles the program from the source code and creates the executable file which is then copied to the local folder for binary files | ||
| sudo make | uninstall | only removes the executable file from the local folder for binary files recursively |
Manpage
To open the manual, use the following command:
man pyamlGitHub
Read the documentation carefully.
https://github.com/AntiSecTech/pyaml/blob/main/README.md
ReadTheDocs
- This function is not yet available!
https://pyaml.readthedocs.io/
Here you will find a small overview of the files used and their locations.
| filename | filetype | project path | install path | description |
|---|---|---|---|---|
| pyaml | shared library | ./pyaml | /usr/local/bin | executable |
| pyaml.c | plaintext | ./pyaml | source code | |
| pyaml.1 | groff | ./pyaml | /usr/share/man/man1 | documentation |
| pyaml.yml | yaml | ./pyaml | /etc | configuration |
Note at the current time it may be that some of the listed files are not yet available or used. It is also possible that they can be found under a different path.
The program utilizes pygmentize to provide syntax highlighting for YAML files.
By default, it uses the color scheme specified in the pyaml.yml file.
However, users can customize the color scheme by modifying this configuration file.
Open the pyaml.yml file located in the same directory as the program.
Locate the scheme field under the config section.
Change its value to your desired Pygments color scheme.
config:
scheme: "default"For example, you can change the color scheme to monokai:
config:
scheme: "monokai"After editing the configuration file, the new color scheme will be applied automatically.
Pygments offers a wide variety of color schemes. Some popular options include:
- default
- emacs
- monokai
For a full list of available styles, you can use the following command:
pygmentize -L stylesGiven the following YAML file test.yml on Gist:
main-key:
keyword: "value"
sub-key:
inner-sub-keyword: "value"
next-key:
keyword: "another-value"
inner-sub-key:
keyword: "nested values"retrieve the following keys:
- keyword
- (next-key) keyword
- (inner-sub) keyword
pyaml test.yml main-key.keyword
pyaml test.yml next-key.keyword
pyaml test.yml next-key.inner-sub-key.keywordOutput:
value
another-value
nested valuesYou must observe the spelling and take upper and lower case into account.
Integrating pyaml with Bash Scripts
One of the primary advantages of pyaml is its seamless integration with Bash scripts. This allows for dynamic reading and setting of configuration parameters directly within your scripts.
Example Bash Script:
#!/bin/bash
# Parse YAML file and store values in variables
config_file="testme.yml"
author=$(pyaml $config_file Release.Author)
contact=$(pyaml $config_file Release.Contact)
# Use the parsed values
echo "Author: $author"
echo "Contact: $contact"Release:
Author: "AntiSecTech"
Contact: "[email protected]"Output:
Author: AntiSecTech
Contact: [email protected]- Efficiency: Written in C, pyaml provides high-speed parsing capabilities, reducing overhead in scripts.
- Simplicity: With its straightforward command-line interface, pyaml can be easily integrated into existing workflows and automation scripts.
- Flexibility: Able to parse any standard YAML file, making it versatile for various applications and configurations.
This project is licensed under the MIT License. See the LICENSE file for more details.