|
| 1 | +# |
| 2 | +# DVR-Scan: Video Motion Event Detection & Extraction Tool |
| 3 | +# -------------------------------------------------------------- |
| 4 | +# [ Site: https://www.dvr-scan.com/ ] |
| 5 | +# [ Repo: https://github.com/Breakthrough/DVR-Scan ] |
| 6 | +# |
| 7 | +# Copyright (C) 2016 Brandon Castellano <http://www.bcastell.com>. |
| 8 | +# |
| 9 | + |
| 10 | +# This script generates a headless (no GUI) version of the package |
| 11 | +# by modifying the setup.cfg file. When the project is next built, |
| 12 | +# the headless variant will be used. |
| 13 | +# |
| 14 | +# *WARNING*: This modifies the existing setup.cfg file in place. |
| 15 | +# The changes must be reverted to restore the full package. |
| 16 | +# |
| 17 | + |
| 18 | +import configparser |
| 19 | +import os |
| 20 | + |
| 21 | +COPYRIGHT_TEXT = """# |
| 22 | +# DVR-Scan: Video Motion Event Detection & Extraction Tool |
| 23 | +# -------------------------------------------------------------- |
| 24 | +# [ Site: https://www.dvr-scan.com/ ] |
| 25 | +# [ Repo: https://github.com/Breakthrough/DVR-Scan ] |
| 26 | +# |
| 27 | +# Copyright (C) 2016 Brandon Castellano <http://www.bcastell.com>. |
| 28 | +# |
| 29 | +
|
| 30 | +""" |
| 31 | + |
| 32 | +# Correctly locate setup.cfg relative to the script's location |
| 33 | +script_dir = os.path.dirname(os.path.abspath(__file__)) |
| 34 | +project_root = os.path.abspath(os.path.join(script_dir, "..")) |
| 35 | +setup_cfg_path = os.path.join(project_root, "setup.cfg") |
| 36 | + |
| 37 | +# Read setup.cfg |
| 38 | +config = configparser.ConfigParser() |
| 39 | +# Preserve case of keys |
| 40 | +config.optionxform = str |
| 41 | +config.read(setup_cfg_path) |
| 42 | + |
| 43 | +assert config.has_option("metadata", "name") |
| 44 | +name = config.get("metadata", "name") |
| 45 | +config.set("metadata", "name", f"{name}-Headless") |
| 46 | + |
| 47 | +# Remove dvr-scan-app from console_scripts |
| 48 | +assert config.has_section("options.entry_points") |
| 49 | +assert config.has_option("options.entry_points", "console_scripts") |
| 50 | +scripts = config.get("options.entry_points", "console_scripts").splitlines() |
| 51 | +scripts = [s.strip() for s in scripts if s.strip() and "dvr-scan-app" not in s] |
| 52 | +config.set("options.entry_points", "console_scripts", "\n" + "\n".join(scripts)) |
| 53 | + |
| 54 | +# Write back to setup.cfg |
| 55 | +with open(setup_cfg_path, "w") as configfile: |
| 56 | + configfile.write(COPYRIGHT_TEXT) |
| 57 | + config.write(configfile) |
| 58 | + |
| 59 | +print("Successfully generated headless setup.cfg.") |
0 commit comments