dotfiles/bin/system-parameters
Eryn Wells 661e5516e7 Add a mechanism for building a cache of "system parameters"
- Add a system_parameters module to eryntools that implements some basic types and can write a cache to a file.
- Add a system-parameters Python script that builds the cache.
- Add init_system_parameters to zsh that exports an environment variable that points to the parameters file
- Add an eryn.system-parameters.plist LaunchAgent file for running the script at regular intervals
2024-03-05 11:08:53 -08:00

41 lines
1.1 KiB
Python
Executable file

#!/usr/bin/env python3
import argparse
from eryntools.dotfiles.system_parameters import CommandParameter, SystemParameters
class HomebrewPrefix(CommandParameter):
def __init__(self):
super().__init__(['brew', '--prefix'])
class XcodeSelectPrintPath(CommandParameter):
def __init__(self):
super().__init__(['xcode-select', '-p'])
def main(argv):
parser = argparse.ArgumentParser(prog=argv[0])
parser.add_argument('-f', '--file', type=argparse.FileType('r'))
parser.add_argument('-o', '--output', type=argparse.FileType('w'), default=sys.stdout)
arguments = parser.parse_args(argv[1:])
output_parameters = SystemParameters()
if arguments.file:
output_parameters.load_from_file(arguments.file)
parameters = {
'homebrew_prefix': HomebrewPrefix(),
'xcode_path': XcodeSelectPrintPath(),
}
for name, parameter in parameters.items():
setattr(output_parameters, name, parameter)
output_parameters.write_to_file(arguments.output)
if __name__ == "__main__":
import sys
sys.exit(main(sys.argv) or 0)