2018-12-08 19:01:28 -05:00
|
|
|
import os
|
|
|
|
import distutils
|
2018-12-08 23:20:00 -05:00
|
|
|
import subprocess
|
2018-12-08 19:01:28 -05:00
|
|
|
from pathlib import Path
|
|
|
|
from lib.package import Package
|
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-08 19:01:28 -05:00
|
|
|
|
|
|
|
installed_packages = pacman.get_installed()
|
|
|
|
|
|
|
|
def copy(source, dest):
|
|
|
|
print(source, '->', dest)
|
|
|
|
if source.is_dir():
|
|
|
|
pass#distutils.dir_util.copy_tree(source.absolute(), dest.absolute())
|
|
|
|
else:
|
|
|
|
pass#distutils.file_util.copy_file(source.absolute(), dest.absolute())
|
|
|
|
|
2018-12-08 23:20:00 -05:00
|
|
|
def import_path(paths):
|
|
|
|
if not isinstance(paths, list):
|
|
|
|
paths = [paths]
|
|
|
|
for path in paths:
|
|
|
|
copy(Path('~') / path, Path('./lain') / path)
|
2018-12-08 19:01:28 -05:00
|
|
|
|
2018-12-08 23:20:00 -05:00
|
|
|
def export_path(paths):
|
|
|
|
if not isinstance(paths, list):
|
|
|
|
paths = [paths]
|
|
|
|
for path in paths:
|
|
|
|
copy(Path('./lain') / path, Path('~') / path)
|
2018-12-08 19:01:28 -05:00
|
|
|
|
|
|
|
def install(package):
|
|
|
|
if not package.install or not package.source:
|
|
|
|
return
|
2018-12-08 23:20:00 -05:00
|
|
|
if package.source == 'core':# and package.name not in installed_packages:
|
|
|
|
print('pacman', package.name)
|
|
|
|
#pacman.install(package.name)
|
|
|
|
elif package.source == 'aur':# and package.name not in installed_packages:
|
|
|
|
print('yay', package.name)
|
|
|
|
#yay.install(package.name)
|
|
|
|
elif package.source == 'git':
|
|
|
|
print('git', 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:20:00 -05:00
|
|
|
export_path(package.config)
|
2018-12-08 19:01:28 -05:00
|
|
|
|
|
|
|
def import_config(package):
|
|
|
|
if not package.config:
|
|
|
|
return
|
2018-12-08 23:20:00 -05:00
|
|
|
import_path(package.config)
|
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:20:00 -05:00
|
|
|
print('fish', package.script)
|
|
|
|
#proc.exec(['fish', package.script.absolute()])
|
2018-12-08 19:01:28 -05:00
|
|
|
|
|
|
|
def export_units(package):
|
|
|
|
if not package.export_units or not package.userunits:
|
|
|
|
return
|
2018-12-08 23:20:00 -05:00
|
|
|
export_path(package.userunits)
|
2018-12-08 19:01:28 -05:00
|
|
|
|
|
|
|
def import_units(package):
|
|
|
|
if not package.userunits:
|
|
|
|
return
|
2018-12-08 23:20:00 -05:00
|
|
|
import_path(package.userunits)
|
2018-12-08 19:01:28 -05:00
|
|
|
|
2018-12-08 23:20:00 -05:00
|
|
|
def enable_units(package):
|
|
|
|
if not package.enable_units or not package.userunits:
|
|
|
|
return
|
2018-12-08 19:01:28 -05:00
|
|
|
for unit in package.userunits:
|
2018-12-08 23:20:00 -05:00
|
|
|
print('systemctl --user enable', unit.name)
|
|
|
|
#proc.exec(['systemctl', '--user', 'enable', unit.name])
|
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)
|
|
|
|
|