Skip to content

Commit

Permalink
Use shopen instead of manual launch_editor impl
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarnett committed Sep 22, 2024
1 parent 8476a1d commit 7526388
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 26 deletions.
9 changes: 5 additions & 4 deletions gcalcli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'])
Expand Down Expand Up @@ -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':
Expand Down
22 changes: 0 additions & 22 deletions gcalcli/utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 ~.
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies = [
"platformdirs",
"pydantic",
"python-dateutil",
"shopen >= 0.2.2",
"toml; python_version < '3.11'",
"truststore",
]
Expand Down

0 comments on commit 7526388

Please sign in to comment.