Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use shopen instead of manual launch_editor impl #767

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading