diff --git a/bin/ikhal b/bin/ikhal index 45ed5d605..2e92d53b0 100644 --- a/bin/ikhal +++ b/bin/ikhal @@ -1,5 +1,5 @@ #!/usr/bin/env python from khal.cli import main_ikhal -if __name__ == "__main__": - main_ikhal() +if _name_ == "_main_": +    main_ikhal() diff --git a/bin/khal b/bin/khal index 425af7acd..1dbbc973a 100644 --- a/bin/khal +++ b/bin/khal @@ -1,5 +1,5 @@ #!/usr/bin/env python from khal.cli import main_khal -if __name__ == "__main__": - main_khal() +if _name_ == "_main_": +    main_khal() diff --git a/khal/controllers.py b/khal/controllers.py index abe36e9d7..90f7e9211 100644 --- a/khal/controllers.py +++ b/khal/controllers.py @@ -326,17 +326,34 @@ def khal_list( def new_interactive(collection, calendar_name, conf, info, location=None, categories=None, repeat=None, until=None, alarms=None, format=None, json=None, env=None, url=None): - info: EventCreationTypes - try: - info = parse_datetime.eventinfofstr( - info, conf['locale'], - default_event_duration=conf['default']['default_event_duration'], - default_dayevent_duration=conf['default']['default_dayevent_duration'], - adjust_reasonably=True, - ) - except DateTimeParseError: + # Vérifiez si info est une chaîne ou un dictionnaire, puis initialisez en conséquence + if isinstance(info, dict): + info_string = f"{info.get('summary', '')} {info.get('datetime_range', '')}" + elif isinstance(info, str): + info_string = info + info = {} # Réinitialisez `info` en dictionnaire après conversion + else: + info_string = "" info = {} + while True: + try: + # Passez une chaîne correctement formatée à `eventinfofstr` + parsed_info = parse_datetime.eventinfofstr( + info_string.strip(), + conf['locale'], + default_event_duration=conf['default']['default_event_duration'], + default_dayevent_duration=conf['default']['default_dayevent_duration'], + adjust_reasonably=True, + ) + info.update(parsed_info) # Mettez à jour `info` avec les données parsées + break # Sortir de la boucle si tout est valide + except DateTimeParseError as e: + echo(f"Error parsing information: {e}. Please correct the fields.") + summary = prompt('summary', default=info.get('summary', '')).strip() + datetime_range = prompt('datetime range', default=info.get('datetime_range', '')).strip() + info_string = f"{summary} {datetime_range}" + while True: summary = info.get('summary') if not summary: @@ -344,7 +361,7 @@ def new_interactive(collection, calendar_name, conf, info, location=None, info['summary'] = prompt('summary', default=summary) if info['summary']: break - echo("a summary is required") + echo("A summary is required.") while True: range_string = None @@ -353,14 +370,16 @@ def new_interactive(collection, calendar_name, conf, info, location=None, end_string = info["dtend"].strftime(conf['locale']['datetimeformat']) range_string = start_string + ' ' + end_string daterange = prompt("datetime range", default=range_string) - start, end, allday = parse_datetime.guessrangefstr( - daterange, conf['locale'], adjust_reasonably=True) - info['dtstart'] = start - info['dtend'] = end - info['allday'] = allday - if info['dtstart'] and info['dtend']: + try: + start, end, allday = parse_datetime.guessrangefstr( + daterange, conf['locale'], adjust_reasonably=True + ) + info['dtstart'] = start + info['dtend'] = end + info['allday'] = allday break - echo("invalid datetime range") + except ValueError: + echo("Invalid datetime range, please try again.") while True: tz = info.get('timezone') or conf['locale']['default_timezone'] @@ -370,9 +389,9 @@ def new_interactive(collection, calendar_name, conf, info, location=None, info['timezone'] = tz break except pytz.UnknownTimeZoneError: - echo("unknown timezone") + echo("Unknown timezone, please enter a valid timezone.") - info['description'] = prompt("description (or 'None')", default=info.get('description')) + info['description'] = prompt("description (or 'None')", default=info.get('description', '')) if info['description'] == 'None': info['description'] = '' @@ -394,7 +413,7 @@ def new_interactive(collection, calendar_name, conf, info, location=None, calendar_name=calendar_name, json=json, ) - echo("event saved") + echo("Event saved.") term_width, _ = get_terminal_size() edit_event(event, collection, conf['locale'], width=term_width) diff --git a/khal/utils.py b/khal/utils.py index 78f525bbd..df7fd7664 100644 --- a/khal/utils.py +++ b/khal/utils.py @@ -216,17 +216,45 @@ def fmt(rows): CONTENT_ATTRIBUTES = ['start', 'start-long', 'start-date', 'start-date-long', - 'start-time', 'end', 'end-long', 'end-date', 'end-date-long', 'end-time', - 'duration', 'start-full', 'start-long-full', 'start-date-full', - 'start-date-long-full', 'start-time-full', 'end-full', 'end-long-full', - 'end-date-full', 'end-date-long-full', 'end-time-full', 'duration-full', 'start-style', 'end-style', 'to-style', 'start-end-time-style', 'end-necessary', 'end-necessary-long', 'repeat-symbol', 'repeat-pattern', 'title', 'organizer', 'description', 'location', 'all-day', 'categories', - 'uid', 'url', 'calendar', 'calendar-color', 'status', 'cancelled'] + 'uid', 'url', 'calendar', 'calendar-color', 'status', 'cancelled', 'attendees'] + def json_formatter(fields): + """Create a formatter that formats events in JSON.""" + if len(fields) == 1 and fields[0] == 'all': + fields = CONTENT_ATTRIBUTES + + def fmt(rows): + single = isinstance(rows, dict) + if single: + rows = [rows] + + filtered = [] + for row in rows: + row['attendees'] = row.get('attendees', '') # Ajout d'une valeur par défaut + f = dict(filter(lambda e: e[0] in fields and e[0] in CONTENT_ATTRIBUTES, row.items())) + + if f.get('repeat-symbol', '') != '': + f["repeat-symbol"] = f["repeat-symbol"].strip() + if f.get('status', '') != '': + f["status"] = f["status"].strip() + if f.get('cancelled', '') != '': + f["cancelled"] = f["cancelled"].strip() + + filtered.append(f) + + results = [json.dumps(filtered, ensure_ascii=False)] + + if single: + return results[0] + else: + return results + return fmt + """Create a formatter that formats events in JSON.""" if len(fields) == 1 and fields[0] == 'all': @@ -239,7 +267,10 @@ def fmt(rows): filtered = [] for row in rows: + print(f"Processing row: {row}") # Affiche les données brutes + row['attendees'] = row.get('attendees', '') f = dict(filter(lambda e: e[0] in fields and e[0] in CONTENT_ATTRIBUTES, row.items())) + print(f"Filtered row: {f}") # Affiche les données filtrées if f.get('repeat-symbol', '') != '': f["repeat-symbol"] = f["repeat-symbol"].strip() diff --git a/myenv/bin/python b/myenv/bin/python new file mode 120000 index 000000000..b8a0adbbb --- /dev/null +++ b/myenv/bin/python @@ -0,0 +1 @@ +python3 \ No newline at end of file diff --git a/myenv/bin/python3 b/myenv/bin/python3 new file mode 120000 index 000000000..ae65fdaa1 --- /dev/null +++ b/myenv/bin/python3 @@ -0,0 +1 @@ +/usr/bin/python3 \ No newline at end of file diff --git a/myenv/bin/python3.11 b/myenv/bin/python3.11 new file mode 120000 index 000000000..b8a0adbbb --- /dev/null +++ b/myenv/bin/python3.11 @@ -0,0 +1 @@ +python3 \ No newline at end of file diff --git a/myenv/lib64 b/myenv/lib64 new file mode 120000 index 000000000..7951405f8 --- /dev/null +++ b/myenv/lib64 @@ -0,0 +1 @@ +lib \ No newline at end of file diff --git a/myenv/pyvenv.cfg b/myenv/pyvenv.cfg new file mode 100644 index 000000000..6ebfc6387 --- /dev/null +++ b/myenv/pyvenv.cfg @@ -0,0 +1,5 @@ +home = /usr/bin +include-system-site-packages = false +version = 3.11.2 +executable = /usr/bin/python3.11 +command = /usr/bin/python3 -m venv /home/bini/khal/myenv