def _are_provided_values_valid(self, values): """ Try to validate the provided values. Check if all the values are included in valid fields. If any of the values is not provided in the valid fields and we can connect candlepin server, then print some warning. :param values: provided values on CLI :return: list of invalid values """ # First check if the the value is in the valid_fields. Comparison is case insensitive. invalid_values = [] valid_fields = self._get_valid_fields() if self.attr in valid_fields: for value in values: if all([ x.casefold() != value.casefold() for x in valid_fields[self.attr] ]): invalid_values.append(value) invalid_values_len = len(invalid_values) # When there are values not in the valid fields, then try to print some warning, # when the system is registered or username & password was provided as CLI option. # When the system is not registered and no username & password was provided, then # these values will be set silently. if invalid_values_len > 0: if self.is_registered() or \ (self.options.username and self.options.password) or \ self.options.token: if self.attr in valid_fields: if len(valid_fields[self.attr]) > 0: # TRANSLATORS: this is used to quote a string quoted_values = [ _("\"{value}\"").format(value=value) for value in invalid_values ] printable_values = friendly_join(quoted_values) print( ungettext( 'Warning: Provided value {vals} is not included in the list of valid values', 'Warning: Provided values {vals} are not included in the list of valid values', invalid_values_len).format( vals=printable_values)) self._print_valid_values(valid_fields) else: print( _('Warning: This org does not have any subscriptions with an available "{attr}" is empty.' ).format(attr=self.attr)) else: print( _('Warning: This org does not have any subscriptions with an available "{attr}"' ).format(attr=self.attr)) return invalid_values
def test_join(self): self.assertEquals("One", friendly_join(["One"])) self.assertEquals("One and Two", friendly_join(["One", "Two"])) self.assertEquals("One, Two, and Three", friendly_join(["One", "Two", "Three"])) self.assertEquals("Three, Two, and One", friendly_join(set(["One", "Two", "Three"]))) self.assertEquals("", friendly_join([])) self.assertEquals("", friendly_join(None))
def update(self): entries = [] range_calculator = inj.require(inj.PRODUCT_DATE_RANGE_CALCULATOR, self.backend.cp_provider.get_consumer_auth_cp()) for product_cert in self.product_dir.list(): for product in product_cert.products: product_id = product.id status = self.backend.cs.get_status(product_id) entry = {} entry['product'] = product.name entry['version'] = product.version entry['product_id'] = product_id entry['arch'] = ",".join(product.architectures) # Common properties entry['align'] = 0.5 # TODO: Pull this date logic out into a separate lib! # This is also used in mysubstab... if status != NOT_SUBSCRIBED: compliant_range = range_calculator.calculate(product.id) start = '' end = '' if compliant_range: start = compliant_range.begin() end = compliant_range.end() contract_ids, sub_names = self._calc_subs_providing( product_id, compliant_range) contract = friendly_join(contract_ids) num_of_contracts = len(contract_ids) entry['subscription'] = list(sub_names) entry['start_date'] = start entry['expiration_date'] = end if status == FUTURE_SUBSCRIBED: entry['image'] = self._render_icon('red') entry['status'] = _('Future Subscription') entry['validity_note'] = _("Future Subscribed") elif status == EXPIRED: entry['image'] = self._render_icon('red') entry['status'] = _('Expired') sub_numbers = set([]) for ent_cert in self.entitlement_dir.list_for_product(product_id): order = ent_cert.order # FIXME: getSubscription() seems to always be None...? if order.subscription: sub_numbers.add(order.subscription) subs_str = ', '.join(sub_numbers) entry['validity_note'] = \ _('Subscription %s is expired') % subs_str elif status == PARTIALLY_SUBSCRIBED: entry['image'] = self._render_icon('yellow') entry['status'] = _('Partially Subscribed') entry['validity_note'] = _("Partially Subscribed") elif status == UNKNOWN: entry['image'] = self._render_icon('unknown') entry['status'] = _('Unknown') if not self.backend.cs.is_registered(): entry['validity_note'] = _("System is not registered.") else: # System must be registered but unable to reach server: entry['validity_note'] = _("Entitlement server is unreachable.") else: entry['image'] = self._render_icon('green') entry['status'] = _('Subscribed') entry['validity_note'] = \ gettext.ngettext("Covered by contract %s through %s", 'Covered by contracts %s through %s', num_of_contracts) % \ (contract, managerlib.format_date(entry['expiration_date'])) else: entry['image'] = self._render_icon('red') entry['status'] = _('Not Subscribed') entry['validity_note'] = _("Not Subscribed") entries.append(entry) self._entries = entries
def test_join(self): self.assertEqual("One", friendly_join(["One"])) self.assertEqual("One and Two", friendly_join(["One", "Two"])) self.assertEqual("One, Two, and Three", friendly_join(["One", "Two", "Three"])) self.assertEqual("", friendly_join([])) self.assertEqual("", friendly_join(None)) self.assertEqual("", friendly_join(set())) self.assertEqual("One", friendly_join([None, "One"])) self.assertEqual("One", friendly_join(["One", None])) self.assertEqual("", friendly_join([None, None, None])) # We allow any iterable, so test a set created from a list with dupes words = set(["Two", "One", "Two", "Two"]) res = friendly_join(words) self.assertTrue(res in ["One and Two", "Two and One"]) self.assertEqual("1, 2, 3, 4, 5, 6, and fish", friendly_join([1, 2, u"3", 4, "5", 6, "fish"]))
def test_join(self): self.assertEquals("One", friendly_join(["One"])) self.assertEquals("One and Two", friendly_join(["One", "Two"])) self.assertEquals("One, Two, and Three", friendly_join(["One", "Two", "Three"])) self.assertEquals("Three, Two, and One", friendly_join(set(["One", "Two", "Three"]))) self.assertEquals("", friendly_join([])) self.assertEquals("", friendly_join(None)) self.assertEquals("", friendly_join(set())) self.assertEquals("One", friendly_join([None, "One"])) self.assertEquals("One", friendly_join(["One", None])) self.assertEquals("", friendly_join([None, None, None])) # We allow any iterable, so test a set created from a list with dupes words = set(["Two", "One", "Two", "Two"]) res = friendly_join(words) self.assertTrue(res in ["One and Two", "Two and One"]) self.assertEquals("1, 2, 3, 4, 5, 6, and fish", friendly_join([1, 2, u"3", 4, "5", 6, "fish"]))
def update(self): entries = [] range_calculator = inj.require( inj.PRODUCT_DATE_RANGE_CALCULATOR, self.backend.cp_provider.get_consumer_auth_cp()) installed_products = products.InstalledProducts( self.backend.cp_provider.get_consumer_auth_cp()).list() for product in installed_products: entry = {} entry['product'] = product[0] entry['product_id'] = product_id = product[1] entry['version'] = product[2] entry['arch'] = product[ 3] # TODO: need to test, when more more architectures is supported status = product[4] # NOTE: following code cannot be used, because start_date and expiration_date # are stored in textual form in product and GUI requires datetime format. # entry['start_date'] = product[6] # entry['expiration_date'] = product[7] # Common properties entry['align'] = 0.5 # TODO: Pull this date logic out into a separate lib! # This is also used in mysubstab... if status != NOT_SUBSCRIBED: compliant_range = range_calculator.calculate(product_id) start = '' end = '' if compliant_range: start = compliant_range.begin() end = compliant_range.end() entry['start_date'] = start entry['expiration_date'] = end contract_ids, sub_names = self._calc_subs_providing( product_id, compliant_range) contract = friendly_join(contract_ids) num_of_contracts = len(contract_ids) entry['subscription'] = list(sub_names) if status == FUTURE_SUBSCRIBED: entry['image'] = self._render_icon('red') entry['status'] = _('Future Subscription') entry['validity_note'] = _("Future Subscribed") elif status == EXPIRED: entry['image'] = self._render_icon('red') entry['status'] = _('Expired') sub_numbers = set([]) for ent_cert in self.entitlement_dir.list_for_product( product_id): order = ent_cert.order # FIXME: getSubscription() seems to always be None...? if order.subscription: sub_numbers.add(order.subscription) subs_str = ', '.join(sub_numbers) entry['validity_note'] = \ _('Subscription %s is expired') % subs_str elif status == PARTIALLY_SUBSCRIBED: entry['image'] = self._render_icon('yellow') entry['status'] = _('Partially Subscribed') entry['validity_note'] = _("Partially Subscribed") elif status == UNKNOWN: entry['image'] = self._render_icon('unknown') entry['status'] = _('Unknown') if not self.backend.cs.is_registered(): entry['validity_note'] = _("System is not registered.") else: # System must be registered but unable to reach server: entry['validity_note'] = _( "Entitlement server is unreachable.") else: entry['image'] = self._render_icon('green') entry['status'] = _('Subscribed') entry['validity_note'] = \ ungettext("Covered by contract %s through %s", 'Covered by contracts %s through %s', num_of_contracts) % \ (contract, managerlib.format_date(entry['expiration_date'])) else: entry['image'] = self._render_icon('red') entry['status'] = _('Not Subscribed') entry['validity_note'] = _("Not Subscribed") entries.append(entry) self._entries = entries
def update_products(self): self.store.clear() range_calculator = inj.require( inj.PRODUCT_DATE_RANGE_CALCULATOR, self.backend.cp_provider.get_consumer_auth_cp()) for product_cert in self.product_dir.list(): for product in product_cert.products: product_id = product.id status = self.backend.cs.get_status(product_id) entry = {} entry['product'] = product.name entry['version'] = product.version entry['product_id'] = product_id entry['arch'] = ",".join(product.architectures) # Common properties entry['align'] = 0.5 # TODO: Pull this date logic out into a separate lib! # This is also used in mysubstab... if status != NOT_SUBSCRIBED: compliant_range = range_calculator.calculate(product.id) start = '' end = '' if compliant_range: start = compliant_range.begin() end = compliant_range.end() contract_ids, sub_names = self._calc_subs_providing( product_id, compliant_range) contract = friendly_join(contract_ids) num_of_contracts = len(contract_ids) entry['subscription'] = list(sub_names) entry['start_date'] = start entry['expiration_date'] = end if status == FUTURE_SUBSCRIBED: entry['image'] = self._render_icon('red') entry['status'] = _('Future Subscription') entry['validity_note'] = _("Future Subscribed") elif status == EXPIRED: entry['image'] = self._render_icon('red') entry['status'] = _('Expired') sub_numbers = set([]) for ent_cert in self.entitlement_dir.list_for_product( product_id): order = ent_cert.order # FIXME: getSubscription() seems to always be None...? if order.subscription: sub_numbers.add(order.subscription) subs_str = ', '.join(sub_numbers) entry['validity_note'] = \ _('Subscription %s is expired') % subs_str elif status == PARTIALLY_SUBSCRIBED: entry['image'] = self._render_icon('yellow') entry['status'] = _('Partially Subscribed') entry['validity_note'] = _("Partially Subscribed") elif status == UNKNOWN: entry['image'] = self._render_icon('unknown') entry['status'] = _('Unknown') if not self.backend.cs.is_registered(): entry['validity_note'] = _( "System is not registered.") else: # System must be registered but unable to reach server: entry['validity_note'] = _( "Entitlement server is unreachable.") else: entry['image'] = self._render_icon('green') entry['status'] = _('Subscribed') entry['validity_note'] = \ gettext.ngettext("Covered by contract %s through %s", 'Covered by contracts %s through %s', num_of_contracts) % \ (contract, managerlib.format_date(entry['expiration_date'])) else: entry['image'] = self._render_icon('red') entry['status'] = _('Not Subscribed') entry['validity_note'] = _("Not Subscribed") # FIXME # TODO: fix mapped stores self.store.add_map(entry) # 811340: Select the first product in My Installed Products # table by default. selection = self.top_view.get_selection() selection.select_path(0)