def find_newest(repo_ids, module_name): """ Find the newest version of the requested module :param repo_ids: IDs of repos to search in :type repo_ids: list :param module_name: name of module in form "author/title" :type module_name: str :return: Unit instance, or None if not found :rtype: puppet.forge.unit.Unit """ dbs = get_repo_data(repo_ids) host = get_host_and_protocol()['host'] ret = None try: for repo_id, data in dbs.iteritems(): units = Unit.units_from_json(module_name, data['db'], repo_id, host, data['protocol']) if units: repo_max = max(units) if ret is None or repo_max > ret: ret = repo_max finally: # close database files we don't need to use if ret: del dbs[ret.repo_id] for data in dbs.itervalues(): data['db'].close() return ret
def find_newest(repo_ids, module_name): """ Find the newest version of the requested module :param repo_ids: IDs of repos to search in :type repo_ids: list :param module_name: name of module in form "author/title" :type module_name: str :return: Unit instance, or None if not found :rtype: puppet.forge.unit.Unit """ dbs = get_repo_data(repo_ids) host = get_host_and_protocol()['host'] ret = None try: for repo_id, data in dbs.iteritems(): units = Unit.units_from_json(module_name, data['db'], repo_id, host, data['protocol']) if units: repo_max = max(units) if ret is None or repo_max > ret: ret = repo_max finally: # close database files we don't need to use if ret: del dbs[ret.repo_id] for data in dbs.itervalues(): data['db'].close() return ret
def find_version(repo_ids, module_name, version): """ Find a particular version of the requested module :param repo_ids: IDs of repos to search in :type repo_ids: list :param module_name: name of module in form "author/title" :type module_name: str :param version: version to search for :type version: str :return: Unit instance :rtype: puppet.forge.unit.Unit """ dbs = get_repo_data(repo_ids) host = get_host_and_protocol()['host'] ret = None try: for repo_id, data in dbs.iteritems(): units = Unit.units_from_json(module_name, data['db'], repo_id, host, data['protocol']) for unit in units: if unit.version == version: ret = unit break finally: # close database files we don't need to use if ret: del dbs[ret.repo_id] for data in dbs.itervalues(): data['db'].close() return ret
def find_version(repo_ids, module_name, version): """ Find a particular version of the requested module :param repo_ids: IDs of repos to search in :type repo_ids: list :param module_name: name of module in form "author/title" :type module_name: str :param version: version to search for :type version: str :return: Unit instance :rtype: puppet.forge.unit.Unit """ dbs = get_repo_data(repo_ids) host = get_host_and_protocol()['host'] ret = None try: for repo_id, data in dbs.iteritems(): units = Unit.units_from_json(module_name, data['db'], repo_id, host, data['protocol']) for unit in units: if unit.version == version: ret = unit break finally: # close database files we don't need to use if ret: del dbs[ret.repo_id] for data in dbs.itervalues(): data['db'].close() return ret
def test_valid(self): name = 'me/stuntmodule' db = {name: self.UNIT_JSON} result = Unit.units_from_json(name, db, 'repo1', 'localhost', 'http') self.assertEqual(len(result), 1) self.assertTrue(isinstance(result[0], Unit)) self.assertEqual(result[0].name, name) self.assertEqual(result[0].repo_id, 'repo1') self.assertEqual(result[0].host, 'localhost') self.assertEqual(result[0].protocol, 'http')
def test_valid(self): name = 'me/stuntmodule' db = {name:self.UNIT_JSON} result = Unit.units_from_json(name, db, 'repo1', 'localhost', 'http') self.assertEqual(len(result), 1) self.assertTrue(isinstance(result[0], Unit)) self.assertEqual(result[0].name, name) self.assertEqual(result[0].repo_id, 'repo1') self.assertEqual(result[0].host, 'localhost') self.assertEqual(result[0].protocol, 'http')
def test_not_in_db(self): name = 'me/stuntmodule' db = {} result = Unit.units_from_json(name, db, 'repo1', 'localhost', 'http') self.assertEqual(len(result), 0)
def test_not_in_db(self): name = 'me/stuntmodule' db = {} result = Unit.units_from_json(name, db, 'repo1', 'localhost', 'http') self.assertEqual(len(result), 0)