-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
253 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# CONTRIBUTING | ||
|
||
Code contributions are welcome and appreciated. Just submit a PR! | ||
|
||
The current build environment uses `pre-commit`, and `hatch`. | ||
|
||
### Environment setup: | ||
|
||
```console | ||
pip install hatch | ||
git clone [email protected]:afourney/aprstastic.git | ||
cd aprstastic | ||
pre-commit install | ||
|
||
# Optionally run the pre-commit scripts at any time | ||
pre-commit run --all-files | ||
``` | ||
|
||
### Running and testing: | ||
|
||
From the aprstastic directory: | ||
|
||
```console | ||
hatch shell | ||
|
||
# Running | ||
python -m aprstastic | ||
|
||
|
||
# Testing | ||
hatch test | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# SPDX-FileCopyrightText: 2024-present Adam Fourney <[email protected]> | ||
# | ||
# SPDX-License-Identifier: MIT | ||
__version__ = "0.0.1a12" | ||
__version__ = "0.0.1a14" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
# SPDX-FileCopyrightText: 2024-present Adam Fourney <[email protected]> | ||
# | ||
# SPDX-License-Identifier: MIT | ||
import os | ||
import json | ||
import time | ||
import shutil | ||
|
||
from aprstastic._config import ( | ||
ConfigError, | ||
init_config, | ||
CONFIG_FILE_NAME, | ||
LOGS_SUBDIR, | ||
DATA_SUBDIR, | ||
DEFAULT_CALL_SIGN, | ||
) | ||
|
||
|
||
TEST_CONFIG_FILE_NAME_1 = "test_aprstastic_1.yaml" | ||
TEST_CONFIG_FILE_NAME_2 = "test_aprstastic_2.yaml" | ||
config_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "test_data") | ||
|
||
# Monkey patch the default directory | ||
import aprstastic._config | ||
|
||
aprstastic._config.DEFAULT_DATA_DIR = config_dir | ||
|
||
logs_dir = os.path.join(config_dir, LOGS_SUBDIR) | ||
data_dir = os.path.join(config_dir, DATA_SUBDIR) | ||
|
||
|
||
def test_initialize_config(): | ||
config_file = os.path.join(config_dir, CONFIG_FILE_NAME) | ||
|
||
# Start fresh | ||
if os.path.isfile(config_file): | ||
os.unlink(config_file) | ||
|
||
assert not os.path.isfile(config_file) | ||
|
||
cwd = os.path.abspath(os.getcwd()) | ||
error_msg = None | ||
try: | ||
os.chdir(config_dir) | ||
|
||
# Initialize the config | ||
config = init_config() | ||
|
||
except ConfigError as e: | ||
error_msg = str(e) | ||
finally: | ||
os.chdir(cwd) | ||
|
||
# Make sure the sample config exists now | ||
assert os.path.isfile(config_file) | ||
# assert os.path.isdir(logs_dir) | ||
# assert os.path.isdir(data_dir) | ||
|
||
# Make sure the correct error was thrown | ||
assert "A sample configuration was written" in error_msg | ||
|
||
# Try loading it again, and check that the correct error was thrown the second time | ||
try: | ||
os.chdir(config_dir) | ||
config = init_config() | ||
except ConfigError as e: | ||
error_msg = str(e) | ||
finally: | ||
os.chdir(cwd) | ||
assert "appears to be the sample config" in error_msg | ||
|
||
|
||
def test_load_config(): | ||
config_file = os.path.join(config_dir, CONFIG_FILE_NAME) | ||
test_config_file_1 = os.path.join(config_dir, TEST_CONFIG_FILE_NAME_1) | ||
test_config_file_2 = os.path.join(config_dir, TEST_CONFIG_FILE_NAME_2) | ||
|
||
mylogs_dir = os.path.join(config_dir, "mylogs") | ||
mydata_dir = os.path.join(config_dir, "mydata") | ||
|
||
# Install our test config #1 | ||
shutil.copyfile(test_config_file_1, config_file) | ||
|
||
# Load the config | ||
cwd = os.path.abspath(os.getcwd()) | ||
error_msg = None | ||
try: | ||
os.chdir(config_dir) | ||
config = init_config() | ||
finally: | ||
os.chdir(cwd) | ||
|
||
# Check that it looks right | ||
assert config == json.loads( | ||
""" | ||
{ | ||
"gateway": { | ||
"call_sign": "N0CALL-1", | ||
"aprsis_passcode": 12345, | ||
"meshtastic_interface": { | ||
"type": "serial" | ||
}, | ||
"beacon_registrations": true, | ||
"data_dir": "%s", | ||
"logs_dir": "%s" | ||
}, | ||
"licensed_operators": {} | ||
} | ||
""" | ||
% (data_dir, logs_dir) | ||
) | ||
|
||
# Install our test config #2 | ||
shutil.copyfile(test_config_file_2, config_file) | ||
|
||
# Load the config | ||
cwd = os.path.abspath(os.getcwd()) | ||
error_msg = None | ||
try: | ||
os.chdir(config_dir) | ||
config = init_config() | ||
finally: | ||
os.chdir(cwd) | ||
|
||
# Check that it looks right | ||
assert config == json.loads( | ||
""" | ||
{ | ||
"gateway": { | ||
"call_sign": "N0CALL-2", | ||
"aprsis_passcode": 12345, | ||
"meshtastic_interface": { | ||
"type": "serial" | ||
}, | ||
"beacon_registrations": false, | ||
"data_dir": "%s", | ||
"logs_dir": "%s" | ||
}, | ||
"licensed_operators": {} | ||
} | ||
""" | ||
% (mydata_dir, mylogs_dir) | ||
) | ||
|
||
|
||
########################## | ||
if __name__ == "__main__": | ||
import logging | ||
|
||
logging.basicConfig(level=logging.DEBUG) | ||
test_initialize_config() | ||
test_load_config() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# | ||
# APRSTASTIC CONFIGURATION FILE (version: 1) | ||
# Be sure to at least modify 'call_sign' and 'aprsis_passcode'. | ||
# | ||
|
||
# Radio call sign of the gateway itself (analogy, iGate's call sign) | ||
call_sign: N0CALL-1 | ||
|
||
# APRS-IS passcode. Search Google for how to get this | ||
aprsis_passcode: 12345 | ||
|
||
# Only serial devices are supported right now. | ||
# If 'device' is null (or commented out), an attempt will be made to | ||
# detected it automatically. | ||
meshtastic_interface: | ||
type: serial | ||
# device: /dev/ttyACM0 | ||
|
||
# Beacon new registrations to APRS-IS to facilitate discovery | ||
beacon_registrations: true | ||
# Where should logs be stored? | ||
# If null, (or commented out), store logs in the `logs` dir, sibling to this file. | ||
#logs_dir: null | ||
|
||
# Where should data be stored? | ||
# If null, (or commented out), store data in the `data` dir, sibling to this file. | ||
#data_dir: null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# | ||
# APRSTASTIC CONFIGURATION FILE (version: 1) | ||
# Be sure to at least modify 'call_sign' and 'aprsis_passcode'. | ||
# | ||
|
||
# Radio call sign of the gateway itself (analogy, iGate's call sign) | ||
call_sign: N0CALL-2 | ||
|
||
# APRS-IS passcode. Search Google for how to get this | ||
aprsis_passcode: 12345 | ||
|
||
# Only serial devices are supported right now. | ||
# If 'device' is null (or commented out), an attempt will be made to | ||
# detected it automatically. | ||
meshtastic_interface: | ||
type: serial | ||
# device: /dev/ttyACM0 | ||
|
||
# Beacon new registrations to APRS-IS to facilitate discovery | ||
beacon_registrations: false | ||
|
||
# Where should logs be stored? | ||
# If null, (or commented out), store logs in the `logs` dir, sibling to this file. | ||
logs_dir: mylogs | ||
|
||
# Where should data be stored? | ||
# If null, (or commented out), store data in the `data` dir, sibling to this file. | ||
data_dir: mydata |