Skip to content

Commit

Permalink
Update yml2jopts.py
Browse files Browse the repository at this point in the history
Added author information
  • Loading branch information
prince11jose authored Jun 15, 2024
1 parent bf2795a commit 36838b8
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions yml2jopts.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
"""
Title: YML to Java Options Converter
Author: Prince Jose
Email: prince11jose@hotmail.com
Date Created: 2024-04-26
Last Modified: 2024-06-15
Description: This script converts YAML configuration files into Java command-line options.
It removes comments from the YAML file before processing and handles nested
dictionaries by flattening the keys.
Usage:
python yml2opts.py <yaml_file>
Dependencies:
- PyYAML
License: MIT License
"""

import sys
import yaml

def load_yaml(file_path):
with open(file_path, 'r') as file:
content = yaml.safe_load(file)
return content

def convert_to_java_options(data):
java_options = []
for key, value in data.items():
Expand All @@ -14,6 +36,7 @@ def convert_to_java_options(data):
else:
java_options.append(f'-D{key}={value}')
return java_options

def flatten_keys(dictionary, parent_key='', separator='.'):
items = {}
for k, v in dictionary.items():
Expand All @@ -23,8 +46,10 @@ def flatten_keys(dictionary, parent_key='', separator='.'):
else:
items[new_key] = v
return items

def remove_comments(lines):
return [line for line in lines if not line.strip().startswith('#')]

def main(yaml_file):
lines = None
with open(yaml_file, 'r') as file:
Expand All @@ -34,6 +59,7 @@ def main(yaml_file):
data = load_yaml(yaml_file)
java_options = convert_to_java_options(data)
print(' '.join(java_options))

if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: yml2opts <yaml_file>")
Expand Down

0 comments on commit 36838b8

Please sign in to comment.