summaryrefslogtreecommitdiffstats
path: root/.bin/dot-pkgs
blob: f5c80ee84a8df3fde579638c86e29d0d1595ede7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/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()
remember that computers suck.