def test_handle_unparsed(): # minimal test showing that we can parse a global option after the # subcommand (in some cases) parser = argparsers.get_argument_parser() argv = shlex.split('delete --calendar=test "search text"') parsed, unparsed = parser.parse_known_args(argv) parsed = argparsers.handle_unparsed(unparsed, parsed) assert parsed.calendar == ['test']
def test_handle_unparsed(): # minimal test showing that we can parse a global option after the # subcommand (in some cases) parser = argparsers.get_argument_parser() argv = shlex.split('delete --calendar=test "search text"') parsed, unparsed = parser.parse_known_args(argv) parsed = argparsers.handle_unparsed(unparsed, parsed) assert parsed.calendar == ['test']
def main(): parser = get_argument_parser() try: argv = sys.argv[1:] gcalclirc = os.path.expanduser('~/.gcalclirc') if os.path.exists(gcalclirc): # We want .gcalclirc to be sourced before any other --flagfile # params since we may be told to use a specific config folder, we # need to store generated argv in temp variable tmp_argv = [ '@%s' % gcalclirc, ] + argv else: tmp_argv = argv (parsed_args, unparsed) = parser.parse_known_args(tmp_argv) except Exception as e: sys.stderr.write(str(e)) parser.print_usage() sys.exit(1) if parsed_args.config_folder: if not os.path.exists(os.path.expanduser(parsed_args.config_folder)): os.makedirs(os.path.expanduser(parsed_args.config_folder)) if os.path.exists( os.path.expanduser('%s/gcalclirc' % parsed_args.config_folder)): rc_path = [ '@%s/gcalclirc' % parsed_args.config_folder, ] if not parsed_args.includeRc: tmp_argv = rc_path + argv else: tmp_argv = rc_path + tmp_argv (parsed_args, unparsed) = parser.parse_known_args(tmp_argv) printer = Printer(conky=parsed_args.conky, use_color=parsed_args.color, art_style=parsed_args.lineart) if unparsed: try: parsed_args = handle_unparsed(unparsed, parsed_args) except Exception as e: sys.stderr.write(str(e)) parser.print_usage() sys.exit(1) if parsed_args.locale: try: utils.set_locale(parsed_args.locale) except ValueError as exc: printer.err_msg(str(exc)) if len(parsed_args.calendar) == 0: parsed_args.calendar = parsed_args.defaultCalendar cal_names = parse_cal_names(parsed_args.calendar) gcal = GoogleCalendarInterface(cal_names=cal_names, printer=printer, **vars(parsed_args)) try: if parsed_args.command == 'list': gcal.ListAllCalendars() elif parsed_args.command == 'agenda': gcal.AgendaQuery(start=parsed_args.start, end=parsed_args.end) elif parsed_args.command == 'updates': gcal.UpdatesQuery(last_updated_datetime=parsed_args.since, start=parsed_args.start, end=parsed_args.end) elif parsed_args.command == 'conflicts': gcal.ConflictsQuery(search_text=parsed_args.text, start=parsed_args.start, end=parsed_args.end) elif parsed_args.command == 'calw': gcal.CalQuery(parsed_args.command, count=parsed_args.weeks, start_text=parsed_args.start) elif parsed_args.command == 'calm': gcal.CalQuery(parsed_args.command, start_text=parsed_args.start) elif parsed_args.command == 'quick': if not parsed_args.text: printer.err_msg('Error: invalid event text\n') sys.exit(1) # allow unicode strings for input gcal.QuickAddEvent(_u(parsed_args.text), reminders=parsed_args.reminders) elif parsed_args.command == 'add': if parsed_args.prompt: run_add_prompt(parsed_args, printer) # calculate "when" time: try: estart, eend = utils.get_times_from_duration( parsed_args.when, parsed_args.duration, parsed_args.allday) except ValueError as exc: printer.err_msg(str(exc)) # Since we actually need a valid start and end time in order to # add the event, we cannot proceed. raise gcal.AddEvent(parsed_args.title, parsed_args.where, estart, eend, parsed_args.description, parsed_args.who, parsed_args.reminders, parsed_args.event_color) elif parsed_args.command == 'search': gcal.TextQuery(parsed_args.text[0], start=parsed_args.start, end=parsed_args.end) elif parsed_args.command == 'delete': gcal.ModifyEvents(gcal._delete_event, parsed_args.text[0], start=parsed_args.start, end=parsed_args.end, expert=parsed_args.iamaexpert) elif parsed_args.command == 'edit': gcal.ModifyEvents(gcal._edit_event, parsed_args.text[0], start=parsed_args.start, end=parsed_args.end) elif parsed_args.command == 'remind': gcal.Remind(parsed_args.minutes, parsed_args.cmd, use_reminders=parsed_args.use_reminders) elif parsed_args.command == 'import': gcal.ImportICS(parsed_args.verbose, parsed_args.dump, parsed_args.reminders, parsed_args.file) except GcalcliError as exc: printer.err_msg(str(exc)) sys.exit(1)
def test_get_argparser(): """Just asserts no errors have been introduced""" argparser = argparsers.get_argument_parser() assert argparser
def test_get_argparser(): """Just asserts no errors have been introduced""" argparser = argparsers.get_argument_parser() assert argparser
def main(): parser = get_argument_parser() try: argv = sys.argv[1:] gcalclirc = os.path.expanduser('~/.gcalclirc') if os.path.exists(gcalclirc): # We want .gcalclirc to be sourced before any other --flagfile # params since we may be told to use a specific config folder, we # need to store generated argv in temp variable tmp_argv = ['@%s' % gcalclirc, ] + argv else: tmp_argv = argv (parsed_args, unparsed) = parser.parse_known_args(tmp_argv) except Exception as e: sys.stderr.write(str(e)) parser.print_usage() sys.exit(1) if parsed_args.config_folder: if not os.path.exists(os.path.expanduser(parsed_args.config_folder)): os.makedirs(os.path.expanduser(parsed_args.config_folder)) if os.path.exists(os.path.expanduser('%s/gcalclirc' % parsed_args.config_folder)): rc_path = ['@%s/gcalclirc' % parsed_args.config_folder, ] if not parsed_args.includeRc: tmp_argv = rc_path + argv else: tmp_argv = rc_path + tmp_argv (parsed_args, unparsed) = parser.parse_known_args(tmp_argv) printer = Printer( conky=parsed_args.conky, use_color=parsed_args.color, art_style=parsed_args.lineart ) if unparsed: try: parsed_args = handle_unparsed(unparsed, parsed_args) except Exception as e: sys.stderr.write(str(e)) parser.print_usage() sys.exit(1) if parsed_args.locale: try: utils.set_locale(parsed_args.locale) except ValueError as exc: printer.err_msg(str(exc)) if len(parsed_args.calendar) == 0: parsed_args.calendar = parsed_args.defaultCalendar cal_names = parse_cal_names(parsed_args.calendar) gcal = GoogleCalendarInterface( cal_names=cal_names, printer=printer, **vars(parsed_args) ) try: if parsed_args.command == 'list': gcal.ListAllCalendars() elif parsed_args.command == 'agenda': gcal.AgendaQuery(start=parsed_args.start, end=parsed_args.end) elif parsed_args.command == 'calw': gcal.CalQuery( parsed_args.command, count=parsed_args.weeks, start_text=parsed_args.start ) elif parsed_args.command == 'calm': gcal.CalQuery(parsed_args.command, start_text=parsed_args.start) elif parsed_args.command == 'quick': if not parsed_args.text: printer.err_msg('Error: invalid event text\n') sys.exit(1) # allow unicode strings for input gcal.QuickAddEvent( _u(parsed_args.text), reminders=parsed_args.reminders ) elif parsed_args.command == 'add': if parsed_args.prompt: run_add_prompt(parsed_args, printer) # calculate "when" time: try: estart, eend = utils.get_times_from_duration( parsed_args.when, parsed_args.duration, parsed_args.allday ) except ValueError as exc: printer.err_msg(str(exc)) # Since we actually need a valid start and end time in order to # add the event, we cannot proceed. raise gcal.AddEvent(parsed_args.title, parsed_args.where, estart, eend, parsed_args.description, parsed_args.who, parsed_args.reminders, parsed_args.event_color) elif parsed_args.command == 'search': gcal.TextQuery( parsed_args.text[0], start=parsed_args.start, end=parsed_args.end ) elif parsed_args.command == 'delete': gcal.ModifyEvents( gcal._delete_event, parsed_args.text[0], start=parsed_args.start, end=parsed_args.end, expert=parsed_args.iamaexpert ) elif parsed_args.command == 'edit': gcal.ModifyEvents( gcal._edit_event, parsed_args.text[0], start=parsed_args.start, end=parsed_args.end ) elif parsed_args.command == 'remind': gcal.Remind( parsed_args.minutes, parsed_args.cmd, use_reminders=parsed_args.use_reminders ) elif parsed_args.command == 'import': gcal.ImportICS( parsed_args.verbose, parsed_args.dump, parsed_args.reminders, parsed_args.file ) except GcalcliError as exc: printer.err_msg(str(exc)) sys.exit(1)