def duplicate_deps(self, manifest, engine, pkglint_id="005"): """Checks for repeated dependencies, including package version substrings.""" seen_deps = {} duplicates = [] dup_msg = _( "duplicate depend actions in {pkg} {actions}") duplicates = [] for action in manifest.gen_actions_by_type("depend"): # this only checks require, require-any and group-any # actions if action.attrs["type"] not in ["require", "require-any", "group-any"]: continue if "fmri" not in action.attrs: lint_id = "{0}{1}.1".format(self.name, pkglint_id) if not engine.linted(action=action, manifest=manifest, lint_id=lint_id): engine.critical( _("no fmri attribute in depend " "action in {0}").format( manifest.fmri), msgid=lint_id) continue lint_id = "{0}{1}.2".format(self.name, pkglint_id) if engine.linted(action=action, manifest=manifest, lint_id=lint_id): continue deps = action.attrs["fmri"] if isinstance(deps, six.string_types): deps = [deps] for dep in deps: shortname = fmri.extract_pkg_name(dep) if shortname not in seen_deps: seen_deps[shortname] = [action] else: seen_deps[shortname].append(action) compared = set() for key in seen_deps: actions = seen_deps[key] if len(actions) > 1: conflict_vars, conflict_actions = \ self.conflicting_dep_actions(actions, manifest.get_all_variants(), compared) if conflict_actions: duplicates.append(key) if duplicates: dlist = sorted((str(d) for d in duplicates)) engine.error(dup_msg.format( pkg=manifest.fmri, actions=" ".join(dlist)), msgid="{0}{1}.2".format(self.name, pkglint_id))
def duplicate_deps(self, manifest, engine, pkglint_id="005"): """Checks for repeated dependencies, including package version substrings.""" seen_deps = {} duplicates = [] dup_msg = _( "duplicate depend actions in %(pkg)s %(actions)s") duplicates = [] for action in manifest.gen_actions_by_type("depend"): # this only checks require and require-any actions if "require" not in action.attrs["type"]: continue if "fmri" not in action.attrs: lint_id = "%s%s.1" % (self.name, pkglint_id) if not engine.linted(action=action, manifest=manifest, lint_id=lint_id): engine.critical( _("no fmri attribute in depend " "action in %s") % manifest.fmri, msgid=lint_id) continue lint_id = "%s%s.2" % (self.name, pkglint_id) if engine.linted(action=action, manifest=manifest, lint_id=lint_id): continue deps = action.attrs["fmri"] if isinstance(deps, basestring): deps = [deps] for dep in deps: shortname = fmri.extract_pkg_name(dep) if shortname not in seen_deps: seen_deps[shortname] = [action] else: seen_deps[shortname].append(action) for key in seen_deps: actions = seen_deps[key] if len(actions) > 1: conflict_vars, conflict_actions = \ self.conflicting_variants(actions, manifest.get_all_variants()) if conflict_actions: duplicates.append(key) if duplicates: dlist = sorted((str(d) for d in duplicates)) engine.error(dup_msg % {"pkg": manifest.fmri, "actions": " ".join(dlist)}, msgid="%s%s.2" % (self.name, pkglint_id))
def __output_pkg_install_tasks(self, infobuffer, textiter, num_tasks): if num_tasks == 0: return msg = ngettext( "\n Install Package\n", "\n Install Packages\n", num_tasks) infobuffer.insert_with_tags_by_name(textiter, msg, "bold") for entry in self.pkg_install_tasks: pub_info = entry[0] packages = entry[1] if len(packages) > 0: if self.disabled_pubs and \ pub_info.prefix in self.disabled_pubs: infobuffer.insert_with_tags_by_name(textiter, _("\t%s (disabled)\n") % pub_info.prefix, "bold", "disabled") else: infobuffer.insert_with_tags_by_name(textiter, "\t%s\n" % pub_info.prefix, "bold") for pkg in packages: infobuffer.insert(textiter, "\t\t%s\n" % fmri.extract_pkg_name(pkg))
def __output_pkg_install_tasks(self, infobuffer, textiter, num_tasks): if num_tasks == 0: return msg = ngettext("\n Install Package\n", "\n Install Packages\n", num_tasks) infobuffer.insert_with_tags_by_name(textiter, msg, "bold") for entry in self.pkg_install_tasks: pub_info = entry[0] packages = entry[1] if len(packages) > 0: if self.disabled_pubs and \ pub_info.prefix in self.disabled_pubs: infobuffer.insert_with_tags_by_name( textiter, _("\t%s (disabled)\n") % pub_info.prefix, "bold", "disabled") else: infobuffer.insert_with_tags_by_name( textiter, "\t%s\n" % pub_info.prefix, "bold") for pkg in packages: infobuffer.insert(textiter, "\t\t%s\n" % fmri.extract_pkg_name(pkg))
def activate(self, selected_pkgs): self.selected_pkgs = selected_pkgs if self.selected_pkgs == None or len(self.selected_pkgs) == 0: return infobuffer = self.w_confirm_textview.get_buffer() infobuffer.set_text("") textiter = infobuffer.get_end_iter() for pub_name, pkgs in self.selected_pkgs.items(): name = self.parent.get_publisher_name_from_prefix(pub_name) if name == pub_name: infobuffer.insert_with_tags_by_name(textiter, "%s\n" % pub_name, "bold") else: infobuffer.insert_with_tags_by_name(textiter, "%s" % name, "bold") infobuffer.insert(textiter, " (%s)\n" % pub_name) for pkg in pkgs.keys(): infobuffer.insert(textiter, "\t%s\n" % fmri.extract_pkg_name(pkg)) self.w_confirmok_button.grab_focus() self.w_exportconfirm_dialog.show()
def set_dependencies_text(textview, info, dep_info, installed_dep_info, installed_icon, not_installed_icon): names = [] states = None installed_states = [] if dep_info != None and len(dep_info.get(0)) >= 0: states = dep_info[0] if installed_dep_info != None and len(installed_dep_info.get(0)) >= 0: installed_states = installed_dep_info[0] version_fmt = get_version_fmt_string() for x in info.dependencies: if states != None and len(states) > 0: name = fmri.extract_pkg_name(x) found = False for state in states: if name == state.pkg_stem: version = version_fmt % \ {"version": state.version, "build": state.build_release, "branch": state.branch} found = True break if not found: version = version_fmt % \ {"version": '0', "build": '0', "branch": '0'} found = False for state in installed_states: if name == state.fmri.get_name(): installed_version = version_fmt % \ {"version": state.version, "build": state.build_release, "branch": state.branch} found = True break if not found: installed_version = (_("(not installed)")) names.append((name, version, installed_version, found)) else: build_rel = "0" pkg_fmri = fmri.PkgFmri(x, build_release=build_rel) branch = pkg_fmri.version.branch version_stripped = pkg_fmri.get_version().split("-%s" % branch)[0] version = version_fmt % \ {"version": version_stripped, "build": build_rel, "branch": branch} names.append( (pkg_fmri.pkg_name, version, _("(not installed)"), False)) depbuffer = textview.get_buffer() depbuffer.set_text("") if states == None: if len(names) == 0: itr = depbuffer.get_iter_at_line(0) depbuffer.insert_with_tags_by_name(itr, _("None"), "bold") else: for i in range(0, len(names)): itr = depbuffer.get_iter_at_line(i) dep_str = "%s\n" % (names[i]) depbuffer.insert(itr, dep_str) return style = textview.get_style() font_size_in_pango_unit = style.font_desc.get_size() font_size_in_pixel = font_size_in_pango_unit / pango.SCALE tab_array = pango.TabArray(3, True) header = [_("Name"), _("Dependency"), _("Installed Version")] max_len = [0, 0] for i in range(2): depbuffer.set_text("") itr = depbuffer.get_iter_at_line(0) depbuffer.insert_with_tags_by_name(itr, header[i], "bold") max_len[i] = get_textview_width(textview) depbuffer.set_text("") for one_names in names: itr = depbuffer.get_iter_at_line(0) depbuffer.insert(itr, one_names[i]) test_len = get_textview_width(textview) if test_len > max_len[i]: max_len[i] = test_len depbuffer.set_text("") tab_array.set_tab(1, pango.TAB_LEFT, max_len[0] + font_size_in_pixel) tab_array.set_tab(2, pango.TAB_LEFT, max_len[0] + max_len[1] + 2 * font_size_in_pixel) textview.set_tabs(tab_array) if len(names) == 0: depbuffer.set_text("") itr = depbuffer.get_iter_at_line(0) depbuffer.insert_with_tags_by_name(itr, _("No dependencies"), "bold") return itr = depbuffer.get_iter_at_line(0) header_text = "%s\t%s\t%s\n" % (header[0], header[1], header[2]) depbuffer.insert_with_tags_by_name(itr, header_text, "bold") resized_installed_icon = None resized_not_installed_icon = None i += 0 for (name, version, installed_version, is_installed) in names: if is_installed: if resized_installed_icon == None: resized_installed_icon = resize_icon(installed_icon, font_size_in_pixel) icon = resized_installed_icon else: if resized_not_installed_icon == None: resized_not_installed_icon = resize_icon( not_installed_icon, font_size_in_pixel) icon = resized_not_installed_icon itr = depbuffer.get_iter_at_line(i + 1) dep_str = "%s\t%s\t" % (name, version) depbuffer.insert(itr, dep_str) end_itr = depbuffer.get_end_iter() depbuffer.insert_pixbuf(end_itr, icon) depbuffer.insert(end_itr, " %s\n" % installed_version) i += 1
def get_fmri_set(action): fmris = set() for dep in action.attrs["fmri"]: fmris.add(fmri.extract_pkg_name(dep)) return fmris
def set_dependencies_text(textview, info, dep_info, installed_dep_info, installed_icon, not_installed_icon): names = [] states = None installed_states = [] if dep_info != None and len(dep_info.get(0)) >= 0: states = dep_info[0] if installed_dep_info != None and len(installed_dep_info.get(0)) >= 0: installed_states = installed_dep_info[0] version_fmt = get_version_fmt_string() for x in info.dependencies: if states != None and len(states) > 0: name = fmri.extract_pkg_name(x) found = False for state in states: if name == state.pkg_stem: version = version_fmt % \ {"version": state.version, "build": state.build_release, "branch": state.branch} found = True break if not found: version = version_fmt % \ {"version": '0', "build": '0', "branch": '0'} found = False for state in installed_states: if name == state.fmri.get_name(): installed_version = version_fmt % \ {"version": state.version, "build": state.build_release, "branch": state.branch} found = True break if not found: installed_version = (_("(not installed)")) names.append((name, version, installed_version, found)) else: build_rel = "0" pkg_fmri = fmri.PkgFmri(x, build_release=build_rel) branch = pkg_fmri.version.branch version_stripped = pkg_fmri.get_version().split("-%s" % branch)[0] version = version_fmt % \ {"version": version_stripped, "build": build_rel, "branch": branch} names.append((pkg_fmri.pkg_name, version, _("(not installed)"), False)) depbuffer = textview.get_buffer() depbuffer.set_text("") if states == None: if len(names) == 0: itr = depbuffer.get_iter_at_line(0) depbuffer.insert_with_tags_by_name(itr, _("None"), "bold") else: for i in range(0, len(names)): itr = depbuffer.get_iter_at_line(i) dep_str = "%s\n" % (names[i]) depbuffer.insert(itr, dep_str) return style = textview.get_style() font_size_in_pango_unit = style.font_desc.get_size() font_size_in_pixel = font_size_in_pango_unit / pango.SCALE tab_array = pango.TabArray(3, True) header = [_("Name"), _("Dependency"), _("Installed Version")] max_len = [0, 0] for i in range(2): depbuffer.set_text("") itr = depbuffer.get_iter_at_line(0) depbuffer.insert_with_tags_by_name(itr, header[i], "bold") max_len[i] = get_textview_width(textview) depbuffer.set_text("") for one_names in names: itr = depbuffer.get_iter_at_line(0) depbuffer.insert(itr, one_names[i]) test_len = get_textview_width(textview) if test_len > max_len[i]: max_len[i] = test_len depbuffer.set_text("") tab_array.set_tab(1, pango.TAB_LEFT, max_len[0] + font_size_in_pixel) tab_array.set_tab(2, pango.TAB_LEFT, max_len[0] + max_len[1] + 2 * font_size_in_pixel) textview.set_tabs(tab_array) if len(names) == 0: depbuffer.set_text("") itr = depbuffer.get_iter_at_line(0) depbuffer.insert_with_tags_by_name(itr, _("No dependencies"), "bold") return itr = depbuffer.get_iter_at_line(0) header_text = "%s\t%s\t%s\n" % (header[0], header[1], header[2]) depbuffer.insert_with_tags_by_name(itr, header_text, "bold") resized_installed_icon = None resized_not_installed_icon = None i += 0 for (name, version, installed_version, is_installed) in names: if is_installed: if resized_installed_icon == None: resized_installed_icon = resize_icon( installed_icon, font_size_in_pixel) icon = resized_installed_icon else: if resized_not_installed_icon == None: resized_not_installed_icon = resize_icon( not_installed_icon, font_size_in_pixel) icon = resized_not_installed_icon itr = depbuffer.get_iter_at_line(i + 1) dep_str = "%s\t%s\t" % (name, version) depbuffer.insert(itr, dep_str) end_itr = depbuffer.get_end_iter() depbuffer.insert_pixbuf(end_itr, icon) depbuffer.insert(end_itr, " %s\n" % installed_version) i += 1