diff --git a/gcalcli/cli.py b/gcalcli/cli.py index bca93b91..d7c77df4 100755 --- a/gcalcli/cli.py +++ b/gcalcli/cli.py @@ -20,15 +20,16 @@ # Everything you need to know (Google API Calendar v3): http://goo.gl/HfTGQ # # # # ######################################################################### # -from argparse import ArgumentTypeError import json import os import pathlib import re import signal import sys +from argparse import ArgumentTypeError from collections import namedtuple +import shopen import truststore from . import config, env, utils @@ -37,13 +38,13 @@ from .gcal import GoogleCalendarInterface from .printer import Printer, valid_color_name from .validators import ( - get_date_input_description, - get_input, PARSABLE_DATE, PARSABLE_DURATION, REMINDER, STR_ALLOW_EMPTY, STR_NOT_EMPTY, + get_date_input_description, + get_input, ) CalName = namedtuple('CalName', ['name', 'color']) @@ -339,7 +340,7 @@ def main(): if not config_filepath.exists(): with open(config_filepath, 'w') as f: f.write(EMPTY_CONFIG_TOML) - utils.launch_editor(config_filepath) + shopen.open(config_filepath, 'edit') elif parsed_args.command == 'util': if parsed_args.subcommand == 'config-schema': diff --git a/gcalcli/utils.py b/gcalcli/utils.py index f94cd4bb..6a2f354d 100644 --- a/gcalcli/utils.py +++ b/gcalcli/utils.py @@ -1,9 +1,7 @@ import calendar import locale -import os import pathlib import re -import subprocess import time from datetime import datetime, timedelta from typing import Tuple @@ -187,26 +185,6 @@ def localize_datetime(dt): return dt.astimezone(tzlocal()) -def launch_editor(path: str | os.PathLike): - if hasattr(os, 'startfile'): - os.startfile(path, 'edit') - return - for editor in ( - 'editor', - os.environ.get('EDITOR', None), - 'xdg-open', - 'open', - ): - if not editor: - continue - try: - subprocess.call((editor, path)) - return - except OSError: - pass - raise OSError(f'No editor/launcher detected on your system to edit {path}') - - def shorten_path(path: pathlib.Path) -> pathlib.Path: """Try to shorten path using special characters like ~. diff --git a/pyproject.toml b/pyproject.toml index 5da15535..cabab092 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,6 +35,7 @@ dependencies = [ "platformdirs", "pydantic", "python-dateutil", + "shopen >= 0.2.2", "toml; python_version < '3.11'", "truststore", ]