mirror of
https://github.com/Foltik/dotfiles
synced 2024-11-30 22:42:11 -05:00
Reorganize package
This commit is contained in:
parent
2cd2015210
commit
e63d131f9e
@ -6,15 +6,20 @@ def toggle(obj, prop):
|
|||||||
|
|
||||||
class Package:
|
class Package:
|
||||||
def __init__(self, obj):
|
def __init__(self, obj):
|
||||||
# Immutable Attributes
|
# Defaults
|
||||||
|
self.source = 'core'
|
||||||
|
self.alias = None
|
||||||
|
|
||||||
|
# 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.source = 'core'
|
self.source = 'core'
|
||||||
for key, value in props.items():
|
for key, value in props.items():
|
||||||
setattr(self, key, value)
|
setattr(self, key, value if value != 'none' else None)
|
||||||
else:
|
else:
|
||||||
self.name = obj
|
self.name = obj
|
||||||
self.source = 'core'
|
|
||||||
|
# Transform and infer attributes
|
||||||
self.update_from_files()
|
self.update_from_files()
|
||||||
|
|
||||||
# Install State
|
# Install State
|
||||||
@ -23,43 +28,45 @@ class Package:
|
|||||||
self.export_config = True
|
self.export_config = True
|
||||||
self.run_script = True
|
self.run_script = True
|
||||||
self.export_units = True
|
self.export_units = True
|
||||||
|
self.enable_units = True
|
||||||
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
def __getitem__(self, key):
|
||||||
|
return getattr(self, key)
|
||||||
|
|
||||||
|
def __setitem__(self, key, value):
|
||||||
|
return setattr(self, key, value)
|
||||||
|
|
||||||
|
def getattrs(self):
|
||||||
|
excepted = [
|
||||||
|
'name', 'enabled', 'install',
|
||||||
|
'export_config', 'run_script',
|
||||||
|
'export_units', 'enable_units'
|
||||||
|
]
|
||||||
|
|
||||||
|
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):
|
||||||
|
default_path = Path(default)
|
||||||
|
if hasattr(self, prop):
|
||||||
|
if isinstance(self[prop], list):
|
||||||
|
self[prop] = list(map(lambda p: Path(p), self[prop]))
|
||||||
|
elif self[prop] == 'none':
|
||||||
|
self[prop] = None
|
||||||
|
elif self[prop] != None:
|
||||||
|
self[prop] = Path(self[prop])
|
||||||
|
elif (Path(basepath) / default_path).is_dir() or (Path(basepath) / default_path).is_file():
|
||||||
|
self[prop] = [default_path]
|
||||||
|
else:
|
||||||
|
self[prop] = None
|
||||||
|
|
||||||
def update_from_files(self):
|
def update_from_files(self):
|
||||||
if self.source == 'none':
|
self.transform_default('config', self.name, 'lain/.config')
|
||||||
self.source = None
|
self.transform_default('script', self.name + '.fish', 'scripts')
|
||||||
|
self.transform_default('userunit', self.name + '.service', 'lain/.config/systemd/user')
|
||||||
default_config = Path('.config/' + self.name)
|
|
||||||
if hasattr(self, 'config'):
|
|
||||||
if isinstance(self.config, list):
|
|
||||||
self.config = list(map(lambda c: Path(c), self.config))
|
|
||||||
elif self.config == 'none':
|
|
||||||
self.config = None
|
|
||||||
else:
|
|
||||||
self.config = Path(self.config)
|
|
||||||
elif (Path('lain') / default_config).is_dir():
|
|
||||||
self.config = default_config
|
|
||||||
else:
|
|
||||||
self.config = None
|
|
||||||
|
|
||||||
default_script = Path(self.name + '.fish')
|
|
||||||
if hasattr(self, 'script'):
|
|
||||||
self.script = Path(self.script)
|
|
||||||
elif (Path('lain') / default_script).is_file():
|
|
||||||
self.script = default_script
|
|
||||||
else:
|
|
||||||
self.script = None
|
|
||||||
|
|
||||||
default_unit = Path('.config/systemd/user/' + self.name + '.service')
|
|
||||||
if hasattr(self, 'userunits'):
|
|
||||||
self.userunits = list(map(lambda unit: Path('.config/systemd/user/' + unit), self.userunits))
|
|
||||||
elif (Path('lain') / default_unit).is_file():
|
|
||||||
self.userunits = [default_unit]
|
|
||||||
else:
|
|
||||||
self.userunits = None
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def config_menu(screen, title, packages):
|
def config_menu(screen, title, packages):
|
||||||
@ -70,7 +77,8 @@ class Package:
|
|||||||
('Install', toggle(package, 'install')),
|
('Install', toggle(package, 'install')),
|
||||||
('Export Config', toggle(package, 'export_config')),
|
('Export Config', toggle(package, 'export_config')),
|
||||||
('Run Script', toggle(package, 'run_script')),
|
('Run Script', toggle(package, 'run_script')),
|
||||||
('Export Units', toggle(package, 'export_units'))
|
('Export Units', toggle(package, 'export_units')),
|
||||||
|
('Enable Units', toggle(package, 'enable_units'))
|
||||||
], True)
|
], True)
|
||||||
items += [(package.name, toggle(package, 'enabled'), submenu.display)]
|
items += [(package.name, toggle(package, 'enabled'), submenu.display)]
|
||||||
return ChecklistMenu(screen, title, items, True)
|
return ChecklistMenu(screen, title, items, True)
|
||||||
|
Loading…
Reference in New Issue
Block a user