Author: lslezak Date: Thu Aug 2 10:11:01 2007 New Revision: 39880 URL: http://svn.opensuse.org/viewcvs/yast?rev=39880&view=rev Log: - added Pkg::CallbackInitDownload() and Pkg::CallbackDestDownload() for registering the initial and the final even when downloading a file (to leave the progress popup open and avoid flashing) - call the new callbacks when scanning, probing, refreshing and downloading a file or directory - Pkg::SourceSaveAll() - remove also raw metadata cache for the removed repositories - ignore errors in the download callback when probing or scanning a repository (the downloaded files are optional) - Pkg::SourceProvideDir() - return the correct value - 2.15.39 Modified: trunk/pkg-bindings/ (props changed) trunk/pkg-bindings/VERSION trunk/pkg-bindings/package/yast2-pkg-bindings.changes trunk/pkg-bindings/src/Callbacks.YCP.h trunk/pkg-bindings/src/Callbacks.cc trunk/pkg-bindings/src/PkgModuleFunctions.h trunk/pkg-bindings/src/Source.cc Modified: trunk/pkg-bindings/VERSION URL: http://svn.opensuse.org/viewcvs/yast/trunk/pkg-bindings/VERSION?rev=39880&r1=39879&r2=39880&view=diff ============================================================================== --- trunk/pkg-bindings/VERSION (original) +++ trunk/pkg-bindings/VERSION Thu Aug 2 10:11:01 2007 @@ -1 +1 @@ -2.15.38 +2.15.39 Modified: trunk/pkg-bindings/package/yast2-pkg-bindings.changes URL: http://svn.opensuse.org/viewcvs/yast/trunk/pkg-bindings/package/yast2-pkg-bindings.changes?rev=39880&r1=39879&r2=39880&view=diff ============================================================================== --- trunk/pkg-bindings/package/yast2-pkg-bindings.changes (original) +++ trunk/pkg-bindings/package/yast2-pkg-bindings.changes Thu Aug 2 10:11:01 2007 @@ -1,4 +1,19 @@ ------------------------------------------------------------------- +Thu Aug 2 09:56:21 CEST 2007 - lslezak@suse.cz + +- added Pkg::CallbackInitDownload() and Pkg::CallbackDestDownload() + for registering the initial and the final even when downloading + a file (to leave the progress popup open and avoid flashing) +- call the new callbacks when scanning, probing, refreshing + and downloading a file or directory +- Pkg::SourceSaveAll() - remove also raw metadata cache for the + removed repositories +- ignore errors in the download callback when probing or scanning + a repository (the downloaded files are optional) +- Pkg::SourceProvideDir() - return the correct value +- 2.15.39 + +------------------------------------------------------------------- Wed Aug 1 10:14:28 CEST 2007 - lslezak@suse.cz - Pkg::SourceProvideDir() is non-recursive now (backward comaptible Modified: trunk/pkg-bindings/src/Callbacks.YCP.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/pkg-bindings/src/Callbacks.YCP.h?rev=39880&r1=39879&r2=39880&view=diff ============================================================================== --- trunk/pkg-bindings/src/Callbacks.YCP.h (original) +++ trunk/pkg-bindings/src/Callbacks.YCP.h Thu Aug 2 10:11:01 2007 @@ -82,7 +82,7 @@ CB_StartDeltaApply, CB_ProgressDeltaApply, CB_ProblemDeltaApply, CB_StartPatchDownload, CB_ProgressPatchDownload, CB_ProblemPatchDownload, CB_FinishDeltaDownload, CB_FinishDeltaApply, CB_FinishPatchDownload, - CB_StartDownload, CB_ProgressDownload, CB_DoneDownload, + CB_StartDownload, CB_ProgressDownload, CB_DoneDownload, CB_InitDownload, CB_DestDownload, CB_SourceProbeStart, CB_SourceProbeFailed, CB_SourceProbeSucceeded, CB_SourceProbeEnd, CB_SourceProbeProgress, CB_SourceProbeError, CB_SourceReportStart, CB_SourceReportProgress, CB_SourceReportError, CB_SourceReportEnd, CB_SourceReportInit, CB_SourceReportDestroy, @@ -136,6 +136,8 @@ ENUM_OUT( StartDownload ); ENUM_OUT( ProgressDownload ); ENUM_OUT( DoneDownload ); + ENUM_OUT( InitDownload ); + ENUM_OUT( DestDownload ); ENUM_OUT( ScriptStart ); ENUM_OUT( ScriptProgress ); Modified: trunk/pkg-bindings/src/Callbacks.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/pkg-bindings/src/Callbacks.cc?rev=39880&r1=39879&r2=39880&view=diff ============================================================================== --- trunk/pkg-bindings/src/Callbacks.cc (original) +++ trunk/pkg-bindings/src/Callbacks.cc Thu Aug 2 10:11:01 2007 @@ -822,8 +822,17 @@ { CB callback( ycpcb( YCPCallbacks::CB_DoneDownload ) ); + zypp::media::DownloadProgressReport::Error err = error; + + // ignore errors for optional files + if ( _silent_probing == MEDIA_CHANGE_DISABLE || + _silent_probing == MEDIA_CHANGE_OPTIONALFILE) + { + err = zypp::media::DownloadProgressReport::NO_ERROR; + } + if ( callback._set ) { - callback.addInt( error ); + callback.addInt( err ); callback.addStr( reason ); callback.evaluate(); } @@ -2528,4 +2537,11 @@ return SET_YCP_CB( CB_ProgressDone, func ); } +YCPValue PkgModuleFunctions::CallbackInitDownload( const YCPString& args ) { + return SET_YCP_CB( CB_InitDownload, args ); +} + +YCPValue PkgModuleFunctions::CallbackDestDownload( const YCPString& args ) { + return SET_YCP_CB( CB_DestDownload, args ); +} #undef SET_YCP_CB Modified: trunk/pkg-bindings/src/PkgModuleFunctions.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/pkg-bindings/src/PkgModuleFunctions.h?rev=39880&r1=39879&r2=39880&view=diff ============================================================================== --- trunk/pkg-bindings/src/PkgModuleFunctions.h (original) +++ trunk/pkg-bindings/src/PkgModuleFunctions.h Thu Aug 2 10:11:01 2007 @@ -162,6 +162,12 @@ void CallSourceReportInit(); void CallSourceReportDestroy(); + void CallInitDownload(const std::string &task); + void CallDestDownload(); + void RefreshWithCallbacks(const zypp::RepoInfo &repo); + zypp::repo::RepoType ProbeWithCallbacks(const zypp::Url &url); + void ScanProductsWithCallBacks(const zypp::Url &url); + // After all, APPL_HIGH might be more appropriate, because we suggest // the user what he should do and if it does not work, it's his job to // fix it (using USER). --ma @@ -270,6 +276,10 @@ YCPValue CallbackProgressDownload (const YCPString& func); /* TYPEINFO: void(string) */ YCPValue CallbackDoneDownload (const YCPString& func); + /* TYPEINFO: void(string) */ + YCPValue CallbackInitDownload( const YCPString& args ); + /* TYPEINFO: void(string) */ + YCPValue CallbackDestDownload( const YCPString& args ); /* TYPEINFO: void(string) */ YCPValue CallbackSourceCreateStart( const YCPString& func); Modified: trunk/pkg-bindings/src/Source.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/pkg-bindings/src/Source.cc?rev=39880&r1=39879&r2=39880&view=diff ============================================================================== --- trunk/pkg-bindings/src/Source.cc (original) +++ trunk/pkg-bindings/src/Source.cc Thu Aug 2 10:11:01 2007 @@ -54,15 +54,46 @@ Textdomain "pkg-bindings" */ -zypp::MediaProductSet scanProducts(const zypp::Url &url) +// scanned available products +// hack: zypp/MediaProducts.h cannot be included in PkgModuleFunctions.h +zypp::MediaProductSet available_products; + +// this method should be used instead of zypp::productsInMedia() +// it initializes the download callbacks +void PkgModuleFunctions::ScanProductsWithCallBacks(const zypp::Url &url) { - // scan available products - zypp::MediaProductSet products; + CallInitDownload(std::string(_("Scanning products in ") + url.asString())); + + extern ZyppRecipients::MediaChangeSensitivity _silent_probing; + // remember the current value + ZyppRecipients::MediaChangeSensitivity _silent_probing_old = _silent_probing; + + // disable media change callback for optional file + _silent_probing = ZyppRecipients::MEDIA_CHANGE_DISABLE; y2milestone("Scanning products in %s ...", url.asString().c_str()); - zypp::productsInMedia(url, products); - return products; + try + { + available_products.clear(); + zypp::productsInMedia(url, available_products); + } + catch(...) + { + // call the final event even in case of exception + CallDestDownload(); + + // restore the probing flag + _silent_probing = _silent_probing_old; + + // rethrow the execption + throw; + } + + CallDestDownload(); + + // restore the probing flag + _silent_probing = _silent_probing_old; } void PkgModuleFunctions::CallSourceReportStart(const std::string &text) @@ -127,6 +158,94 @@ } } +void PkgModuleFunctions::CallInitDownload(const std::string &task) +{ + // get the YCP callback handler for destroy event + Y2Function* ycp_handler = _callbackHandler._ycpCallbacks.createCallback(CallbackHandler::YCPCallbacks::CB_InitDownload); + + // is the callback registered? + if (ycp_handler != NULL) + { + ycp_handler->appendParameter(YCPString(task)); + // evaluate the callback function + ycp_handler->evaluateCall(); + } +} + +void PkgModuleFunctions::CallDestDownload() +{ + // get the YCP callback handler for destroy event + Y2Function* ycp_handler = _callbackHandler._ycpCallbacks.createCallback(CallbackHandler::YCPCallbacks::CB_DestDownload); + + // is the callback registered? + if (ycp_handler != NULL) + { + // evaluate the callback function + ycp_handler->evaluateCall(); + } +} + +// this method should be used instead of RepoManager::refreshMetadata() +void PkgModuleFunctions::RefreshWithCallbacks(const zypp::RepoInfo &repo) +{ + CallInitDownload(std::string(_("Refreshing repository ") + repo.alias())); + + try + { + zypp::RepoManager repomanager = CreateRepoManager(); + repomanager.refreshMetadata(repo); + } + catch(...) + { + // call the final event even in case of exception + CallDestDownload(); + // rethrow the execption + throw; + } + + CallDestDownload(); +} + +// this method should be used instead of RepoManager::probe() +zypp::repo::RepoType PkgModuleFunctions::ProbeWithCallbacks(const zypp::Url &url) +{ + CallInitDownload(std::string(_("Probing repository ") + url.asString())); + + zypp::repo::RepoType repotype; + + extern ZyppRecipients::MediaChangeSensitivity _silent_probing; + // remember the current value + ZyppRecipients::MediaChangeSensitivity _silent_probing_old = _silent_probing; + + // disable media change callback for optional file + _silent_probing = ZyppRecipients::MEDIA_CHANGE_DISABLE; + + try + { + // probe type of the repository + zypp::RepoManager repomanager = CreateRepoManager(); + repotype = repomanager.probe(url); + } + catch(...) + { + // call the final event even in case of exception + CallDestDownload(); + + // restore the probing flag + _silent_probing = _silent_probing_old; + + // rethrow the execption + throw; + } + + CallDestDownload(); + + // restore the probing flag + _silent_probing = _silent_probing_old; + + return repotype; +} + /** * Logging helper: * call zypp::SourceManager::sourceManager()->findSource @@ -289,15 +408,25 @@ // autorefresh the source if ((*it)->repoInfo().autorefresh()) { - y2milestone("Autorefreshing source: %s", (*it)->repoInfo().alias().c_str()); - repomanager.refreshMetadata((*it)->repoInfo()); + try + { + y2milestone("Autorefreshing source: %s", (*it)->repoInfo().alias().c_str()); + RefreshWithCallbacks((*it)->repoInfo()); - // rebuild cache (the default policy is "if needed") - y2milestone("Rebuilding cache for '%s'...", (*it)->repoInfo().alias().c_str()); - repomanager.buildCache((*it)->repoInfo()); + // rebuild cache (the default policy is "if needed") + y2milestone("Rebuilding cache for '%s'...", (*it)->repoInfo().alias().c_str()); + repomanager.buildCache((*it)->repoInfo()); + } + catch (const zypp::Exception& excpt) + { + // FIXME: assuming the sources are already initialized + y2error ("Error in SourceLoad: %s", excpt.asString().c_str()); + _last_error.setLastError(excpt.asUserString()); + success = false; + } } - success = LoadResolvablesFrom((*it)->repoInfo()); + success = success && LoadResolvablesFrom((*it)->repoInfo()); } } @@ -493,21 +622,31 @@ if ((*it)->isDeleted()) { std::string repo_alias = (*it)->repoInfo().alias(); - // remove the cache - if (repomanager.isCached((*it)->repoInfo())) - { - y2milestone("Removing cache for '%s'...", repo_alias.c_str()); - repomanager.cleanCache((*it)->repoInfo()); - } try { + // remove the metadata + zypp::RepoStatus raw_metadata_status = repomanager.metadataStatus((*it)->repoInfo()); + if (!raw_metadata_status.empty()) + { + y2milestone("Removing metadata for source '%s'...", repo_alias.c_str()); + repomanager.cleanMetadata((*it)->repoInfo()); + } + + // remove the cache + if (repomanager.isCached((*it)->repoInfo())) + { + y2milestone("Removing cache for '%s'...", repo_alias.c_str()); + repomanager.cleanCache((*it)->repoInfo()); + } + repomanager.getRepositoryInfo(repo_alias); y2milestone("Removing repository '%s'", repo_alias.c_str()); repomanager.removeRepository((*it)->repoInfo()); } catch (const zypp::repo::RepoNotFoundException &ex) { + // repository not found -- not critical, continue y2warning("No such repository: %s", repo_alias.c_str()); } catch (const zypp::Exception & excpt) @@ -859,8 +998,7 @@ const YCPString& f, const YCPBoolean & optional) { - CallSourceReportInit(); - CallSourceReportStart(_("Downloading file...")); + CallInitDownload(std::string(_("Downloading ") + f->value())); bool found = true; YRepo_Ptr repo = logFindRepository(id->value()); @@ -898,8 +1036,7 @@ // set the original probing value _silent_probing = _silent_probing_old; - CallSourceReportEnd(_("Downloading file...")); - CallSourceReportDestroy(); + CallDestDownload(); if (found) { @@ -968,7 +1105,7 @@ { y2warning("Pkg::SourceProvideDir() is obsoleted use Pkg::SourceProvideDirectory() instead"); // non optional, non recursive - SourceProvideDirectory(id, mid, d, false, false); + return SourceProvideDirectory(id, mid, d, false, false); } @@ -989,6 +1126,8 @@ YCPValue PkgModuleFunctions::SourceProvideDirectory(const YCPInteger& id, const YCPInteger& mid, const YCPString& d, const YCPBoolean &optional, const YCPBoolean &recursive) { + CallInitDownload(std::string(_("Downloading ") + d->value())); + bool found = true; YRepo_Ptr repo = logFindRepository(id->value()); if (!repo) @@ -1021,6 +1160,8 @@ // set the original probing value _silent_probing = _silent_probing_old; + CallDestDownload(); + if (found) { return YCPString(path.asString()); @@ -1261,7 +1402,7 @@ y2milestone("Probing source type: '%s'", url.asString().c_str()); // autoprobe type of the repository - repotype = repomanager.probe(url); + repotype = ProbeWithCallbacks(url); } y2milestone("Using source type: %s", repotype.asString().c_str()); @@ -1296,7 +1437,7 @@ y2milestone("Adding source '%s' (%s)", repo.alias().c_str(), url.asString().c_str()); // note: exceptions should be caught by the calling code - repomanager.refreshMetadata(repo); + RefreshWithCallbacks(repo); // build cache if needed if (!repomanager.isCached(repo)) @@ -1536,7 +1677,8 @@ try { y2milestone("Scanning products in %s ...", url.asString().c_str()); - zypp::productsInMedia(url, products); + ScanProductsWithCallBacks(url); + products = available_products; } catch ( const zypp::Exception& excpt) { @@ -1668,7 +1810,8 @@ zypp::MediaProductSet products; try { - products = scanProducts(url); + ScanProductsWithCallBacks(url); + products = available_products; } catch ( const zypp::Exception& excpt) { @@ -1843,7 +1986,7 @@ { zypp::RepoManager repomanager = CreateRepoManager(); y2milestone("Refreshing metadata '%s'", repo->repoInfo().alias().c_str()); - repomanager.refreshMetadata(repo->repoInfo()); + RefreshWithCallbacks(repo->repoInfo()); y2milestone("Caching source '%s'...", repo->repoInfo().alias().c_str()); repomanager.buildCache(repo->repoInfo()); @@ -2193,7 +2336,7 @@ if (raw_metadata_status.empty()) { y2milestone("Missing metadata for source '%s', downloading...", repoinfo.alias().c_str()); - repomanager.refreshMetadata(repoinfo); + RefreshWithCallbacks(repoinfo); } y2milestone("Caching source '%s'...", repoinfo.alias().c_str()); @@ -2249,7 +2392,7 @@ zypp::Url probe_url(url->value()); // autoprobe type of the repository - zypp::repo::RepoType repotype = repomanager.probe(probe_url); + zypp::repo::RepoType repotype = ProbeWithCallbacks(probe_url); ret = zypp2yastType(repotype.asString()); y2milestone("Detected type: '%s'...", ret.c_str()); @@ -2278,7 +2421,8 @@ try { zypp::Url baseurl(url->value()); - products = scanProducts(baseurl); + ScanProductsWithCallBacks(baseurl); + products = available_products; } catch ( const zypp::Exception& excpt) { -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org