#!/usr/bin/env python3
import subprocess
import os
ENV = {
'path': f'{os.environ["HOME"]}/.cache/dot-pkgs',
'bin_path': f'{os.environ["HOME"]}/.local/bin'
}
PKGS = [
{
'src': 'git://git.suckless.org/dwm',
'path': f'{ENV["path"]}/dwm',
'bin': 'dwm',
'type': 'git'
},
{
'src': 'git://git.suckless.org/st',
'path': f'{ENV["path"]}/st',
'bin': 'st',
'type': 'git'
},
{
'src': 'git@st0dev1:_suckless/dwm',
'path': f'{os.environ["HOME"]}/git.rgoncalves.se/_suckless/dwm',
'bin': 'st',
'type': 'git'
},
{
'src': '',
'type': ''
}
]
def copy_executable_file(src, dst):
pass
def merge_mappings(pkgs, env):
"""
Merge two dict in the first one.
"""
for index, pkg in enumerate(pkgs):
pkgs[index] = {**env, **pkg}
def handle_git(pkg):
"""
Clone and update git repo.
"""
commands = [
['git', 'clone', pkg['src'], pkg['path']],
['git', 'pull']
]
for command in commands:
subprocess.run(command, cwd=pkg['path'])
def handle_make(pkg):
subprocess.run(['make'], cwd=pkg['path'])
def main():
merge_mappings(PKGS, ENV)
for pkg in [pkg for pkg in PKGS if pkg['type'] == 'git']:
os.makedirs(pkg['path'], exist_ok=True)
handle_git(pkg)
handle_make(pkg)
if __name__ == '__main__':
main()