Esempio n. 1
0
 def run(self):
     conf = config.Config()
     table = [('source', 'cached', 'in-use', 'max')]
     details_table = [('source', 'instance')]
     sources = config.sources(config.default_path())
     if 'local' not in sources:
         sources.add('local')
     if self.ui.arguments['(re)sources']:
         query = sorted(self.ui.arguments['(re)sources'])
         check = set(query).__contains__
     else:
         check = lambda x:True
     sources = [conf.get_source(source_name) for source_name
         in sorted(sources) if check(source_name)]
     def available(source):
         return source.maximum - source.in_use()
     if self.ui.options.query:
         source_map = {
             'cached': methodcaller('cached'),
             'in-ues': methodcaller('in_use'),
             'max': attrgetter('maximum'),
             'available': available
             }
         lookup = source_map[self.ui.options.query]
         result = sum(map(lookup, sources))
         self.ui.output_rest('%d' % result)
         return 0
     for source in sources:
         cached = str(source.cached())
         in_use = str(source.in_use())
         table.append((source.name, cached, in_use, str(source.maximum)))
         if self.ui.options.verbose:
             instances = sorted(source.instances())
             if not instances:
                 continue
             details_table.append((source.name, instances[0]))
             for instance in instances[1:]:
                 details_table.append(('', instance))
     self.ui.output_table(table)
     if self.ui.options.verbose:
         self.ui.output_rest("\n")
         self.ui.output_table(details_table)
     return 0
Esempio n. 2
0
 def test_finds_source_in_home(self):
     root = config.default_path()[0]
     os.makedirs(os.path.join(root, 'sources', 'foo'))
     self.assertEqual(set(['foo']), config.sources([root]))
Esempio n. 3
0
 def test_source_dirs_missing_paths(self):
     config.source_dirs(config.default_path())
Esempio n. 4
0
 def test_search_path(self):
     homedir_config = os.path.join(self.homedir, '.config', 'crcache')
     cwd_config = os.path.join(os.getcwd(), '.crcache')
     expected_path = [homedir_config, cwd_config]
     self.assertEqual(expected_path, config.default_path())