/* Emits a dependency that has been found in the database. */ static bool emit_found_dependency(PkBackend *backend, struct pkg *package) { emit_package(package, backend, pkgutils_pkg_current_state(package)); return true; }
/* This prints out the bytes downloaded and the overall average line speed */ void AcqPackageKitStatus::Stop() { pkgAcquireStatus::Stop(); // the items that still on the set are finished for (set<string>::iterator it = currentPackages.begin(); it != currentPackages.end(); it++ ) { emit_package(*it, true); } }
int emit_python(lcmgen_t *lcm) { GHashTable *packages = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify)_package_contents_free); // group the enums and structs by package for (unsigned int i = 0; i < lcm->enums->len; i++) { lcm_enum_t *le = (lcm_enum_t *) g_ptr_array_index(lcm->enums, i); _package_contents_t *pc = (_package_contents_t *) g_hash_table_lookup (packages, le->enumname->package); if (!pc) { pc = _package_contents_new (le->enumname->package); g_hash_table_insert (packages, pc->name, pc); } g_ptr_array_add (pc->enums, le); } for (unsigned int i = 0; i < lcm->structs->len; i++) { lcm_struct_t *ls = (lcm_struct_t *) g_ptr_array_index(lcm->structs, i); _package_contents_t *pc = (_package_contents_t *) g_hash_table_lookup (packages, ls->structname->package); if (!pc) { pc = _package_contents_new (ls->structname->package); g_hash_table_insert (packages, pc->name, pc); } g_ptr_array_add (pc->structs, ls); } GPtrArray *vals = _hash_table_get_vals (packages); for (int i=0; i<vals->len; i++) { _package_contents_t *pc = (_package_contents_t *) g_ptr_array_index (vals, i); int status = emit_package (lcm, pc); if (0 != status) return status; } g_ptr_array_free (vals, TRUE); g_hash_table_destroy (packages); return 0; }
/* * Event handler for events emitted by pkg during an installation. TODO: Many * of these events are unhandled or deficiently handled. */ int event_cb(void *backend_v, struct pkg_event *event) { PkBackend *backend; assert(backend_v != NULL); assert(event != NULL); backend = (PkBackend *)backend_v; switch (event->type) { case PKG_EVENT_INSTALL_BEGIN: STATUS(backend, PK_STATUS_ENUM_INSTALL); emit_package(event->e_install_begin.pkg, backend, PK_INFO_ENUM_INSTALLING); break; case PKG_EVENT_INSTALL_FINISHED: emit_package(event->e_install_finished.pkg, backend, PK_INFO_ENUM_FINISHED); break; case PKG_EVENT_DEINSTALL_BEGIN: STATUS(backend, PK_STATUS_ENUM_REMOVE); emit_package(event->e_deinstall_begin.pkg, backend, PK_INFO_ENUM_REMOVING); break; case PKG_EVENT_DEINSTALL_FINISHED: emit_package(event->e_deinstall_finished.pkg, backend, PK_INFO_ENUM_FINISHED); break; case PKG_EVENT_UPGRADE_BEGIN: STATUS(backend, PK_STATUS_ENUM_UPDATE); emit_package(event->e_upgrade_begin.pkg, backend, PK_INFO_ENUM_UPDATING); break; case PKG_EVENT_UPGRADE_FINISHED: emit_package(event->e_upgrade_finished.pkg, backend, PK_INFO_ENUM_FINISHED); break; case PKG_EVENT_FETCHING: STATUS(backend, PK_STATUS_ENUM_DOWNLOAD); break; case PKG_EVENT_INTEGRITYCHECK_BEGIN: case PKG_EVENT_INTEGRITYCHECK_FINISHED: /* Unimplemented */ break; case PKG_EVENT_INTEGRITYCHECK_CONFLICT: ERR(backend, PK_ERROR_ENUM_PACKAGE_CORRUPT, event->e_integrity_conflict.pkg_name); break; case PKG_EVENT_NEWPKGVERSION: /* TODO: find a better enum for this? */ ERR(backend, PK_ERROR_ENUM_PACKAGE_INSTALL_BLOCKED, "A new version of pkg is available; install that first."); break; case PKG_EVENT_NOTICE: case PKG_EVENT_INCREMENTAL_UPDATE: /* Unimplemented */ break; case PKG_EVENT_ERROR: /* * This is sometimes used for nonfatal errors, so we can't * throw an error code here. What we'll do (mainly for debug * purposes) is post the error into the backend so we can * retrieve it if it was fatal. * * pk_backend_set_string seems to strdup, so we don't have to. */ (void)pk_backend_set_string(backend, "job_error", event->e_pkg_error.msg); break; case PKG_EVENT_ERRNO: case PKG_EVENT_ARCHIVE_COMP_UNSUP: /* Unimplemented */ break; case PKG_EVENT_ALREADY_INSTALLED: ERR(backend, PK_ERROR_ENUM_PACKAGE_ALREADY_INSTALLED, "Already installed."); break; case PKG_EVENT_FAILED_CKSUM: case PKG_EVENT_CREATE_DB_ERROR: /* Unimplemented */ break; case PKG_EVENT_LOCKED: /* TODO: find a better enum for this? */ ERR(backend, PK_ERROR_ENUM_PACKAGE_INSTALL_BLOCKED, "Package is locked."); break; case PKG_EVENT_REQUIRED: /* TODO: find a better enum for this? */ ERR(backend, PK_ERROR_ENUM_CANNOT_REMOVE_SYSTEM_PACKAGE, "Package is required."); break; case PKG_EVENT_MISSING_DEP: ERR(backend, PK_ERROR_ENUM_DEP_RESOLUTION_FAILED, "Package is missing a dependency."); break; case PKG_EVENT_NOREMOTEDB: case PKG_EVENT_NOLOCALDB: /* Unimplemented */ break; case PKG_EVENT_FILE_MISMATCH: ERR(backend, PK_ERROR_ENUM_PACKAGE_CORRUPT, pkg_file_path(event->e_file_mismatch.file)); break; case PKG_EVENT_DEVELOPER_MODE: case PKG_EVENT_PLUGIN_ERRNO: case PKG_EVENT_PLUGIN_ERROR: case PKG_EVENT_PLUGIN_INFO: /* Unimplemented */ break; case PKG_EVENT_NOT_FOUND: ERR(backend, PK_ERROR_ENUM_PACKAGE_DOWNLOAD_FAILED, event->e_not_found.pkg_name); } return EPKG_OK; }
/* This draws the current progress. Each line has an overall percent meter and a per active item status meter along with an overall bandwidth and ETA indicator. */ bool AcqPackageKitStatus::Pulse(pkgAcquire *Owner) { pkgAcquireStatus::Pulse(Owner); unsigned long percent_done; percent_done = long(double((CurrentBytes + CurrentItems)*100.0)/double(TotalBytes+TotalItems)); // Emit the percent done if (last_percent != percent_done) { if (last_percent < percent_done) { pk_backend_set_percentage(m_backend, percent_done); } else { pk_backend_set_percentage(m_backend, PK_BACKEND_PERCENTAGE_INVALID); pk_backend_set_percentage(m_backend, percent_done); } last_percent = percent_done; } set<string> localCurrentPackages = currentPackages;; for (pkgAcquire::Worker *I = Owner->WorkersBegin(); I != 0; I = Owner->WorkerStep(I)) { // Check if there is no item running or if we don't have // any packages set we are probably refreshing the cache if (I->CurrentItem == 0 || packages.size() == 0) { continue; } emit_package(I->CurrentItem->ShortDesc, false); localCurrentPackages.erase(I->CurrentItem->ShortDesc); // Add the total size and percent if (I->TotalSize > 0 && I->CurrentItem->Owner->Complete == false) { unsigned long sub_percent; // TODO PackageKit needs to emit package with progress. sub_percent = long(double(I->CurrentSize*100.0)/double(I->TotalSize)); if (last_sub_percent != sub_percent) { if (last_sub_percent < sub_percent) { pk_backend_set_sub_percentage(m_backend, sub_percent); } else { pk_backend_set_sub_percentage(m_backend, PK_BACKEND_PERCENTAGE_INVALID); pk_backend_set_sub_percentage(m_backend, sub_percent); } last_sub_percent = sub_percent; } } } // the items that still on the set are finished for (set<string>::iterator it = localCurrentPackages.begin(); it != localCurrentPackages.end(); it++ ) { emit_package(*it, true); } double localCPS = (CurrentCPS >= 0) ? CurrentCPS : -1 * CurrentCPS; if (localCPS != last_CPS) { last_CPS = localCPS; pk_backend_set_speed(m_backend, (int) last_CPS); } Update = false; return !_cancelled;; }