man. some major restructuring, and envsetup.py is a kinda neat hack.

This commit is contained in:
brent s
2019-09-30 22:08:37 -04:00
parent 7a2e66f1a2
commit 3ca56d7b5c
17 changed files with 1184 additions and 2429 deletions

3
aif/__init__.py Normal file
View File

@@ -0,0 +1,3 @@
class AIF(object):
def __init__(self):
pass

17
aif/config.py Normal file
View File

@@ -0,0 +1,17 @@
import os
##
from lxml import etree
class Config(object):
def __init__(self):
self.xml = None
def parseLocalFile(self, fpath):
fpath = os.path.abspath(os.path.expanduser(fpath))
pass
def parseRemoteFile(self, url):
pass
def parseRawContent(self, content):
pass

0
aif/constants.py Normal file
View File

15
aif/disk.py Normal file
View File

@@ -0,0 +1,15 @@
# To reproduce sgdisk behaviour in v1 of AIF-NG:
# https://gist.github.com/herry13/5931cac426da99820de843477e41e89e
# https://github.com/dcantrell/pyparted/blob/master/examples/query_device_capacity.py
# TODO: Remember to replicate genfstab behaviour.
try:
# https://stackoverflow.com/a/34812552/733214
# https://github.com/karelzak/util-linux/blob/master/libmount/python/test_mount_context.py#L6
import libmount as mount
except ImportError:
# We should never get here. util-linux is part of core (base) in Arch and uses "libmount".
import pylibmount as mount
##
import parted
import psutil

50
aif/envsetup.py Normal file
View File

@@ -0,0 +1,50 @@
# We use a temporary venv to ensure we have all the external libraries we need.
# This removes the necessity of extra libs at runtime. If you're in an environment that doesn't have access to PyPI/pip,
# you'll need to customize the install host (typically the live CD/live USB) to have them installed as system packages.
# Before you hoot and holler about this, Let's Encrypt's certbot-auto does the same thing.
# Except I segregate it out even further; I don't even install pip into the system python.
import ensurepip
import json
import os
import tempfile
import subprocess
import sys
import venv
# TODO: a more consistent way of managing deps?
depmods = ['gpg', 'requests', 'lxml', 'psutil', 'pyparted', 'pytz', 'passlib', 'validators']
class EnvBuilder(object):
def __init__(self):
self.vdir = tempfile.mkdtemp(prefix = '.aif_', suffix = '_VENV')
self.venv = venv.create(self.vdir, system_site_packages = True, clear = True, with_pip = True)
ensurepip.bootstrap(root = self.vdir)
# pip does some dumb env var things and doesn't clean up after itself.
for v in ('PIP_CONFIG_FILE', 'ENSUREPIP_OPTIONS', 'PIP_REQ_TRACKER', 'PLAT'):
if os.environ.get(v):
del(os.environ[v])
moddir_raw = subprocess.run([os.path.join(self.vdir,
'bin',
'python3'),
'-c',
('import site; '
'import json; '
'print(json.dumps(site.getsitepackages(), indent = 4))')],
stdout = subprocess.PIPE)
self.modulesdir = json.loads(moddir_raw.stdout.decode('utf-8'))[0]
# This is SO. DUMB. WHY DO I HAVE TO CALL PIP FROM A SHELL. IT'S WRITTEN IN PYTHON.
# https://pip.pypa.io/en/stable/user_guide/#using-pip-from-your-program
# TODO: logging
for m in depmods:
pip_cmd = [os.path.join(self.vdir,
'bin',
'python3'),
'-m',
'pip',
'install',
'--disable-pip-version-check',
m]
subprocess.run(pip_cmd)
# And now make it available to other components.
sys.path.insert(1, self.modulesdir)

1
aif/log.py Normal file
View File

@@ -0,0 +1 @@
import logging

1
aif/network.py Normal file
View File

@@ -0,0 +1 @@
import ipaddress

6
aif/pacman.py Normal file
View File

@@ -0,0 +1,6 @@
# We can manually bootstrap and alter pacman's keyring. But check the bootstrap tarball; we might not need to.
# TODO.
import os
##
import gpg

9
aif/users.py Normal file
View File

@@ -0,0 +1,9 @@
# There isn't a python package that can manage *NIX users (well), unfortunately.
# So we do something stupid:
# https://www.tldp.org/LDP/sag/html/adduser.html
# https://unix.stackexchange.com/a/153227/284004
# https://wiki.archlinux.org/index.php/users_and_groups#File_list
import os
##
import passlib # validate password hash/gen hash