mirror of
https://github.com/jo1gi/grawlix.git
synced 2025-12-23 06:56:24 +00:00
Add option to print config path
This commit is contained in:
parent
961789d316
commit
78312371d8
@ -1,5 +1,5 @@
|
|||||||
from .book import Book, Series
|
from .book import Book, Series
|
||||||
from .config import load_config, Config, SourceConfig
|
from .config import load_config, Config, SourceConfig, get_config_path
|
||||||
from .exceptions import SourceNotAuthenticated, GrawlixError
|
from .exceptions import SourceNotAuthenticated, GrawlixError
|
||||||
from .sources import load_source, Source
|
from .sources import load_source, Source
|
||||||
from .output import download_book
|
from .output import download_book
|
||||||
@ -87,8 +87,18 @@ async def authenticate(source: Source, config: Config, options):
|
|||||||
raise SourceNotAuthenticated
|
raise SourceNotAuthenticated
|
||||||
|
|
||||||
|
|
||||||
|
def run_debug_commands(options) -> None:
|
||||||
|
"""
|
||||||
|
Run optional debug commands if argument is set
|
||||||
|
"""
|
||||||
|
if options.print_config_path:
|
||||||
|
config_path = get_config_path()
|
||||||
|
print(config_path)
|
||||||
|
|
||||||
|
|
||||||
async def main() -> None:
|
async def main() -> None:
|
||||||
args = arguments.parse_arguments()
|
args = arguments.parse_arguments()
|
||||||
|
run_debug_commands(args)
|
||||||
config = load_config()
|
config = load_config()
|
||||||
logging.debug_mode = args.debug
|
logging.debug_mode = args.debug
|
||||||
urls = get_urls(args)
|
urls = get_urls(args)
|
||||||
|
|||||||
@ -14,6 +14,12 @@ def parse_arguments() -> argparse.Namespace:
|
|||||||
action = "version",
|
action = "version",
|
||||||
version = f"grawlix {__version__}"
|
version = f"grawlix {__version__}"
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--print-config-path',
|
||||||
|
action = "store_true",
|
||||||
|
help = "Print config path",
|
||||||
|
dest = "print_config_path"
|
||||||
|
)
|
||||||
# Basics
|
# Basics
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'urls',
|
'urls',
|
||||||
|
|||||||
@ -19,14 +19,20 @@ class Config:
|
|||||||
sources: dict[str, SourceConfig]
|
sources: dict[str, SourceConfig]
|
||||||
|
|
||||||
|
|
||||||
|
def get_config_path() -> str:
|
||||||
|
"""Return the path of the config file"""
|
||||||
|
config_dir = appdirs.user_config_dir("grawlix", "jo1gi")
|
||||||
|
config_file = os.path.join(config_dir, "grawlix.toml")
|
||||||
|
return config_file
|
||||||
|
|
||||||
|
|
||||||
def load_config() -> Config:
|
def load_config() -> Config:
|
||||||
"""
|
"""
|
||||||
Load config from disk
|
Load config from disk
|
||||||
|
|
||||||
:returns: Config object
|
:returns: Config object
|
||||||
"""
|
"""
|
||||||
config_dir = appdirs.user_config_dir("grawlix", "jo1gi")
|
config_file = get_config_path()
|
||||||
config_file = os.path.join(config_dir, "grawlix.toml")
|
|
||||||
if os.path.exists(config_file):
|
if os.path.exists(config_file):
|
||||||
with open(config_file, "rb") as f:
|
with open(config_file, "rb") as f:
|
||||||
config_dict = tomli.load(f)
|
config_dict = tomli.load(f)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user