def test_project_status(cli, config, data_dir): config.set_dict({ 'test_aliases': { 'alias_not_started': '0/0', 'alias_active': '1/0', 'alias_finished': '2/0', 'alias_cancelled': '3/0', } }) projects_db = ProjectsDb(str(data_dir)) project_not_started = Project(0, 'not started project', Project.STATUS_NOT_STARTED) project_not_started.backend = 'test' project_not_started.activities.append(Activity(0, 'activity', 0)) project_active = Project(1, 'active project', Project.STATUS_ACTIVE) project_active.backend = 'test' project_active.activities.append(Activity(0, 'activity', 0)) project_finished = Project(2, 'finished project', Project.STATUS_FINISHED) project_finished.backend = 'test' project_finished.activities.append(Activity(0, 'activity', 0)) project_cancelled = Project(3, 'cancelled project', Project.STATUS_CANCELLED) project_cancelled.backend = 'test' project_cancelled.activities.append(Activity(0, 'activity', 0)) projects_db.update([ project_not_started, project_active, project_finished, project_cancelled ]) cli('clean-aliases', ['--yes']) settings = Settings(config.path) assert list(settings.get_aliases().keys()) == ['alias_active']
def test_project_status(self): projects_db = ProjectsDb(self.taxi_dir) project_not_started = Project(0, 'not started project', Project.STATUS_NOT_STARTED) project_not_started.backend = 'test' project_not_started.activities.append(Activity(0, 'activity', 0)) project_active = Project(1, 'active project', Project.STATUS_ACTIVE) project_active.backend = 'test' project_active.activities.append(Activity(0, 'activity', 0)) project_finished = Project(2, 'finished project', Project.STATUS_FINISHED) project_finished.backend = 'test' project_finished.activities.append(Activity(0, 'activity', 0)) project_cancelled = Project(3, 'cancelled project', Project.STATUS_CANCELLED) project_cancelled.backend = 'test' project_cancelled.activities.append(Activity(0, 'activity', 0)) projects_db.update([ project_not_started, project_active, project_finished, project_cancelled ]) self.run_command('clean-aliases', args=['--yes']) settings = Settings(self.config_file) self.assertEqual(list(settings.get_aliases().keys()), ['alias_active'])
def test_migration_to_41_copies_local_aliases(self): stdout = self.run_command('alias', ['list', '_foo']) self.assertIn('[local] _foo -> not mapped', stdout) settings = Settings(self.config_file) self.assertTrue(settings.config.has_section('local_aliases')) self.assertTrue(settings.config.has_option('local_aliases', '_foo')) self.assertIsNone(settings.config.get('local_aliases', '_foo')) self.assertTrue(settings.config.has_option('local_aliases', '_bar')) self.assertIsNone(settings.config.get('local_aliases', '_bar'))
def test_project_status(self): config = self.default_config.copy() options = self.default_options.copy() config['wrmap'] = { 'alias_not_started': '0/0', 'alias_active': '1/0', 'alias_finished': '2/0', 'alias_cancelled': '3/0', } options['force_yes'] = True projects_db = ProjectsDb(options['projects_db']) project_not_started = Project(0, 'not started project', Project.STATUS_NOT_STARTED) project_not_started.activities.append(Activity(0, 'activity', 0)) project_active = Project(1, 'active project', Project.STATUS_ACTIVE) project_active.activities.append(Activity(0, 'activity', 0)) project_finished = Project(2, 'finished project', Project.STATUS_FINISHED) project_finished.activities.append(Activity(0, 'activity', 0)) project_cancelled = Project(3, 'cancelled project', Project.STATUS_CANCELLED) project_cancelled.activities.append(Activity(0, 'activity', 0)) projects_db.update([ project_not_started, project_active, project_finished, project_cancelled ]) stdout = self.run_command('clean-aliases', options=options, config_options=config) settings = Settings(self.config_file) self.assertEqual(settings.get_aliases().keys(), ['alias_active'])
def run_command(self, command, options={}, args=[]): actions = { 'add': commands.AddCommand, 'alias': commands.AliasCommand, 'autofill': commands.AutofillCommand, 'clean-aliases': commands.CleanAliasesCommand, 'ci': commands.CommitCommand, 'commit': commands.CommitCommand, 'edit': commands.EditCommand, 'help': commands.HelpCommand, 'kitty': commands.KittyCommand, 'ohai': commands.KittyCommand, 'search': commands.SearchCommand, 'show': commands.ShowCommand, 'start': commands.StartCommand, 'stat': commands.StatusCommand, 'status': commands.StatusCommand, 'stop': commands.StopCommand, 'up': commands.UpdateCommand, 'update': commands.UpdateCommand, } options = options.copy() args = list(args) options['config'] = os.path.expanduser(options['config']) self.create_config_file(options['config']) settings = Settings(options['config']) if not os.path.exists(settings.TAXI_PATH): os.mkdir(settings.TAXI_PATH) if options.get('file', None) is None: options['forced_file'] = False try: options['file'] = settings.get('file') except ConfigParser.NoOptionError: raise Exception("Error: no file to parse. You must either " "define one in your config file with the " "'file' setting, or use the -f option") else: options['forced_file'] = True options['unparsed_file'] = os.path.expanduser(options['file']) options['file'] = expand_filename(options['file']) if options.get('date', None) is not None: date_format = '%d.%m.%Y' try: if '-' in options['date']: split_date = options['date'].split('-', 1) options['date'] = ( datetime.datetime.strptime(split_date[0], date_format).date(), datetime.datetime.strptime(split_date[1], date_format).date()) else: options['date'] = datetime.datetime.strptime( options['date'], date_format ).date() except ValueError: raise UsageError("Invalid date format (must be dd.mm.yyyy)") else: options['date'] = None if 'projects_db' not in options: options['projects_db'] = os.path.join( settings.TAXI_PATH, 'projects.db' ) projects_db = ProjectsDb(options['projects_db']) view = TtyUi( options.get('stdout', sys.stdout), settings.get('use_colors').lower() in ['1', 'yes', 'true'] ) ac = AppContainer() ac.settings = settings ac.options = options ac.projects_db = projects_db ac.arguments = args ac.view = view action = None try: if command not in actions: raise UsageError("Unknown command `%s`" % command) if command == 'help': ac.commands_mapping = actions action = actions[command](ac) action.validate() action.setup() except UsageError as ue: if (action is not None and not isinstance(action, commands.HelpCommand)): view.msg(inspect.getdoc(action)) else: raise ue else: try: action.run() except TaxiException as e: view.err(e)
def run(self): usage = """Usage: %prog [options] command Available commands: add \t\tsearches, prompts for project, activity and alias, adds to .tksrc alias \t\tshows your mappings and allows you to create new ones autofill \t\tautofills the current timesheet with all the days of the month clean-aliases\t\tremoves aliases that point to inactive projects commit \t\tcommits the changes to the server edit \t\topens your zebra file in your favourite editor help \t\tprints this help or the one of the given command search \t\tsearches for a project show \t\tshows the activities and other details of a project start \t\tstarts the counter on a given activity status \t\tshows the status of your entries file stop \t\tstops the counter and record the elapsed time update \t\tupdates your project database with the one on the server""" opt = OptionParser(usage=usage, version='%prog ' + __version__) opt.add_option('-c', '--config', dest='config', help='use CONFIG file ' 'instead of ~/.tksrc', default='~/.tksrc') opt.add_option('-v', '--verbose', dest='verbose', action='store_true', help='make taxi verbose', default=False) opt.add_option('-f', '--file', dest='file', help='parse FILE instead of the '\ 'one defined in your CONFIG file') opt.add_option('-d', '--date', dest='date', help='only process entries for date '\ 'DATE (eg. 31.01.2011, 31.01.2011-05.02.2011)') opt.add_option('--ignore-date-error', dest='ignore_date_error', help='suppresses the error if'\ ' you\'re trying to commit a date that\'s on a week-end or on another'\ ' day than the current day or the day before', action='store_true', default=False) (options, args) = opt.parse_args() args = [term_unicode(arg) for arg in args] actions = { 'add': commands.AddCommand, 'alias': commands.AliasCommand, 'autofill': commands.AutofillCommand, 'clean-aliases': commands.CleanAliasesCommand, 'ci': commands.CommitCommand, 'commit': commands.CommitCommand, 'edit': commands.EditCommand, 'help': commands.HelpCommand, 'kitty': commands.KittyCommand, 'ohai': commands.KittyCommand, 'search': commands.SearchCommand, 'show': commands.ShowCommand, 'start': commands.StartCommand, 'stat': commands.StatusCommand, 'status': commands.StatusCommand, 'stop': commands.StopCommand, 'up': commands.UpdateCommand, 'update': commands.UpdateCommand, } settings = Settings(options.config) if not os.path.exists(settings.TAXI_PATH): os.mkdir(settings.TAXI_PATH) if options.file is None: try: options.file = settings.get('file') except ConfigParser.NoOptionError: raise Exception("Error: no file to parse. You must either " "define one in your config file with the " "'file' setting, or use the -f option") options.unparsed_file = os.path.expanduser(options.file) options.file = datetime.date.today().strftime(os.path.expanduser(options.file)) if options.date is not None: date_format = '%d.%m.%Y' try: if '-' in options.date: split_date = options.date.split('-', 1) options.date = ( datetime.datetime.strptime(split_date[0], date_format).date(), datetime.datetime.strptime(split_date[1], date_format).date()) else: options.date = datetime.datetime.strptime(options.date, date_format).date() except ValueError: opt.print_help() exit() projects_db = ProjectsDb(os.path.join(settings.TAXI_PATH, 'projects.db')) view = TtyUi() ac = AppContainer() ac.settings = settings ac.options = options ac.projects_db = projects_db ac.arguments = args[1:] ac.view = view action = None try: if len(args) == 0 or args[0] not in actions: raise UsageError() if args[0] == 'help': ac.commands_mapping = actions action = actions[args[0]](ac) action.validate() action.setup() except UsageError: if (action is not None and not isinstance(action, commands.HelpCommand)): view.msg(inspect.getdoc(action)) else: view.msg(opt.format_help()) else: try: action.run() except UndefinedAliasError as e: close = settings.get_close_matches(e.message) view.suggest_aliases(e.message, close)