1
0
mirror of https://github.com/Foltik/dotfiles synced 2024-11-30 22:42:11 -05:00
dotfiles/lib/parse.py

27 lines
763 B
Python
Raw Normal View History

2018-12-01 14:24:43 -05:00
import yaml
class Package:
def __init__(self, obj):
if isinstance(obj, dict):
self.name, props = next(iter(obj.items()))
self.source = 'core'
for key, value in props.items():
setattr(self, key, value)
else:
self.name = obj
self.source = 'core'
def __repr__(self):
return self.name
class Category:
def __init__(self, name, packages):
self.name = name
self.packages = [Package(pkg) for pkg in packages]
def __repr__(self):
return self.name + ': ' + str(self.packages)
def parse(file):
f = open(file, 'r')
data = yaml.load(f)
return [Category(name, packages) for name, packages in data.items()]