Exemple #1
0
def new_from_string(collection,
                    calendar_name,
                    conf,
                    info,
                    location=None,
                    categories=None,
                    repeat=None,
                    until=None,
                    alarms=None,
                    format=None,
                    env=None):
    """construct a new event from a string and add it"""
    info = utils.eventinfofstr(info,
                               conf['locale'],
                               adjust_reasonably=True,
                               localize=False)
    new_from_args(collection,
                  calendar_name,
                  conf,
                  format=format,
                  env=env,
                  location=location,
                  categories=categories,
                  repeat=repeat,
                  until=until,
                  alarms=alarms,
                  **info)
Exemple #2
0
def _construct_event(info,
                     locale,
                     defaulttimelen=60,
                     defaultdatelen=1,
                     description=None,
                     location=None,
                     categories=None,
                     repeat=None,
                     until=None,
                     alarm=None,
                     **kwargs):
    info = eventinfofstr(' '.join(info),
                         locale,
                         adjust_reasonably=True,
                         localize=False)
    if description is not None:
        info["description"] = description
    event = new_event(locale=locale,
                      location=location,
                      categories=categories,
                      repeat=repeat,
                      until=until,
                      alarms=alarm,
                      **info)
    return event
Exemple #3
0
def new_interactive(collection, calendar_name, conf, info, location=None,
                    categories=None, repeat=None, until=None, alarms=None,
                    format=None, env=None):
    try:
        info = utils.eventinfofstr(info, conf['locale'], adjust_reasonably=True, localize=False)
    except ValueError:
        info = dict()

    while True:
        summary = info.get('summary')
        if not summary:
            summary = None
        info['summary'] = prompt('summary', default=summary)
        if info['summary']:
            break
        echo("a summary is required")

    while True:
        range_string = None
        if info.get('dtstart') and info.get('dtend'):
            start_string = info["dtstart"].strftime(conf['locale']['datetimeformat'])
            end_string = info["dtend"].strftime(conf['locale']['datetimeformat'])
            range_string = start_string + ' ' + end_string
        daterange = prompt("datetime range", default=range_string)
        start, end, allday = utils.guessrangefstr(
            daterange, conf['locale'], adjust_reasonably=True)
        info['dtstart'] = start
        info['dtend'] = end
        info['allday'] = allday
        if info['dtstart'] and info['dtend']:
            break
        echo("invalid datetime range")

    while True:
        tz = info.get('timezone') or conf['locale']['default_timezone']
        timezone = prompt("timezone", default=str(tz))
        try:
            tz = pytz.timezone(timezone)
            info['timezone'] = tz
            break
        except pytz.UnknownTimeZoneError:
            echo("unknown timezone")

    info['description'] = prompt("description (or 'None')", default=info.get('description'))
    if info['description'] == 'None':
        info['description'] = ''

    event = new_from_args(
        collection, calendar_name, conf, format=format, env=env,
        location=location, categories=categories,
        repeat=repeat, until=until, alarms=alarms,
        **info)

    echo("event saved")

    term_width, _ = get_terminal_size()
    edit_event(event, collection, conf['locale'], width=term_width)
Exemple #4
0
def new_from_string(collection, calendar_name, conf, info, location=None,
                    categories=None, repeat=None, until=None, alarms=None,
                    format=None, env=None):
    """construct a new event from a string and add it"""
    info = utils.eventinfofstr(
        info, conf['locale'], default_timedelta="60m", adjust_reasonably=True, localize=False)
    new_from_args(collection, calendar_name, conf, format=format, env=env,
                  location=location, categories=categories, repeat=repeat,
                  until=until, alarms=alarms, **info)
Exemple #5
0
def _construct_event(info, locale,
                     defaulttimelen=60, defaultdatelen=1, description=None,
                     location=None, categories=None, repeat=None, until=None,
                     alarm=None, **kwargs):
    info = eventinfofstr(' '.join(info), locale, default_timedelta=str(defaulttimelen) + 'm',
                         adjust_reasonably=True, localize=False)
    if description is not None:
        info["description"] = description
    event = new_event(locale=locale, location=location,
                      categories=categories, repeat=repeat, until=until,
                      alarms=alarm, **info)
    return event
Exemple #6
0
def new_interactive(collection, calendar_name, conf, info, location=None,
                    categories=None, repeat=None, until=None, alarms=None,
                    format=None, env=None):
    info = utils.eventinfofstr(
        info, conf['locale'], default_timedelta="60m", adjust_reasonably=True, localize=False)
    while True:
        summary = info["summary"]
        if not summary:
            summary = None
        info['summary'] = prompt("summary", default=summary)
        if info['summary']:
            break
        echo("a summary is required")

    while True:
        range_string = None
        if info["dtstart"] and info["dtend"]:
            start_string = info["dtstart"].strftime(conf['locale']['datetimeformat'])
            end_string = info["dtend"].strftime(conf['locale']['datetimeformat'])
            range_string = start_string + ' ' + end_string
        daterange = prompt("datetime range", default=range_string)
        start, end, allday = utils.guessrangefstr(
            daterange, conf['locale'], default_timedelta='60m', adjust_reasonably=True)
        info['dtstart'] = start
        info['dtend'] = end
        info['allday'] = allday
        if info['dtstart'] and info['dtend']:
            break
        echo("invalid datetime range")

    while True:
        tz = info['timezone'] or conf['locale']['default_timezone']
        timezone = prompt("timezone", default=str(tz))
        try:
            tz = pytz.timezone(timezone)
            info['timezone'] = tz
            break
        except pytz.UnknownTimeZoneError:
            echo('unknown timezone')

    info['description'] = prompt('description (or "None")', default=info['description'])
    if info['description'] == "None":
        info['description'] = ''

    event = new_from_args(collection, calendar_name, conf, format=format, env=env,
                          location=location, categories=categories,
                          repeat=repeat, until=until, alarms=alarms, **info)

    echo("event saved")

    term_width, _ = get_terminal_size()
    edit_event(event, collection, conf['locale'], width=term_width)