autoeagle.autoeagle_config API documentation

# autoeagle.autoeagle_config

View Source

      1import argparse
      2from pathlib import Path
      3
      4import tomlkit
      5
      6
      7def is_configured() -> bool:
      8    config = load_config()
      9    return config["eagledir"] != ""
     10
     11
     12def configure(eagledir: str, ulpdir: str = None, scriptsdir: str = None):
     13    """Configure autoeagle configuration file.
     14
     15    :param eagledir: Path to user's Eagle directory.
     16    (Not the executable installation directory, but the one containing
     17    projects, libraries, ulps, etc.)
     18
     19    :param ulpdir: Path to user's ulp directory.
     20    Only necessary if different from the standard ulp
     21    directory path.
     22
     23    :param scriptsdir: Path to user's scripts directory.
     24    Only necessary if different from the standard scripts
     25    directory path."""
     26    config = load_config()
     27    eagledir = Path(eagledir)
     28    ulpdir = Path(ulpdir) if ulpdir else Path(eagledir) / "ulps"
     29    scriptsdir = Path(scriptsdir) if scriptsdir else Path(eagledir) / "scripts"
     30    configpath = Path(__file__).parent / "autoeagle.toml"
     31    # tomlkit doesn't like Path objects
     32    config["eagledir"] = str(eagledir)
     33    config["ulpdir"] = str(ulpdir)
     34    config["scriptsdir"] = str(scriptsdir)
     35    configpath.write_text(tomlkit.dumps(config))
     36    print("Autoeagle configuration updated.")
     37    print(f"Manual adjustments can be made here: {configpath}")
     38
     39
     40def load_config() -> dict:
     41    """Load autoeagle configuration file."""
     42    config = tomlkit.loads((Path(__file__).parent / "autoeagle.toml").read_text())
     43    return config
     44
     45
     46def prompt_to_configure() -> str:
     47    """Prompt user to provide their EAGLE
     48    directory path and configure autoeagletoml."""
     49    print("Autoeagle config file is not configured.")
     50    eagledir = input(
     51        "Enter path to your 'EAGLE' directory (contains projects, libraries, etc.): "
     52    )
     53    configure(eagledir)
     54
     55
     56def get_args() -> argparse.Namespace:
     57    parser = argparse.ArgumentParser()
     58
     59    parser.add_argument(
     60        "-e",
     61        "--eagledir",
     62        type=str,
     63        help=""" Path to user's Eagle directory.
     64    (Not the executable installation directory, but the one containing
     65    projects, libraries, ulps, etc.) """,
     66    )
     67
     68    parser.add_argument(
     69        "-u",
     70        "--ulpdir",
     71        type=str,
     72        default=None,
     73        help=""" Path to user's ulp directory.
     74    Only necessary if different from the standard ulp
     75    directory path. """,
     76    )
     77
     78    parser.add_argument(
     79        "-s",
     80        "--scriptsdir",
     81        type=str,
     82        default=None,
     83        help=""" Path to user's scripts directory.
     84    Only necessary if different from the standard scripts
     85    directory path. """,
     86    )
     87
     88    args = parser.parse_args()
     89
     90    return args
     91
     92
     93def main(args: argparse.Namespace = None):
     94    if not args:
     95        args = get_args()
     96    configure(args.eagledir, args.ulpdir, args.scriptsdir)
     97
     98
     99if __name__ == "__main__":
    100    main(get_args())

def is_configured() -> bool: View Source

     8def is_configured() -> bool:
     9    config = load_config()
    10    return config["eagledir"] != ""

def configure(eagledir: str, ulpdir: str = None, scriptsdir: str = None): View Source

    13def configure(eagledir: str, ulpdir: str = None, scriptsdir: str = None):
    14    """Configure autoeagle configuration file.
    15
    16    :param eagledir: Path to user's Eagle directory.
    17    (Not the executable installation directory, but the one containing
    18    projects, libraries, ulps, etc.)
    19
    20    :param ulpdir: Path to user's ulp directory.
    21    Only necessary if different from the standard ulp
    22    directory path.
    23
    24    :param scriptsdir: Path to user's scripts directory.
    25    Only necessary if different from the standard scripts
    26    directory path."""
    27    config = load_config()
    28    eagledir = Path(eagledir)
    29    ulpdir = Path(ulpdir) if ulpdir else Path(eagledir) / "ulps"
    30    scriptsdir = Path(scriptsdir) if scriptsdir else Path(eagledir) / "scripts"
    31    configpath = Path(__file__).parent / "autoeagle.toml"
    32    # tomlkit doesn't like Path objects
    33    config["eagledir"] = str(eagledir)
    34    config["ulpdir"] = str(ulpdir)
    35    config["scriptsdir"] = str(scriptsdir)
    36    configpath.write_text(tomlkit.dumps(config))
    37    print("Autoeagle configuration updated.")
    38    print(f"Manual adjustments can be made here: {configpath}")

Configure autoeagle configuration file.

###### Parameters

- eagledir: Path to user's Eagle directory. (Not the executable installation directory, but the one containing projects, libraries, ulps, etc.)

- ulpdir: Path to user's ulp directory. Only necessary if different from the standard ulp directory path.

- scriptsdir: Path to user's scripts directory. Only necessary if different from the standard scripts directory path.

def load_config() -> dict: View Source

    41def load_config() -> dict:
    42    """Load autoeagle configuration file."""
    43    config = tomlkit.loads((Path(__file__).parent / "autoeagle.toml").read_text())
    44    return config

Load autoeagle configuration file.

def prompt_to_configure() -> str: View Source

    47def prompt_to_configure() -> str:
    48    """Prompt user to provide their EAGLE
    49    directory path and configure autoeagletoml."""
    50    print("Autoeagle config file is not configured.")
    51    eagledir = input(
    52        "Enter path to your 'EAGLE' directory (contains projects, libraries, etc.): "
    53    )
    54    configure(eagledir)

Prompt user to provide their EAGLE directory path and configure autoeagletoml.

def get_args() -> argparse.Namespace: View Source

    57def get_args() -> argparse.Namespace:
    58    parser = argparse.ArgumentParser()
    59
    60    parser.add_argument(
    61        "-e",
    62        "--eagledir",
    63        type=str,
    64        help=""" Path to user's Eagle directory.
    65    (Not the executable installation directory, but the one containing
    66    projects, libraries, ulps, etc.) """,
    67    )
    68
    69    parser.add_argument(
    70        "-u",
    71        "--ulpdir",
    72        type=str,
    73        default=None,
    74        help=""" Path to user's ulp directory.
    75    Only necessary if different from the standard ulp
    76    directory path. """,
    77    )
    78
    79    parser.add_argument(
    80        "-s",
    81        "--scriptsdir",
    82        type=str,
    83        default=None,
    84        help=""" Path to user's scripts directory.
    85    Only necessary if different from the standard scripts
    86    directory path. """,
    87    )
    88
    89    args = parser.parse_args()
    90
    91    return args

def main(args: argparse.Namespace = None): View Source

    94def main(args: argparse.Namespace = None):
    95    if not args:
    96        args = get_args()
    97    configure(args.eagledir, args.ulpdir, args.scriptsdir)