Skip to content

Commit

Permalink
feat: Seek config file, and create a default one if it cannot be found
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaVandaele committed Dec 8, 2023
1 parent 3076565 commit fe8636a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include config.toml.default
Empty file added config/__init__.py
Empty file.
File renamed without changes.
11 changes: 3 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@
"Programming Language :: Python :: 3 :: Only",
],
keywords="ventoy, updater, os, iso, updater, sisou, cli", # Optional
# package_dir={"superisoupdater": "."}, # Optional
packages=find_packages(), # Required
py_modules=["sisou"], # Required
include_package_data=True,
package_data={"": ["config.toml.default"]},
python_requires=">=3.10, <4",
install_requires=[
"beautifulsoup4==4.12.2",
Expand All @@ -49,13 +50,6 @@
# "dev": [""],
# "test": [""],
# },
# If there are data files included in your packages that need to be
# installed, specify them here.
# package_data={ # Optional
# "sample": ["package_data.dat"],
# },
# Entry points. The following would provide a command called `sample` which
# executes the function `main` from this package when invoked:
entry_points={ # Optional
"console_scripts": [
"sisou = sisou:main",
Expand All @@ -65,4 +59,5 @@
"Bug Reports": "https://github.com/JoshuaVandaele/SuperISOUpdater/issues",
"Source": "https://github.com/JoshuaVandaele/SuperISOUpdater/",
},
zip_safe=False,
)
31 changes: 30 additions & 1 deletion sisou.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,36 @@ def main():

setup_logging(args.log_level, args.log_file)

config = parse_config(args.config_file or "config.toml")
config_file = args.config_file
if not config_file:
logging.info(
"No config file specified. Trying to find config.toml in the current directory..."
)
config_file = os.path.join(os.getcwd(), "config.toml")

if not os.path.isfile(config_file):
logging.info(
"No config file specified. Trying to find config.toml in the ventoy drive..."
)
config_file = os.path.join(args.ventoy_path, "config.toml")

if not os.path.isfile(config_file):
logging.info(
"No config.toml found in the ventoy drive. Generating one from config.toml.default..."
)
with open(
os.path.join(
os.path.dirname(__file__), "config", "config.toml.default"
)
) as default_config_file:
with open(config_file, "w") as new_config_file:
new_config_file.write(default_config_file.read())
logging.info(
"Generated config.toml in the ventoy drive. Please edit it to your liking and run sisou again."
)
return

config = parse_config(config_file)
if not config:
raise ValueError("Configuration file could not be parsed or is empty")

Expand Down

0 comments on commit fe8636a

Please sign in to comment.