-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
command line tool to extract values from natlink.ini (#96)
- Loading branch information
1 parent
1504756
commit 6708e9e
Showing
3 changed files
with
60 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ build-backend = "flit_core.buildapi" | |
[project] | ||
name = "natlinkcore" | ||
authors = [{name = "Quintijn Hoogenboom (maintainer)", email = "[email protected]"}] | ||
version="5.4.2.dev5" | ||
version="5.4.2.dev6" | ||
dynamic = [ "description"] | ||
requires-python = ">=3.10" | ||
readme = "readme.md" | ||
|
@@ -54,6 +54,7 @@ testpaths= [ | |
[project.scripts] | ||
natlinkconfig_cli = "natlinkcore.configure.natlinkconfig_cli:main_cli" | ||
natlink_extensions = "natlinkcore.configure.natlink_extensions:main" | ||
natlink_extract_ini_value = "natlinkcore.configure.natlink_extract_ini_value:main" | ||
|
||
[project.gui-scripts] | ||
natlinkconfig_gui = "natlinkcore.configure.natlinkconfig_gui:main_gui" | ||
|
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,50 @@ | ||
import argparse | ||
import sys | ||
from natlinkcore.configure.natlinkconfigfunctions import NatlinkConfig | ||
import configparser | ||
from pathlib import Path | ||
import configparser | ||
|
||
def get_config_value(config, section, key): | ||
if not config.has_section(section): | ||
raise configparser.NoSectionError(section) | ||
if not config.has_option(section, key): | ||
raise configparser.NoOptionError(key, section) | ||
return config.get(section, key) | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description= | ||
f"""prints the value for the key in the section of natlink.ini to standard out. You can also ask for the full path to the ini file. | ||
for example, to get the dragonflyuserdirectory key in the directories section: | ||
{sys.argv[0]} --section 'directories' --key dragonflyuserdirectory | ||
""") | ||
parser.add_argument('-i', "--ini_file",action='store_true', help='print the full path to the natlink.ini file') | ||
|
||
|
||
|
||
parser.add_argument('-s', '--section', type=str, help='Section name') | ||
parser.add_argument('-k', '--key', type=str, help='Key name') | ||
|
||
args = parser.parse_args() | ||
|
||
|
||
try: | ||
config=NatlinkConfig() | ||
config_path=config.natlinkconfig_path | ||
config_file=Path(config_path)/"natlink.ini" | ||
if args.ini_file: | ||
print(config_file) | ||
exit(0) | ||
if not (args.key and args.section): | ||
raise Exception("Must supply key and section or -i/--ini_file") | ||
config=configparser.ConfigParser() | ||
config.read(config_file) | ||
v=get_config_value(config,args.section,args.key) | ||
print(f"{v}") | ||
except Exception as e: | ||
print(e) | ||
exit(-1) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |