def test_conky_debug_msg(monkeypatch): err = StringIO() monkeypatch.setattr(sys, 'stderr', err) cp = Printer(conky=True) cp.debug_msg(_u('debug')) err.seek(0) assert err.read() == _u('${color yellow}debug${color}')
def test_conky_debug_msg(monkeypatch): err = StringIO() monkeypatch.setattr(sys, 'stderr', err) cp = Printer(conky=True) cp.debug_msg(_u('debug')) err.seek(0) assert err.read() == _u('${color yellow}debug')
def test_err_msg(monkeypatch): err = StringIO() monkeypatch.setattr(sys, 'stderr', err) cp = Printer() cp.err_msg(_u('error')) err.seek(0) assert err.read() == _u('\033[31;1merror\033[0m')
def test_conky_err_msg(monkeypatch): err = StringIO() monkeypatch.setattr(sys, 'stderr', err) cp = Printer(conky=True) cp.err_msg(_u('error')) err.seek(0) assert err.read() == _u('${color red}error${color}')
def test_debug_msg(monkeypatch): err = StringIO() monkeypatch.setattr(sys, 'stderr', err) cp = Printer() cp.debug_msg(_u('debug')) err.seek(0) assert err.read() == _u('\033[0;33mdebug\033[0m')
def test_conky_err_msg(monkeypatch): err = StringIO() monkeypatch.setattr(sys, 'stderr', err) cp = Printer(conky=True) cp.err_msg(_u('error')) err.seek(0) assert err.read() == _u('${color red}error')
def test_all_colors(): """Makes sure the COLOR_NAMES is in sync with the colors in the printer""" cp = Printer() for color_name in COLOR_NAMES: out = StringIO() cp.msg(_u('msg'), color_name, file=out) out.seek(0) assert out.read() == _u(cp.colors[color_name] + 'msg' + '\033[0m')
def test_run_add_prompt(): """Basic test that only ensures the function can be run without error""" printer = Printer() min_keys = [ 'title', 'where', 'when', 'duration', 'description', 'event_color', 'reminders' ] parsed_args = Namespace(**{k: 'test' for k in min_keys}) run_add_prompt(parsed_args, printer)
def test_no_color(): cp = Printer(use_color=False) out = StringIO() cp.msg(_u('msg'), 'red', file=out) out.seek(0) assert out.read() == _u('msg')
def test_conky_red_msg(): cp = Printer(conky=True) out = StringIO() cp.msg(_u('msg'), 'red', file=out) out.seek(0) assert out.read() == _u('${color red}msg')
def test_red_msg(): cp = Printer() out = StringIO() cp.msg(_u('msg'), 'red', file=out) out.seek(0) assert out.read() == _u('\033[0;31mmsg\033[0m')
def test_conky_red_msg(): cp = Printer(conky=True) out = StringIO() cp.msg(_u('msg'), 'red', file=out) out.seek(0) assert out.read() == _u('${color red}msg${color}')
def test_init(): cp = Printer() assert cp
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)
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)
import argparse import functools import gcalcli from gcalcli.printer import valid_color_name, Printer printer = Printer() CAMELS = { "--configFolder": "--config-folder", "--defaultCalendar": "--default-calendar" } def warn_deprecated_opt(option_string): suggestion = 'Please use "{}", instead.\n' suggestion = (suggestion.format(CAMELS[option_string]) if option_string in CAMELS else suggestion.format( option_string.replace('_', '-'))) msg = ('WARNING: {} has been deprecated and will be removed in a future ' 'release.\n' + suggestion) printer.err_msg(msg.format(option_string)) class DeprecatedStore(argparse._StoreAction): def __call__(self, parser, namespace, values,