mirror of
https://github.com/Foltik/dotfiles
synced 2024-11-30 14:32:08 -05:00
Make all paths relative to cwd and add lib
This commit is contained in:
parent
c8407a8a3f
commit
abc12e373a
@ -1,5 +1,6 @@
|
||||
from pathlib import Path
|
||||
from lib.menu import ChecklistMenu
|
||||
from lib.path import local_path, deploy_path
|
||||
|
||||
def toggle(obj, prop):
|
||||
return lambda b: setattr(obj, prop, b)
|
||||
@ -50,23 +51,23 @@ class Package:
|
||||
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)
|
||||
default_path = local_path(basepath, default)
|
||||
if hasattr(self, prop):
|
||||
if isinstance(self[prop], list):
|
||||
self[prop] = list(map(lambda p: Path(p), self[prop]))
|
||||
self[prop] = list(map(lambda p: local_path(basepath, p), self[prop]))
|
||||
elif self[prop] == 'none':
|
||||
self[prop] = None
|
||||
elif self[prop] != None:
|
||||
self[prop] = [Path(self[prop])]
|
||||
self[prop] = [local_path(basepath, 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):
|
||||
self.transform_default('config', self.name, 'lain/.config')
|
||||
self.transform_default('script', self.name + '.fish', 'scripts')
|
||||
self.transform_default('userunit', self.name + '.service', 'lain/.config/systemd/user')
|
||||
self.transform_default('config', self.name, 'lain/')
|
||||
self.transform_default('script', self.name + '.fish', 'scripts/')
|
||||
self.transform_default('userunit', self.name + '.service', 'lain/.config/systemd/user/')
|
||||
|
||||
@staticmethod
|
||||
def config_menu(screen, title, packages):
|
||||
|
13
lib/path.py
Normal file
13
lib/path.py
Normal file
@ -0,0 +1,13 @@
|
||||
from pathlib import Path
|
||||
|
||||
def local_path(*args):
|
||||
path = Path('./')
|
||||
for arg in args:
|
||||
path /= Path(arg)
|
||||
return path
|
||||
|
||||
def deploy_path(path):
|
||||
start = path.parts[0]
|
||||
target = path.parts[1:]
|
||||
if start == 'lain':
|
||||
return Path('~') / Path(*target)
|
Loading…
Reference in New Issue
Block a user