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

Fix: Allow --config to specify a custom configuration path #1378

Open
wants to merge 2 commits into
base: master
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
11 changes: 11 additions & 0 deletions UNKNOWN.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Metadata-Version: 2.1
Name: UNKNOWN
Version: 0.1.dev2720+g106e4d0
Summary: UNKNOWN
Home-page: UNKNOWN
License: UNKNOWN
Platform: UNKNOWN
License-File: COPYING
License-File: AUTHORS.txt

UNKNOWN
188 changes: 188 additions & 0 deletions UNKNOWN.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
.coveragerc
.gitignore
.pre-commit-config.yaml
.readthedocs.yml
AUTHORS.txt
CHANGELOG.rst
CODE_OF_CONDUCT.rst
CONTRIBUTING.rst
COPYING
MANIFEST.in
README.rst
codecov.yml
khal.conf.sample
pyproject.toml
tox.ini
.github/ISSUE_TEMPLATE/bug_report.md
.github/workflows/ci.yml
UNKNOWN.egg-info/PKG-INFO
UNKNOWN.egg-info/SOURCES.txt
UNKNOWN.egg-info/dependency_links.txt
UNKNOWN.egg-info/top_level.txt
bin/ikhal
bin/khal
doc/Makefile
doc/source/changelog.rst
doc/source/conf.py
doc/source/configure.rst
doc/source/faq.rst
doc/source/feedback.rst
doc/source/hacking.rst
doc/source/index.rst
doc/source/install.rst
doc/source/license.rst
doc/source/man.rst
doc/source/news.rst
doc/source/standards.rst
doc/source/usage.rst
doc/source/images/rss.png
doc/source/news/30c3.rst
doc/source/news/31c3.rst
doc/source/news/callfortesting.rst
doc/source/news/khal01.rst
doc/source/news/khal0100.rst
doc/source/news/khal011.rst
doc/source/news/khal02.rst
doc/source/news/khal03.rst
doc/source/news/khal031.rst
doc/source/news/khal04.rst
doc/source/news/khal05.rst
doc/source/news/khal06.rst
doc/source/news/khal07.rst
doc/source/news/khal071.rst
doc/source/news/khal08.rst
doc/source/news/khal081.rst
doc/source/news/khal082.rst
doc/source/news/khal083.rst
doc/source/news/khal084.rst
doc/source/news/khal09.rst
doc/source/news/khal091.rst
doc/source/news/khal092.rst
doc/source/news/khal093.rst
doc/source/news/khal094.rst
doc/source/news/khal095.rst
doc/source/news/khal096.rst
doc/source/news/khal097.rst
doc/source/news/khal098.rst
doc/source/ystatic/.gitignore
doc/source/ytemplates/layout.html
doc/webpage/src/new_rss_url.rst
khal/__init__.py
khal/__main__.py
khal/_compat.py
khal/calendar_display.py
khal/cli.py
khal/cli_utils.py
khal/configwizard.py
khal/controllers.py
khal/custom_types.py
khal/exceptions.py
khal/icalendar.py
khal/parse_datetime.py
khal/plugins.py
khal/terminal.py
khal/utils.py
khal/khalendar/__init__.py
khal/khalendar/backend.py
khal/khalendar/event.py
khal/khalendar/exceptions.py
khal/khalendar/khalendar.py
khal/khalendar/typing.py
khal/khalendar/vdir.py
khal/settings/__init__.py
khal/settings/exceptions.py
khal/settings/khal.spec
khal/settings/settings.py
khal/settings/utils.py
khal/ui/__init__.py
khal/ui/base.py
khal/ui/calendarwidget.py
khal/ui/colors.py
khal/ui/editor.py
khal/ui/widgets.py
misc/khal.desktop
misc/mutt2khal
tests/__init__.py
tests/backend_test.py
tests/cal_display_test.py
tests/cli_test.py
tests/configwizard_test.py
tests/conftest.py
tests/controller_test.py
tests/event_test.py
tests/icalendar_test.py
tests/khalendar_test.py
tests/khalendar_utils_test.py
tests/parse_datetime_test.py
tests/settings_test.py
tests/terminal_test.py
tests/utils.py
tests/utils_test.py
tests/vdir_test.py
tests/vtimezone_test.py
tests/configs/nocalendars.conf
tests/configs/one_level_calendars.conf
tests/configs/simple.conf
tests/configs/small.conf
tests/ics/cal_d.ics
tests/ics/cal_dt_two_tz.ics
tests/ics/cal_lots_of_timezones.ics
tests/ics/cal_no_dst.ics
tests/ics/event_d.ics
tests/ics/event_d_15.ics
tests/ics/event_d_long.ics
tests/ics/event_d_no_value.ics
tests/ics/event_d_rdate.ics
tests/ics/event_d_rr.ics
tests/ics/event_d_same_start_end.ics
tests/ics/event_dt_description.ics
tests/ics/event_dt_duration.ics
tests/ics/event_dt_floating.ics
tests/ics/event_dt_local_missing_tz.ics
tests/ics/event_dt_london.ics
tests/ics/event_dt_long.ics
tests/ics/event_dt_mixed_awareness.ics
tests/ics/event_dt_multi_recuid_no_master.ics
tests/ics/event_dt_multi_uid.ics
tests/ics/event_dt_no_end.ics
tests/ics/event_dt_partstat.ics
tests/ics/event_dt_rd.ics
tests/ics/event_dt_recuid_no_master.ics
tests/ics/event_dt_rr.ics
tests/ics/event_dt_rrule_invalid_until.ics
tests/ics/event_dt_rrule_invalid_until2.ics
tests/ics/event_dt_rrule_until_before_start.ics
tests/ics/event_dt_simple.ics
tests/ics/event_dt_simple_inkl_vtimezone.ics
tests/ics/event_dt_simple_nocat.ics
tests/ics/event_dt_simple_updated.ics
tests/ics/event_dt_simple_zulu.ics
tests/ics/event_dt_status_confirmed.ics
tests/ics/event_dt_two_rd.ics
tests/ics/event_dt_two_tz.ics
tests/ics/event_dt_url.ics
tests/ics/event_dtr_exdatez.ics
tests/ics/event_dtr_no_tz_exdatez.ics
tests/ics/event_dtr_notz_untilz.ics
tests/ics/event_invalid_exdate.ics
tests/ics/event_no_dst.ics
tests/ics/event_r_past.ics
tests/ics/event_rdate_no_value.ics
tests/ics/event_rrule_no_occurence.ics
tests/ics/event_rrule_recuid.ics
tests/ics/event_rrule_recuid_cancelled.ics
tests/ics/event_rrule_recuid_invalid_tzid.ics
tests/ics/event_rrule_recuid_update.ics
tests/ics/invalid_tzoffset.ics
tests/ics/mult_uids_and_recuid_no_order.ics
tests/ics/non_dst_error.ics
tests/ics/part0.ics
tests/ics/part1.ics
tests/ics/tz_windows_format.ics
tests/ics/without_uid.ics
tests/ui/__init__.py
tests/ui/canvas_render.py
tests/ui/test_calendarwidget.py
tests/ui/test_editor.py
tests/ui/test_walker.py
tests/ui/test_widgets.py
Empty file.
1 change: 1 addition & 0 deletions khal.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ monthdisplay = firstday

