[yast-commit] r64897 - in /branches/SuSE-Code-11-SP1-Branch/pkg-bindings: ./ package/yast2-pkg-bindings.changes src/Package.cc src/PkgFunctions.h

Author: lslezak Date: Tue Jul 19 20:26:35 2011 New Revision: 64897 URL: http://svn.opensuse.org/viewcvs/yast?rev=64897&view=rev Log: backport from SP2 branch: - added Pkg::Commit() function which accepts commit options map (with download_mode, dry_run... options) (FATE#308951) Modified: branches/SuSE-Code-11-SP1-Branch/pkg-bindings/ (props changed) branches/SuSE-Code-11-SP1-Branch/pkg-bindings/package/yast2-pkg-bindings.changes branches/SuSE-Code-11-SP1-Branch/pkg-bindings/src/Package.cc branches/SuSE-Code-11-SP1-Branch/pkg-bindings/src/PkgFunctions.h Modified: branches/SuSE-Code-11-SP1-Branch/pkg-bindings/package/yast2-pkg-bindings.changes URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP1-Branch/pkg-bi... ============================================================================== --- branches/SuSE-Code-11-SP1-Branch/pkg-bindings/package/yast2-pkg-bindings.changes (original) +++ branches/SuSE-Code-11-SP1-Branch/pkg-bindings/package/yast2-pkg-bindings.changes Tue Jul 19 20:26:35 2011 @@ -1,4 +1,9 @@ ------------------------------------------------------------------- + +- added Pkg::Commit() function which accepts commit options map + (with download_mode, dry_run... options) (FATE#308951) + +------------------------------------------------------------------- Wed Apr 21 17:22:31 UTC 2010 - lslezak@suse.cz - reload services after refresh to avoid overwriting the updated Modified: branches/SuSE-Code-11-SP1-Branch/pkg-bindings/src/Package.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP1-Branch/pkg-bi... ============================================================================== --- branches/SuSE-Code-11-SP1-Branch/pkg-bindings/src/Package.cc (original) +++ branches/SuSE-Code-11-SP1-Branch/pkg-bindings/src/Package.cc Tue Jul 19 20:26:35 2011 @@ -2015,31 +2015,8 @@ return YCPVoid(); } -/** - @builtin PkgCommit - - @short Commit package changes (actually install/delete packages) - @description - - if medianr == 0, all packages regardless of media are installed - - if medianr > 0, only packages from this media are installed - - @param integer medianr Media Number - @return list [ int successful, list failed, list remaining, list srcremaining ] - The 'successful' value will be negative, if installation was aborted ! - -*/ -YCPValue -PkgFunctions::PkgCommit (const YCPInteger& media) +YCPValue PkgFunctions::CommitHelper(const zypp::ZYppCommitPolicy &policy) { - int medianr = media->value (); - - if (medianr < 0) - { - return YCPError ("Bad args to Pkg::PkgCommit"); - } - zypp::ZYpp::CommitResult result; // clean the last reported source @@ -2052,8 +2029,6 @@ last_reported_repo = -1; last_reported_mediumnr = 1; - zypp::ZYppCommitPolicy policy; - policy.restrictToMedia( medianr ); result = zypp_ptr()->commit(policy); } catch (const zypp::target::TargetAbortedException & excpt) @@ -2119,6 +2094,186 @@ } /** + @builtin PkgCommit + + @short Commit package changes (actually install/delete packages), see also Pkg::Commit() + @description + + if medianr == 0, all packages regardless of media are installed + + if medianr > 0, only packages from this media are installed + + @param integer medianr Media Number + @return list [ int successful, list failed, list remaining, list srcremaining ] + The 'successful' value will be negative, if installation was aborted ! + +*/ +YCPValue +PkgFunctions::PkgCommit (const YCPInteger& media) +{ + int medianr = media->value (); + + if (medianr < 0) + { + return YCPError ("Bad args to Pkg::PkgCommit"); + } + + zypp::ZYppCommitPolicy policy; + policy.restrictToMedia( medianr ); + + return CommitHelper(policy); +} + +/** + * @builtin Commit + * + * @short Commit package changes (actually install/delete packages) + * @description + * + * @param map commit configuration, currently supported values: + * $["download_mode":`default|`download_only|`download_only|`download_in_advance| + * `download_in_heaps|`download_as_needed, "medium_nr":<integer>, + * "dry_run":<boolean>, "exclude_docs":<boolean>, "no_signature":<boolean>], + * the default is $["download_mode":`default, "medium_nr":0 (all media), + * "dry_run":false, "exclude_docs":false, "no_signature":false], + * + * @return list [ int successful, list failed, list remaining, list srcremaining ] + * The 'successful' value will be negative, if installation was aborted ! +*/ +/* TYPEINFO: list<any>(integer)*/ +YCPValue PkgFunctions::Commit (const YCPMap& config) +{ + zypp::ZYppCommitPolicy policy; + + if (!config.isNull()) + { + YCPString key("download_mode"); + + // set the download mode + if(!config->value(key).isNull()) + { + if (config->value(key)->isSymbol()) + { + std::string mode = config->value(key)->asSymbol()->symbol(); + + if (mode == "default") + { + policy.downloadMode(zypp::DownloadDefault); + } + else if (mode == "download_only") + { + policy.downloadMode(zypp::DownloadOnly); + } + else if (mode == "download_in_advance") + { + policy.downloadMode(zypp::DownloadInAdvance); + } + else if (mode == "download_in_heaps") + { + policy.downloadMode(zypp::DownloadInHeaps); + } + else if (mode == "download_as_needed") + { + policy.downloadMode(zypp::DownloadAsNeeded); + } + else + { + y2error("Invalid download mode: %s", mode.c_str()); + _last_error.setLastError(std::string("Invalid download mode: ") + mode); + return YCPVoid(); + } + + y2milestone("Using download mode: %s", mode.c_str()); + } + else + { + y2error("Invalid download mode: symbol is required, got: %s", config->value(key)->asString()->value().c_str()); + _last_error.setLastError(std::string("Invalid download mode: ") + config->value(key)->asString()->value()); + return YCPVoid(); + } + } + + key = YCPString("medium_nr"); + // set the medium number + if(!config->value(key).isNull()) + { + if (config->value(key)->isInteger()) + { + unsigned medium_nr = config->value(key)->asInteger()->value(); + policy.restrictToMedia(medium_nr); + + y2milestone("Restricting commit only to medium number: %u", medium_nr); + } + else + { + y2error("Invalid medium number: integer is required, got: %s", config->value(key)->asString()->value().c_str()); + _last_error.setLastError(std::string("Invalid medium number: ") + config->value(key)->asString()->value()); + return YCPVoid(); + } + } + + key = YCPString("dry_run"); + // set the medium number + if(!config->value(key).isNull()) + { + if (config->value(key)->isBoolean()) + { + bool dry_run = config->value(key)->asBoolean()->value(); + policy.dryRun(dry_run); + + y2milestone("Dry run commit: %s", config->value(key)->asString()->value().c_str()); + } + else + { + y2error("Dry run option: boolean is required, got: %s", config->value(key)->asString()->value().c_str()); + _last_error.setLastError(std::string("Invalid dry run option: ") + config->value(key)->asString()->value()); + return YCPVoid(); + } + } + + key = YCPString("exclude_docs"); + // set the medium number + if(!config->value(key).isNull()) + { + if (config->value(key)->isBoolean()) + { + bool exclude_docs = config->value(key)->asBoolean()->value(); + policy.rpmExcludeDocs(exclude_docs); + + y2milestone("Excluding documentation: %s", config->value(key)->asString()->value().c_str()); + } + else + { + y2error("Exclude documentation option: boolean is required, got: %s", config->value(key)->asString()->value().c_str()); + _last_error.setLastError(std::string("Invalid exclude documentation option: ") + config->value(key)->asString()->value()); + return YCPVoid(); + } + } + + key = YCPString("no_signature"); + // set the medium number + if(!config->value(key).isNull()) + { + if (config->value(key)->isBoolean()) + { + bool no_signature = config->value(key)->asBoolean()->value(); + policy.rpmNoSignature(no_signature); + + y2milestone("Don't check RPM signature: %s", config->value(key)->asString()->value().c_str()); + } + else + { + y2error("No signature option: boolean is required, got: %s", config->value(key)->asString()->value().c_str()); + _last_error.setLastError(std::string("Invalid no signature option: ") + config->value(key)->asString()->value()); + return YCPVoid(); + } + } + } + + return CommitHelper(policy); +} + +/** @builtin GetBackupPath @short get current path for update backup of rpm config files Modified: branches/SuSE-Code-11-SP1-Branch/pkg-bindings/src/PkgFunctions.h URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP1-Branch/pkg-bi... ============================================================================== --- branches/SuSE-Code-11-SP1-Branch/pkg-bindings/src/PkgFunctions.h (original) +++ branches/SuSE-Code-11-SP1-Branch/pkg-bindings/src/PkgFunctions.h Tue Jul 19 20:26:35 2011 @@ -705,8 +705,11 @@ YCPBoolean PkgSolveCheckTargetOnly (); /* TYPEINFO: integer()*/ YCPValue PkgSolveErrors (); + YCPValue CommitHelper(const zypp::ZYppCommitPolicy &policy); /* TYPEINFO: list<any>(integer)*/ YCPValue PkgCommit (const YCPInteger& medianr); + /* TYPEINFO: list<any>(map<string,any>)*/ + YCPValue Commit (const YCPMap& config); /* TYPEINFO: boolean(map<string,any>)*/ YCPValue AddLock(const YCPMap &lock); -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
lslezak@svn2.opensuse.org