2018-12-09 01:06:47 -05:00
|
|
|
import distutils.dir_util
|
|
|
|
import distutils.file_util
|
2018-12-08 19:01:28 -05:00
|
|
|
from lib.package import Package
|
2018-12-09 00:48:14 -05:00
|
|
|
from lib.path import local_path, deploy_path
|
2018-12-08 23:20:00 -05:00
|
|
|
import lib.proc as proc
|
|
|
|
import lib.pacman as pacman
|
|
|
|
import lib.yay as yay
|
|
|
|
import lib.git as git
|
2018-12-10 21:05:23 -05:00
|
|
|
import lib.systemd as systemd
|
2018-12-09 11:27:18 -05:00
|
|
|
from lib.diff import diff
|
|
|
|
from lib.fish import fish
|
2018-12-08 19:01:28 -05:00
|
|
|
|
|
|
|
installed_packages = pacman.get_installed()
|
|
|
|
|
|
|
|
def copy(source, dest):
|
|
|
|
print(source, '->', dest)
|
2018-12-12 09:45:13 -05:00
|
|
|
if not dest.parent.is_dir():
|
|
|
|
distutils.dir_util.mkpath(str(dest.parent))
|
|
|
|
|
2018-12-08 19:01:28 -05:00
|
|
|
if source.is_dir():
|
2018-12-09 01:06:47 -05:00
|
|
|
distutils.dir_util.copy_tree(str(source), str(dest))
|
2018-12-08 19:01:28 -05:00
|
|
|
else:
|
2018-12-09 01:06:47 -05:00
|
|
|
distutils.file_util.copy_file(str(source), str(dest))
|
2018-12-08 19:01:28 -05:00
|
|
|
|
2018-12-08 23:46:13 -05:00
|
|
|
def import_paths(paths, base):
|
2018-12-08 23:20:00 -05:00
|
|
|
if not isinstance(paths, list):
|
|
|
|
paths = [paths]
|
|
|
|
for path in paths:
|
2018-12-09 00:48:14 -05:00
|
|
|
copy(deploy_path(path), path)
|
2018-12-08 19:01:28 -05:00
|
|
|
|
2018-12-08 23:46:13 -05:00
|
|
|
def export_paths(paths, base):
|
2018-12-08 23:20:00 -05:00
|
|
|
if not isinstance(paths, list):
|
|
|
|
paths = [paths]
|
|
|
|
for path in paths:
|
2018-12-09 00:48:14 -05:00
|
|
|
copy(path, deploy_path(path))
|
|
|
|
|
2018-12-08 19:01:28 -05:00
|
|
|
|
|
|
|
def install(package):
|
|
|
|
if not package.install or not package.source:
|
|
|
|
return
|
2018-12-09 01:01:43 -05:00
|
|
|
if package.source == 'core' and package.name not in installed_packages:
|
|
|
|
print('pacman -S', package.name)
|
|
|
|
pacman.install(package.name)
|
|
|
|
elif package.source == 'aur' and package.name not in installed_packages:
|
|
|
|
print('yay -S', package.name)
|
|
|
|
yay.install(package.name)
|
2018-12-08 23:20:00 -05:00
|
|
|
elif package.source == 'git':
|
2018-12-09 01:01:43 -05:00
|
|
|
print('git clone', package.name)
|
|
|
|
git.clone(package.url, 'git/' + package.name)
|
2018-12-08 19:01:28 -05:00
|
|
|
|
|
|
|
|
|
|
|
def export_config(package):
|
|
|
|
if not package.export_config or not package.config:
|
|
|
|
return
|
2018-12-08 23:46:13 -05:00
|
|
|
export_paths(package.config, '.config')
|
2018-12-08 19:01:28 -05:00
|
|
|
|
|
|
|
def import_config(package):
|
|
|
|
if not package.config:
|
|
|
|
return
|
2018-12-08 23:46:13 -05:00
|
|
|
import_paths(package.config, '.config')
|
2018-12-08 19:01:28 -05:00
|
|
|
|
2018-12-09 00:48:14 -05:00
|
|
|
def diff_config(package):
|
|
|
|
if not package.config:
|
|
|
|
return
|
|
|
|
for config in package.config:
|
|
|
|
print(diff(config, deploy_path(config)))
|
|
|
|
|
2018-12-09 11:27:18 -05:00
|
|
|
|
2018-12-08 19:01:28 -05:00
|
|
|
def run_script(package):
|
|
|
|
if not package.run_script or not package.script:
|
|
|
|
return
|
2018-12-08 23:46:13 -05:00
|
|
|
for script in package.script:
|
|
|
|
print('fish', script)
|
2018-12-09 11:27:18 -05:00
|
|
|
print(fish(script))
|
2018-12-09 00:48:14 -05:00
|
|
|
|
2018-12-09 11:27:18 -05:00
|
|
|
|
2018-12-08 19:01:28 -05:00
|
|
|
def export_units(package):
|
2018-12-08 23:46:13 -05:00
|
|
|
if not package.export_units or not package.userunit:
|
2018-12-08 19:01:28 -05:00
|
|
|
return
|
2018-12-08 23:46:13 -05:00
|
|
|
export_paths(package.userunit, '.config/systemd/user')
|
2018-12-08 19:01:28 -05:00
|
|
|
|
|
|
|
def import_units(package):
|
2018-12-08 23:46:13 -05:00
|
|
|
if not package.userunit:
|
2018-12-08 19:01:28 -05:00
|
|
|
return
|
2018-12-08 23:46:13 -05:00
|
|
|
import_paths(package.userunit, 'lain/.config/systemd/user')
|
2018-12-08 19:01:28 -05:00
|
|
|
|
2018-12-09 00:48:14 -05:00
|
|
|
def diff_units(package):
|
|
|
|
if not package.userunit:
|
|
|
|
return
|
|
|
|
for unit in package.userunit:
|
|
|
|
print(diff(unit, deploy_path(unit)))
|
|
|
|
|
2018-12-08 23:20:00 -05:00
|
|
|
def enable_units(package):
|
2018-12-08 23:46:13 -05:00
|
|
|
if not package.enable_units or not package.userunit:
|
2018-12-08 23:20:00 -05:00
|
|
|
return
|
2018-12-08 23:46:13 -05:00
|
|
|
for unit in package.userunit:
|
2018-12-08 23:20:00 -05:00
|
|
|
print('systemctl --user enable', unit.name)
|
2018-12-10 21:05:23 -05:00
|
|
|
systemd.enable(unit.name, True)
|
2018-12-08 19:01:28 -05:00
|
|
|
|
2018-12-09 00:48:14 -05:00
|
|
|
|
2018-12-08 19:01:28 -05:00
|
|
|
def deploy(package):
|
|
|
|
if not package.enabled:
|
|
|
|
return
|
|
|
|
install(package)
|
|
|
|
export_config(package)
|
|
|
|
run_script(package)
|
|
|
|
export_units(package)
|
|
|
|
|