[default]
default_calendar = home
immediate_deletion = true
timedelta = 2d # the default timedelta that list uses
highlight_event_days = True # the default is False
enable_mouse = True # mouse is enabled by default in interactive mode
37 changes: 30 additions & 7 deletions khal/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,22 @@ def get_command(self, ctx, name):
@global_options
@click.pass_context
def cli(ctx, config):
# setting the process title so it looks nicer in ps
# shows up as 'khal' under linux and as 'python: khal (python2.7)'
# under FreeBSD, which is still nicer than the default
"""Command-line interface for khal."""
setproctitle('khal')
if ctx.logfilepath:
# S'assurer que ctx.obj est initialisé
if ctx.obj is None:
ctx.ensure_object(dict)

# Gestion de logfilepath
if ctx.obj.get('logfilepath'):
logger = logging.getLogger('khal')
logger.handlers = [logging.FileHandler(ctx.logfilepath)]
logger.handlers = [logging.FileHandler(ctx.obj['logfilepath'])]

prepare_context(ctx, config)




@cli.command()
@multi_calendar_option
@click.option('--format', '-f',
Expand Down Expand Up @@ -554,16 +561,32 @@ def at(ctx, datetime, notstarted, format, day_format, json, include_calendar, ex
sys.exit(1)

@cli.command()
@click.option(
'--config', '-c',
default=None,
help='Path to the configuration file to use.'
)
@click.pass_context
def configure(ctx):
def configure(ctx, config):
"""Helper for initial configuration of khal."""
config_path = config or ctx.obj.get('config')


from . import configwizard
try:
configwizard.configwizard()
configwizard.configwizard(config_path=config_path)
except FatalError as error:
logger.debug(error, exc_info=True)
logger.fatal(error)
sys.exit(1)










main_khal, main_ikhal = cli, interactive_cli
23 changes: 20 additions & 3 deletions khal/cli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,24 @@ def calendar_option(f):


def global_options(f):
def config_callback(ctx, option, value):
# S'assurer que ctx.obj est initialisé
if ctx.obj is None:
ctx.ensure_object(dict)
ctx.obj['config'] = value # Stocker la valeur dans ctx.obj
def color_callback(ctx, option, value):
ctx.color = value

def logfile_callback(ctx, option, path):
ctx.logfilepath = path
if ctx.obj is None:
ctx.ensure_object(dict)
ctx.obj['logfilepath'] = path # Stocker logfilepath dans ctx.obj


config = click.option(
'--config', '-c',
help='The config file to use.',
default=None, metavar='PATH'
default=None, metavar='PATH',callback=config_callback
)
color = click.option(
'--color/--no-color',
Expand All @@ -144,6 +152,8 @@ def logfile_callback(ctx, option, path):
return logfile(config(color(version(f))))




def build_collection(conf, selection):
"""build and return a khalendar.CalendarCollection from the configuration"""
try:
Expand Down Expand Up @@ -188,6 +198,13 @@ def __getitem__(self, key):


def prepare_context(ctx, config):
# Vérifier si ctx.obj est déjà initialisé
if ctx.obj is not None:
logger.debug(f"DEBUG: ctx.obj already initialized with: {ctx.obj}")
# Si ctx.obj est déjà initialisé, ne pas le réinitialiser
return

# Ancien comportement si ctx.obj est None
assert ctx.obj is None

logger.debug('khal %s' % __version__)
Expand All @@ -203,9 +220,9 @@ def prepare_context(ctx, config):
logger.debug('Using config:')
logger.debug(stringify_conf(conf))

# Initialisation de ctx.obj
ctx.obj = {'conf_path': config, 'conf': conf}


def stringify_conf(conf):
# since we have only two levels of recursion, a recursive function isn't
# really worth it
Expand Down
Loading