[yast-devel] Re: [yast-commit] r64329 - /trunk/yast2/library/control/src/ProductProfile.ycp
On Tue, Jun 14, 2011 at 06:43:07AM -0000, jsuchome@svn2.opensuse.org wrote:
Author: jsuchome Date: Tue Jun 14 08:43:07 2011 New Revision: 64329
URL: http://svn.opensuse.org/viewcvs/yast?rev=64329&view=rev Log: module for handling product profiles (fate#310730)
Added: trunk/yast2/library/control/src/ProductProfile.ycp (with props)
Added: trunk/yast2/library/control/src/ProductProfile.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/yast2/library/control/src/ProductProfile.ycp?rev=64329&view=auto ============================================================================== --- trunk/yast2/library/control/src/ProductProfile.ycp (added) +++ trunk/yast2/library/control/src/ProductProfile.ycp Tue Jun 14 08:43:07 2011 @@ -0,0 +1,153 @@ +/** + * File: modules/ProductProfile.ycp + * Package: yast2 + * Summary: Functions for handling Product Profiles + * Authors: Jiri Suchomel <jsuchome@suse.cz> + * + * $Id$ + */ +{ + textdomain "base"; + module "ProductProfile"; + + import "Mode"; + import "Report"; + import "YaPI::SubscriptionTools";
Where is this module? I guess yast2.rpm should have a dependency on it.
+ + // path to the profile file on the media + string profile_path = "/profile.prod"; //FIXME the name + + // Result map of isCompliance call. + // If map is not empty, contains reasons why system is not compliant. + map<string,any> compliance = $[]; + + // profiles for all installed products
From an earlier commit, it is apparent that the strings are filenames (as opposed to contents of the files). Please mention that in the comment. How is the variable initialized? Wouldn't it be better to use a function, like GetComplianceMap does with compliance?
+ global list<string> all_profiles = []; + + // return the result of last compliance test + global map<string,any> GetComplianceMap () { + return compliance; + } + + /** + * Checks the profile compliance with the system. + * @param if productId is not nil, check only compliance with given product + * (once new product is added, function should be called to with new product ID) + * @ret true if the system is compliant + */ + global boolean IsCompliant (integer productId) { + + list<string> profiles = []; + list<map> products = []; + list<string> sigkeys = []; + + // iterate all (or given) products and get the info about them + foreach (map product, Pkg::ResolvableProperties ("", `product, ""), { + + integer src_id = product["source"]:-1; + + if (product["status"]:`none != `selected) + return; + + if (productId != nil && src_id != productId) + return; + + // generate product map: + list<string> version_release = splitstring (product["version"]:"", "-"); + products = add (products, $[ + "arch" : product["arch"]:"", + "name" : product["name"]:"", + "version" : version_release[0]:"", + "release" : version_release[1]:"", + "vendor" : product["vendor"]:"" + ]); + + // FIXME it might be needed to check to directory.yast as well for *.profile + string profile = Pkg::SourceProvideOptionalFile (src_id, 1, profile_path); + if (profile != nil) + { + profiles = add (profiles, profile); + } + + // find the list of sigkeys
Comments like these are asking for a function: list<string> SourceSigkeys (integer src_id) { ... }
+ string dir_file = Pkg::SourceProvideOptionalFile (src_id, 1, "/directory.yast"); + map out = (map) SCR::Execute (.target.bash_output, sformat ( + "grep 'gpg-pubkey' %1 2>/dev/null", dir_file)); + list<string> keys = filter (string k, splitstring (out["stdout"]:"", "\n"), ``(k != "")); + + y2internal ("keys for %1: %2", src_id, keys); + + sigkeys = (list<string>) union (sigkeys, keys); + }); + + // remember profiles so they can be copied them to the installed system + all_profiles = union (all_profiles, profiles); + + y2internal ("products: %1", products); + + if (profiles == []) + { + y2milestone ("no product profile present"); + compliance = $[]; + return true; + } + + compliance = YaPI::SubscriptionTools::isCompliant (profiles, products, sigkeys); + return (compliance == nil); + } + + + /** + * Checks the profile compliance with the system. + * If system is not complient, shows a popup with reasons and asks + * to continue with the installation. + * @ret Returns true if system is complient or user agrees to continue + * although the complience test failed. + * @param if productId is not nil, check only compliance with given product + * (once new product is added, function should be called to with new product ID) + */ + global boolean CheckCompliance (integer productId) { + + // behavior for non-installation not defined yet + if (!Mode::installation ()) + { + return true; + } + + if (IsCompliant (productId)) + { + return true; + } + + list<string> reasons = []; + foreach (string key, any val, compliant, { + y2internal ("key %1, val %2", key, val); + if (is (val, map) && haskey ((map)val, "message")) + { + reasons = add (reasons, ((map)val)["message"]:""); + } + });
+ list<string> reasons = [ + "Architecture(x86_64) is not one of: s390x, i586", + "Number of CPU cores(2) exceeds 1" + ];
Are you sure to redeclare reasons? Is this a forgotten example list?
+ + return Report::AnyQuestion ( + // popup dialog caption + _("Warning"), + // popup message, %1 is list of problems + sformat (_("The system is not compliant with provided profile: + +%1 + +Do you want to continue or abort the installation?"), + mergestring (reasons, "\n") + ), + // button label + _("&Continue Installation"), + // button label + _("&Abort Installation"), + `no_button + ); + } +}
-- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
-- Martin Vidner, YaST developer http://en.opensuse.org/User:Mvidner Kuracke oddeleni v restauraci je jako fekalni oddeleni v bazenu
Dne Út 14. června 2011 16:28:38 Martin Vidner napsal(a):
+ import "YaPI::SubscriptionTools";
Where is this module? I guess yast2.rpm should have a dependency on it.
Yes, sure. But there are some unresolved things, so this is still WIP. I've just put my current work to svn.
+ + // path to the profile file on the media + string profile_path = "/profile.prod"; //FIXME the name + + // Result map of isCompliance call. + // If map is not empty, contains reasons why system is not compliant. + map<string,any> compliance = $[]; + + // profiles for all installed products
From an earlier commit, it is apparent that the strings are filenames (as opposed to contents of the files). Please mention that in the comment.
How is the variable initialized? Wouldn't it be better to use a function, like GetComplianceMap does with compliance?
It's initialized in IsCompliant function.The default is empty list, which makes sense.
Comments like these are asking for a function: list<string> SourceSigkeys (integer src_id) { ... }
Ok, right.
+ list<string> reasons = [ + "Architecture(x86_64) is not one of: s390x, i586", + "Number of CPU cores(2) exceeds 1" + ];
Are you sure to redeclare reasons? Is this a forgotten example list?
Exactly. Thanks for noticing. -- Jiri Suchomel SUSE LINUX, s.r.o. e-mail: jsuchome@suse.cz Lihovarská 1060/12 tel: +420 284 028 960 190 00 Praha 9, Czech Republic http://www.suse.cz -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
On Tue, Jun 14, 2011 at 04:47:02PM +0200, Jiri Suchomel wrote:
Dne Út 14. června 2011 16:28:38 Martin Vidner napsal(a):
+ import "YaPI::SubscriptionTools";
Where is this module? I guess yast2.rpm should have a dependency on it.
Yes, sure. But there are some unresolved things, so this is still WIP. I've just put my current work to svn.
Hmm, since yast2.rpm is a dependency for almost everything, please make sure that it stays clean in case we need to release it because of something else. Recently I have started using git-svn for tracking longer pieces of work: git svn clone http://svn.opensuse.org/svn/yast/trunk/yast2 yast2-git cd yast2-git hack, git commit, hack, git commit, git svn rebase, hack, git commit, optionally git rebase -i to cover up "typo" commits git svn dcommit # takes the git commits and applies them to svn 1 by 1 For people who are not familiar with git: that "git commit" only changes your local clone of the repository, so you don't have to put Work In Progress to subversion, and don't have to create (and merge) a subversion branch either. I think this is a nice way to try out git. -- Martin Vidner, YaST developer http://en.opensuse.org/User:Mvidner Kuracke oddeleni v restauraci je jako fekalni oddeleni v bazenu
On Tue, Jun 14, 2011 at 05:37:26PM +0200, Martin Vidner wrote:
On Tue, Jun 14, 2011 at 04:47:02PM +0200, Jiri Suchomel wrote:
Dne Út 14. června 2011 16:28:38 Martin Vidner napsal(a):
+ import "YaPI::SubscriptionTools";
Where is this module? I guess yast2.rpm should have a dependency on it.
Yes, sure. But there are some unresolved things, so this is still WIP. I've just put my current work to svn.
Hmm, since yast2.rpm is a dependency for almost everything, please make sure that it stays clean in case we need to release it because of something else.
I have this problem right now: After a tiny change I cannot make a new package for factory. Please make a new package by Friday for the next milestone. ciao Arvin -- Arvin Schnell, <aschnell@suse.de> Senior Software Engineer, Research & Development SUSE LINUX Products GmbH, GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer, HRB 16746 (AG Nürnberg) Maxfeldstraße 5 90409 Nürnberg Germany -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
Dne St 15. června 2011 10:44:33 Arvin Schnell napsal(a):
On Tue, Jun 14, 2011 at 05:37:26PM +0200, Martin Vidner wrote:
On Tue, Jun 14, 2011 at 04:47:02PM +0200, Jiri Suchomel wrote:
Dne Út 14. června 2011 16:28:38 Martin Vidner napsal(a):
+ import "YaPI::SubscriptionTools";
Where is this module? I guess yast2.rpm should have a dependency on it.
Yes, sure. But there are some unresolved things, so this is still WIP. I've just put my current work to svn.
Hmm, since yast2.rpm is a dependency for almost everything, please make sure that it stays clean in case we need to release it because of something else.
I have this problem right now: After a tiny change I cannot make a new package for factory.
Please make a new package by Friday for the next milestone.
Sorry for that. Actually, my changes maybe should not go to Factory at all. Jiri -- Jiri Suchomel SUSE LINUX, s.r.o. e-mail: jsuchome@suse.cz Lihovarská 1060/12 tel: +420 284 028 960 190 00 Praha 9, Czech Republic http://www.suse.cz -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
participants (3)
-
Arvin Schnell
-
Jiri Suchomel
-
Martin Vidner