mirror of
https://github.com/Foltik/dotfiles
synced 2025-04-05 10:33:24 -04:00
Niceify defaults checking
This commit is contained in:
parent
89a1fd4861
commit
148c83f017
@ -9,21 +9,22 @@ class Package:
|
|||||||
def __init__(self, obj):
|
def __init__(self, obj):
|
||||||
# Defaults
|
# Defaults
|
||||||
self.source = 'core'
|
self.source = 'core'
|
||||||
self.alias = None
|
|
||||||
|
|
||||||
# Immutable attributes
|
# Immutable attributes
|
||||||
if isinstance(obj, dict):
|
if isinstance(obj, dict):
|
||||||
self.name, props = next(iter(obj.items()))
|
self.name, props = next(iter(obj.items()))
|
||||||
|
self.alias = self.name
|
||||||
self.source = 'core'
|
self.source = 'core'
|
||||||
for key, value in props.items():
|
for key, value in props.items():
|
||||||
setattr(self, key, value if value != 'none' else None)
|
setattr(self, key, value if value != 'none' else None)
|
||||||
else:
|
else:
|
||||||
self.name = obj
|
self.name = obj
|
||||||
|
self.alias = self.name
|
||||||
|
|
||||||
# Transform and infer attributes
|
# Infer and properly format attributes as paths
|
||||||
self.transform_default('config', '.config/' + self.name, 'lain/')
|
self.check_defaults('config', ['.config/%s'], 'lain/')
|
||||||
self.transform_default('script', self.name + '.fish', 'scripts/')
|
self.check_defaults('script', ['%s.fish'], 'scripts/')
|
||||||
self.transform_default('userunit', self.name + '.service', 'lain/.config/systemd/user/')
|
self.check_defaults('userunit', ['%s.service', '%s@.service'], 'lain/.config/systemd/user/')
|
||||||
|
|
||||||
# Install State
|
# Install State
|
||||||
self.enabled = True
|
self.enabled = True
|
||||||
@ -38,7 +39,11 @@ class Package:
|
|||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
return getattr(self, key)
|
if hasattr(self, key):
|
||||||
|
val = getattr(self, key)
|
||||||
|
return None if val == 'none' else val
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
def __setitem__(self, key, value):
|
def __setitem__(self, key, value):
|
||||||
return setattr(self, key, value)
|
return setattr(self, key, value)
|
||||||
@ -52,19 +57,20 @@ class Package:
|
|||||||
|
|
||||||
return [(k, v) for k, v in vars(self).items() if v != None and k not in excepted]
|
return [(k, v) for k, v in vars(self).items() if v != None and k not in excepted]
|
||||||
|
|
||||||
def transform_default(self, prop, default, basepath):
|
def check_defaults(self, prop, defaults, basepath):
|
||||||
default_path = local_path(basepath, default)
|
for default in defaults:
|
||||||
if hasattr(self, prop):
|
for name in [self.name, self.alias]:
|
||||||
|
default_path = local_path(basepath, default % name)
|
||||||
|
if self[prop]:
|
||||||
if isinstance(self[prop], list):
|
if isinstance(self[prop], list):
|
||||||
self[prop] = list(map(lambda p: local_path(basepath, p), self[prop]))
|
self[prop] = list(map(lambda p: local_path(basepath, p), self[prop]))
|
||||||
elif self[prop] == 'none':
|
else:
|
||||||
self[prop] = None
|
|
||||||
elif self[prop] != None:
|
|
||||||
self[prop] = [local_path(basepath, self[prop])]
|
self[prop] = [local_path(basepath, self[prop])]
|
||||||
elif default_path.is_dir() or default_path.is_file():
|
elif default_path.is_dir() or default_path.is_file():
|
||||||
self[prop] = [default_path]
|
self[prop] = [default_path]
|
||||||
else:
|
|
||||||
self[prop] = None
|
if self[prop] != None:
|
||||||
|
return
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def config_menu(screen, title, packages):
|
def config_menu(screen, title, packages):
|
||||||
|
Loading…
Reference in New Issue
Block a user