static off_t pkg_get_size(alpm_pkg_t *pkg) { switch(config->op) { case PM_OP_SYNC: return alpm_pkg_download_size(pkg); case PM_OP_UPGRADE: return alpm_pkg_get_size(pkg); default: return alpm_pkg_get_isize(pkg); } }
/* returns package info as list of strings */ static alpm_list_t *create_verbose_row(pm_target_t *target) { char *str; off_t size = 0; double human_size; const char *label; alpm_list_t *ret = NULL; /* a row consists of the package name, */ if(target->install) { const alpm_db_t *db = alpm_pkg_get_db(target->install); if(db) { pm_asprintf(&str, "%s/%s", alpm_db_get_name(db), alpm_pkg_get_name(target->install)); } else { pm_asprintf(&str, "%s", alpm_pkg_get_name(target->install)); } } else { pm_asprintf(&str, "%s", alpm_pkg_get_name(target->remove)); } ret = alpm_list_add(ret, str); /* old and new versions */ pm_asprintf(&str, "%s", target->remove != NULL ? alpm_pkg_get_version(target->remove) : ""); ret = alpm_list_add(ret, str); pm_asprintf(&str, "%s", target->install != NULL ? alpm_pkg_get_version(target->install) : ""); ret = alpm_list_add(ret, str); /* and size */ size -= target->remove ? alpm_pkg_get_isize(target->remove) : 0; size += target->install ? alpm_pkg_get_isize(target->install) : 0; human_size = humanize_size(size, 'M', 2, &label); pm_asprintf(&str, "%.2f %s", human_size, label); ret = alpm_list_add(ret, str); size = target->install ? alpm_pkg_download_size(target->install) : 0; if(size != 0) { human_size = humanize_size(size, 'M', 2, &label); pm_asprintf(&str, "%.2f %s", human_size, label); } else { str = NULL; } ret = alpm_list_add(ret, str); return ret; }
/* prepare a list of pkgs to display */ static void _display_targets(alpm_list_t *targets, int verbose) { char *str; const char *label; double size; off_t isize = 0, rsize = 0, dlsize = 0; unsigned short cols; alpm_list_t *i, *rows = NULL, *names = NULL; if(!targets) { return; } /* gather package info */ for(i = targets; i; i = alpm_list_next(i)) { pm_target_t *target = i->data; if(target->install) { dlsize += alpm_pkg_download_size(target->install); isize += alpm_pkg_get_isize(target->install); } if(target->remove) { /* add up size of all removed packages */ rsize += alpm_pkg_get_isize(target->remove); } } /* form data for both verbose and non-verbose display */ for(i = targets; i; i = alpm_list_next(i)) { pm_target_t *target = i->data; rows = alpm_list_add(rows, create_verbose_row(target)); if(target->install) { pm_asprintf(&str, "%s-%s", alpm_pkg_get_name(target->install), alpm_pkg_get_version(target->install)); } else if(isize == 0) { pm_asprintf(&str, "%s-%s", alpm_pkg_get_name(target->remove), alpm_pkg_get_version(target->remove)); } else { pm_asprintf(&str, "%s-%s [removal]", alpm_pkg_get_name(target->remove), alpm_pkg_get_version(target->remove)); } names = alpm_list_add(names, str); } /* print to screen */ pm_asprintf(&str, _("Packages (%d):"), alpm_list_count(targets)); printf("\n"); cols = getcols(fileno(stdout)); if(verbose) { alpm_list_t *header = create_verbose_header(); if(table_display(str, header, rows, cols) != 0) { /* fallback to list display if table wouldn't fit */ list_display(str, names, cols); } alpm_list_free(header); } else { list_display(str, names, cols); } printf("\n"); /* rows is a list of lists of strings, free inner lists here */ for(i = rows; i; i = alpm_list_next(i)) { alpm_list_t *lp = i->data; FREELIST(lp); } alpm_list_free(rows); FREELIST(names); free(str); if(dlsize > 0 || config->op_s_downloadonly) { size = humanize_size(dlsize, 'M', 2, &label); printf(_("Total Download Size: %.2f %s\n"), size, label); } if(!config->op_s_downloadonly) { if(isize > 0) { size = humanize_size(isize, 'M', 2, &label); printf(_("Total Installed Size: %.2f %s\n"), size, label); } if(rsize > 0 && isize == 0) { size = humanize_size(rsize, 'M', 2, &label); printf(_("Total Removed Size: %.2f %s\n"), size, label); } /* only show this net value if different from raw installed size */ if(isize > 0 && rsize > 0) { size = humanize_size(isize - rsize, 'M', 2, &label); printf(_("Net Upgrade Size: %.2f %s\n"), size, label); } } }
static gboolean pk_backend_get_details_thread (PkBackend *self) { gchar **packages; GError *error = NULL; g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (localdb != NULL, FALSE); packages = pk_backend_get_strv (self, "package_ids"); g_return_val_if_fail (packages != NULL, FALSE); for (; *packages != NULL; ++packages) { alpm_pkg_t *pkg; const alpm_list_t *i; GString *licenses; PkGroupEnum group; const gchar *desc, *url; gulong size; if (pk_backend_cancelled (self)) { break; } pkg = pk_backend_find_pkg (self, *packages, &error); if (pkg == NULL) { break; } i = alpm_pkg_get_licenses (pkg); if (i == NULL) { licenses = g_string_new ("Unknown"); } else { licenses = g_string_new ((const gchar *) i->data); while ((i = i->next) != NULL) { const gchar *license = (const gchar *) i->data; /* assume OR although it may not be correct */ g_string_append_printf (licenses, " or %s", license); } } group = pk_group_enum_from_string (alpm_pkg_get_group (pkg)); desc = alpm_pkg_get_desc (pkg); url = alpm_pkg_get_url (pkg); if (alpm_pkg_get_origin (pkg) == ALPM_PKG_FROM_LOCALDB) { size = alpm_pkg_get_isize (pkg); } else { size = alpm_pkg_download_size (pkg); } pk_backend_job_details (self, *packages, licenses->str, group, desc, url, size); g_string_free (licenses, TRUE); } return pk_backend_finish (self, error); }
static PyObject* pyalpm_pkg_download_size(AlpmPackage *self, void *closure) { CHECK_IF_INITIALIZED(); return PyLong_FromLongLong(alpm_pkg_download_size(self->c_data)); }
/* prepare a list of pkgs to display */ static void _display_targets(alpm_list_t *targets, int verbose) { char *str; off_t isize = 0, rsize = 0, dlsize = 0; unsigned short cols; alpm_list_t *i, *names = NULL, *header = NULL, *rows = NULL; if(!targets) { return; } /* gather package info */ for(i = targets; i; i = alpm_list_next(i)) { pm_target_t *target = i->data; if(target->install) { dlsize += alpm_pkg_download_size(target->install); isize += alpm_pkg_get_isize(target->install); } if(target->remove) { /* add up size of all removed packages */ rsize += alpm_pkg_get_isize(target->remove); } } /* form data for both verbose and non-verbose display */ for(i = targets; i; i = alpm_list_next(i)) { pm_target_t *target = i->data; if(verbose) { rows = alpm_list_add(rows, create_verbose_row(target)); } if(target->install) { pm_asprintf(&str, "%s-%s", alpm_pkg_get_name(target->install), alpm_pkg_get_version(target->install)); } else if(isize == 0) { pm_asprintf(&str, "%s-%s", alpm_pkg_get_name(target->remove), alpm_pkg_get_version(target->remove)); } else { pm_asprintf(&str, "%s-%s [%s]", alpm_pkg_get_name(target->remove), alpm_pkg_get_version(target->remove), _("removal")); } names = alpm_list_add(names, str); } /* print to screen */ pm_asprintf(&str, "%s (%zd)", _("Packages"), alpm_list_count(targets)); printf("\n"); cols = getcols(fileno(stdout)); if(verbose) { header = create_verbose_header(alpm_list_count(targets)); if(table_display(header, rows, cols) != 0) { /* fallback to list display if table wouldn't fit */ list_display(str, names, cols); } } else { list_display(str, names, cols); } printf("\n"); table_free(header, rows); FREELIST(names); free(str); rows = NULL; if(dlsize > 0 || config->op_s_downloadonly) { add_transaction_sizes_row(&rows, _("Total Download Size:"), dlsize); } if(!config->op_s_downloadonly) { if(isize > 0) { add_transaction_sizes_row(&rows, _("Total Installed Size:"), isize); } if(rsize > 0 && isize == 0) { add_transaction_sizes_row(&rows, _("Total Removed Size:"), rsize); } /* only show this net value if different from raw installed size */ if(isize > 0 && rsize > 0) { add_transaction_sizes_row(&rows, _("Net Upgrade Size:"), isize - rsize); } } table_display(NULL, rows, cols); table_free(NULL, rows); }