Thanks to visit codestin.com
Credit goes to github.com

Skip to content

AntiSecTech/pyaml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pyaml - YAML Parser in C

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.

Table of Contents

Introduction

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.


Features

Linux C GitHub Release License made-with-Markdown made-with-bash

  • Minimal Dependencies: Only requires the libyaml library.
  • 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
  • GitHub hosted on GitHub
  • Git Version history control
  • Markdown Markdown Documentary
  • Shell Script Installationroutine
  • Raspberry Pi runs on Raspberry

^ UP to Index

Updates

This release is currently in version: GitHub Release
Please refer to the changelog for all information on current changes.
You can view it here.


^ UP to Index

Dependencies

The libyaml library is required to compile this project. It can be installed as follows:

Ubuntu/Debian:

sudo apt-get update
sudo apt-get install libyaml-dev

Fedora:

sudo dnf install libyaml-devel

Arch Linux:

sudo pacman -S libyaml

In 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 Pygments

^ UP to Index

Prerequisites

To 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:

Ubuntu/Debian:

sudo apt-get update
sudo install gcc

Fedora:

sudo dnf install gcc

Arch Linux:

sudo pacman -S gcc

^ UP to Index

Installation

Express-Installer

You 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

by using curl

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.sh

by using wget

wget -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.sh

or take the following steps for the classic route

Clone the repository:

git clone https://github.com/AntiSecTech/pyaml.git
cd pyaml

Compile the program:

make compile

Install the program:

sudo make install

If 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 /etc

If you have any further questions about the Make process, please refer to the source code of the Makefile.


^ UP to Index

Uninstallation

cd pyaml
sudo make uninstall

^ UP to Index

Usage

   pyaml <file.yml> [<key>]
   pyaml -v | --version
   pyaml -h | --help

^ UP to Index

Help

The following options are available to help you use pyaml.

Buildin

   pyaml --help

Buildin 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 pyaml

GitHub

Read the documentation carefully.

https://github.com/AntiSecTech/pyaml/blob/main/README.md

ReadTheDocs

  • This function is not yet available!
https://pyaml.readthedocs.io/

^ UP to Index

Files

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.


^ UP to Index

Customize

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.

Color Schemes

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 styles

^ UP to Index

Examples

Given 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.keyword

Output:

   value
   another-value
   nested values

You 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]

^ UP to Index

Advantages

  • 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.

^ UP to Index

License

This project is licensed under the MIT License. See the LICENSE file for more details.

About

A simple C program for parsing YAML files.

Resources

License

Stars

Watchers

Forks

Packages

No packages published