summaryrefslogtreecommitdiff
path: root/poezio
diff options
context:
space:
mode:
authorMaxime “pep” Buquet <pep@bouah.net>2022-08-21 22:53:40 +0200
committerMaxime “pep” Buquet <pep@bouah.net>2022-08-23 11:44:11 +0200
commit10cc67e6c78ca37508ba30cba42baa68c8fff5a3 (patch)
tree35a040ed084f389937675218341ff7d2319315d4 /poezio
parentc68b00ae248476751935499dbe5fb151e2919569 (diff)
downloadpoezio-10cc67e6c78ca37508ba30cba42baa68c8fff5a3.tar.gz
poezio-10cc67e6c78ca37508ba30cba42baa68c8fff5a3.tar.bz2
poezio-10cc67e6c78ca37508ba30cba42baa68c8fff5a3.tar.xz
poezio-10cc67e6c78ca37508ba30cba42baa68c8fff5a3.zip
roezio: migrate poezio/args.py
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
Diffstat (limited to 'poezio')
-rw-r--r--poezio/args.py86
-rw-r--r--poezio/libpoezio.pyi2
-rw-r--r--poezio/poezio.py4
3 files changed, 4 insertions, 88 deletions
diff --git a/poezio/args.py b/poezio/args.py
deleted file mode 100644
index 3907fc88..00000000
--- a/poezio/args.py
+++ /dev/null
@@ -1,86 +0,0 @@
-"""
-Module related to the argument parsing
-"""
-import pkg_resources
-import stat
-import sys
-from argparse import ArgumentParser, SUPPRESS, Namespace
-from pathlib import Path
-from shutil import copy2
-from typing import Tuple
-
-from poezio.version import __version__
-from poezio import xdg
-
-
-def parse_args(CONFIG_PATH: Path):
- """
- Parse the arguments from the command line
- """
- parser = ArgumentParser('poezio')
- parser.add_argument(
- "-c",
- "--check-config",
- dest="check_config",
- action='store_true',
- help='Check the config file')
- parser.add_argument(
- "-d",
- "--debug",
- dest="debug",
- help="The file where debug will be written",
- metavar="DEBUG_FILE")
- parser.add_argument(
- "-f",
- "--file",
- dest="filename",
- default=CONFIG_PATH / 'poezio.cfg',
- type=Path,
- help="The config file you want to use",
- metavar="CONFIG_FILE")
- parser.add_argument(
- '-v',
- '--version',
- action='version',
- version='Poezio v%s' % __version__,
- )
- parser.add_argument(
- "--custom-version",
- dest="custom_version",
- help=SUPPRESS,
- metavar="VERSION",
- default=__version__
- )
- return parser.parse_args()
-
-
-def run_cmdline_args() -> Tuple[Namespace, bool]:
- "Parse the command line arguments"
- options = parse_args(xdg.CONFIG_HOME)
- firstrun = False
-
- # Copy a default file if none exists
- if not options.filename.is_file():
- try:
- options.filename.parent.mkdir(parents=True, exist_ok=True)
- except OSError as e:
- sys.stderr.write(
- 'Poezio was unable to create the config directory: %s\n' % e)
- sys.exit(1)
- default = Path(__file__).parent / '..' / 'data' / 'default_config.cfg'
- other = Path(
- pkg_resources.resource_filename('poezio', 'default_config.cfg'))
- if default.is_file():
- copy2(str(default), str(options.filename))
- elif other.is_file():
- copy2(str(other), str(options.filename))
-
- # Inside the nixstore and possibly other distributions, the reference
- # file is readonly, so is the copy.
- # Make it writable by the user who just created it.
- if options.filename.exists():
- options.filename.chmod(options.filename.stat().st_mode
- | stat.S_IWUSR)
- firstrun = True
-
- return (options, firstrun)
diff --git a/poezio/libpoezio.pyi b/poezio/libpoezio.pyi
index e02e0a0f..1212d2c2 100644
--- a/poezio/libpoezio.pyi
+++ b/poezio/libpoezio.pyi
@@ -1,2 +1,4 @@
+from typing import Any, Dict, List, Tuple
def to_curses_attr(fg: int, bg: int, attrs: str) -> int: ...
+def run_cmdline_args(argv: List[str]) -> Tuple[Dict[Any, Any], bool]: ...
diff --git a/poezio/poezio.py b/poezio/poezio.py
index b149abd4..3b83f7c7 100644
--- a/poezio/poezio.py
+++ b/poezio/poezio.py
@@ -79,8 +79,8 @@ def main():
sys.stdout.write("\x1b]0;poezio\x07")
sys.stdout.flush()
- from poezio.args import run_cmdline_args
- options, firstrun = run_cmdline_args()
+ from poezio.libpoezio import run_cmdline_args
+ options, firstrun = run_cmdline_args(sys.argv)
from poezio import config
config.create_global_config(options.filename)
config.setup_logging(options.debug)