Minor fixes and improvements

This commit is contained in:
zawz 2020-08-21 10:17:56 +02:00
parent 52a35fe7d1
commit d760866095
9 changed files with 58 additions and 42 deletions

View file

@ -13,7 +13,7 @@ ifeq ($(DEBUG),true)
CXXFLAGS += -g
CC=clang++
else
CXXFLAGS += -O2 -fopenmp
CXXFLAGS += -Os -fopenmp
endif
ifeq ($(STATIC),true)
LDFLAGS += -l:libztd.a

View file

@ -4,6 +4,15 @@ Cross-distro updating and safe update preview
## Installing
### From [zpkg](https://github.com/zawwz/ztd)
```sh
# install zpkg
wget -qO- https://zpkg.zawz.net/install.sh | sh
# install zupdate
zpkg install zupdate
```
### From source
#### Dependencies

2
commands/aur_ext_size Normal file
View file

@ -0,0 +1,2 @@
#!/bin/sh
yay -Si --logfile /dev/null %s | grep '^Version' | cut -d':' -f2- | sed 's/ //g;1!s/iB$//g;1!s/B//g'

View file

@ -3,6 +3,7 @@
#define PACMAN_FETCH_COMMAND "CHECKUPDATES_DB=\"${TMPDIR:-/tmp}/checkup-db-$USER/\"\nDBPath=\"$(pacman-conf DBPath)\"\nmkdir -p \"$CHECKUPDATES_DB\"\nln -sf \"$DBPath/local\" \"$CHECKUPDATES_DB\" > /dev/null 2>&1\nfakeroot pacman -Sy --dbpath \"$CHECKUPDATES_DB\" --logfile /dev/null >/dev/null || exit $?\npacman -Qu --dbpath \"$CHECKUPDATES_DB/\" 2> /dev/null | cut -d ' ' -f1 | grep -v '\\[.*\\]'"
#define PACMAN_EXT_SIZE_COMMAND "pacman -Si --dbpath \"${TMPDIR:-/tmp}/checkup-db-$USER/\" --logfile /dev/null %s | grep -E '^Version|^Download Size|^Installed Size' | cut -d':' -f2- | sed 's/ //g;1!s/iB$//g;1!s/B//g'"
#define AUR_EXT_SIZE_COMMAND "yay -Si --logfile /dev/null %s | grep '^Version' | cut -d':' -f2- | sed 's/ //g;1!s/iB$//g;1!s/B//g'"
#define APT_LOCAL_SIZE_COMMAND "dpkg -s %s 2>/dev/null| grep -E '^Version:|^Installed-Size:' | awk '{if(NR==1) tmp=$2*1024;else print $2}END{printf \"%%u\\\\n\", tmp}'"
#define PACMAN_LOCAL_SIZE_COMMAND "pacman -Qi %s | grep -E '^Version|^Installed Size' | cut -d':' -f2- | tr -d ' ' | sed 's/ //g;1!s/iB$//g;1!s/B//g'"
#define APT_FETCH_COMMAND "sudo apt-get update >/dev/null || exit $?\napt list --upgradable 2>/dev/null | tail -n +2 | cut -d'/' -f1"

View file

@ -24,7 +24,7 @@ std::pair<double, const char*> convertHReadable(const int64_t size);
void print_separator(uint32_t length, ztd::color color, char sepchar='=');
void print_update(repo_update& ru, ztd::color color, bool dlsize=false, bool nisize=false, bool nusize=false);
void print_update(repo_update& ru, ztd::color color, bool dlsize=false, bool nisize=false, bool nusize=false, bool print_only_install=false);
void print_update_sizes(repo_update& ru, ztd::color color, bool dlsize, bool nisize, bool cisize, bool notitle, uint32_t padsize);

View file

@ -19,14 +19,17 @@
uint64_t sizeconvert(std::string const& in)
{
if(in.size()==0)
return 0;
double num=std::stod(in.substr(0, in.size()-1));
switch(in[in.size()-1])
{
case 'K': return (uint64_t) (std::stod(in.substr(0, in.size()-1)) * KB_MULT); break;
case 'M': return (uint64_t) (std::stod(in.substr(0, in.size()-1)) * MB_MULT); break;
case 'G': return (uint64_t) (std::stod(in.substr(0, in.size()-1)) * GB_MULT); break;
case 'T': return (uint64_t) (std::stod(in.substr(0, in.size()-1)) * TB_MULT); break;
case 'P': return (uint64_t) (std::stod(in.substr(0, in.size()-1)) * PB_MULT); break;
case 'E': return (uint64_t) (std::stod(in.substr(0, in.size()-1)) * EB_MULT); break;
case 'K': return (uint64_t) (num * KB_MULT); break;
case 'M': return (uint64_t) (num * MB_MULT); break;
case 'G': return (uint64_t) (num * GB_MULT); break;
case 'T': return (uint64_t) (num * TB_MULT); break;
case 'P': return (uint64_t) (num * PB_MULT); break;
case 'E': return (uint64_t) (num * EB_MULT); break;
default: return std::stoul(in);
}
}
@ -47,14 +50,10 @@ int fetch_update(repo_update* r, const std::string& name, const std::string& com
{
r->packages.clear();
r->name=name;
r->name_max_length=0;
r->vcur_max_length=0;
r->vnew_max_length=0;
r->max_install_size=0;
r->max_download_size=0;
r->max_net_size=0;
r->download_size = r->new_install_size = r->current_install_size = 0;
r->name_max_length = r->vcur_max_length = r->vnew_max_length = 0;
r->max_install_size = r->max_download_size = r->max_net_size = r->n_updates = 0;
r->has_update=false;
r->n_updates=0;
std::string sup;
if(args.size()>0)
@ -128,9 +127,6 @@ int import_sizes(repo_update* ru, const char* ext_size_command, const char* loc_
pkg->has_update=false;
pkg->net_size = (int64_t) pkg->new_install_size - (int64_t) pkg->current_install_size;
}
ru->download_size = 0;
ru->new_install_size = 0;
ru->current_install_size = 0;
for(auto pkg : ru->packages)
{
// string lengths

View file

@ -6,7 +6,7 @@ void help()
{
printf("zupdate [option...] [package...]\n");
printf("Safely view package updates in a fancy list format.\n");
printf("Supported package managers: pacman, apt\n");
printf("Supported package managers: pacman, yay, apt\n");
printf("\n");
printf("Options:\n");
options.print_help(5,23);
@ -27,15 +27,15 @@ void create_options()
ztd::option('l', "list", false, "Print a detailed list of packages"),
ztd::option('L', "list-raw", false, "Print a raw list of packages"),
ztd::option('s', "size", false, "Print all sizes"),
ztd::option('d', "download-size", false, "Download size (no AUR)"),
ztd::option('i', "install-size", false, "Install size (no AUR)"),
ztd::option('n', "net-size", false, "Net difference size (no AUR)"),
ztd::option('d', "download-size", false, "Print download sizes (no AUR)"),
ztd::option('i', "install-size", false, "Print total install size"),
ztd::option('n', "net-size", false, "Print net difference sizes (no AUR)"),
ztd::option('I', "list-install", false, "Print individual install size in list"),
ztd::option('k', "no-titles", false, "Don't print titles on sizes"),
ztd::option('I', "list-install", false, "Print install size on list"),
ztd::option('C', "no-color", false, "Don't print colors"),
ztd::option("\r [OPERATION]"),
ztd::option('u', "update", false, "Update targeted repositories"),
ztd::option('y', "noconfirm", false, "Doesn't ask for confirmation"),
ztd::option('y', "noconfirm", false, "Don't ask for confirmation"),
ztd::option("\r [PKGMAN]"),
ztd::option( "pacman", false, "Force pacman as package manager"),
ztd::option( "apt", false, "Force apt as package manager"),

View file

@ -34,24 +34,24 @@ uint32_t req_pad_size(repo_update& ru)
return std::ceil(std::max(std::max(pd, pi), pn)) + (size_index>0?7:2);
}
void repo_print_process(repo_update& ru, ztd::color cl, bool print_size=true)
void repo_print_process(repo_update& ru, ztd::color cl, bool print_only_install=false, bool print_extra_separator=false)
{
//only if there are packages
if(ru.packages.size() > 0)
{
//list
if( opt_plist )
print_update(ru, cl, print_size && opt_pdownload, print_size && opt_pinstall, print_size && opt_pnet);
print_update(ru, cl, opt_pdownload, opt_pinstall, opt_pnet, print_only_install);
// raw list
uint32_t padsize=req_pad_size(ru);
if( opt_plist && print_size )
if( opt_plist )
print_separator(padsize+22, cl);
padsize -= size_index>0 ? 3 : 1;
//sizes
if( print_size )
print_update_sizes(ru, cl, opt_pdownload, opt_pinstall, opt_pnet, opt_notitles, padsize);
print_update_sizes(ru, cl, print_only_install ? false : opt_pdownload, opt_pinstall, print_only_install ? false : opt_pnet, opt_notitles, padsize - size_index>0 ? 3 : 1);
if(print_extra_separator)
print_separator(padsize+22, cl);
if(opt_plistraw)
print_listraw(ru);
}
@ -97,7 +97,7 @@ int pacman_process(const std::vector<std::string>& args, bool yay)
return r;
if(opt_aur && yay)
{
r = import_sizes(&aur, NULL, PACMAN_LOCAL_SIZE_COMMAND);
r = import_sizes(&aur, AUR_EXT_SIZE_COMMAND, PACMAN_LOCAL_SIZE_COMMAND);
}
if(r!=0)
return r;
@ -105,11 +105,11 @@ int pacman_process(const std::vector<std::string>& args, bool yay)
//process
if(opt_repo)
{
repo_print_process(repo, ztd::color::b_white);
repo_print_process(repo, ztd::color::b_white, false, opt_aur && yay && aur.packages.size()>0);
}
if(opt_aur && yay)
{
repo_print_process(aur, ztd::color::b_cyan, false);
repo_print_process(aur, ztd::color::b_cyan, true);
}

View file

@ -62,7 +62,7 @@ void print_separator(uint32_t length, ztd::color color, char sepchar)
std::cout << p_color(color) << sep << p_color(no_color) << std::endl;
}
void print_update(repo_update& ru, ztd::color color, bool dlsize, bool nisize, bool nusize)
void print_update(repo_update& ru, ztd::color color, bool dlsize, bool nisize, bool nusize, bool print_only_install)
{
if(ru.packages.size() > 0)
{
@ -106,15 +106,23 @@ void print_update(repo_update& ru, ztd::color color, bool dlsize, bool nisize, b
}
printf(" %*s %*s ", -1*(ru.name_max_length + 2), it.name.c_str(), -1*(ru.vcur_max_length + c_padsize) , v1.c_str());
if(it.has_update) // has update
printf("-> %*s |", -1*(ru.vnew_max_length + c_padsize) , v2.c_str());
printf("-> %*s | ", -1*(ru.vnew_max_length + c_padsize) , v2.c_str());
else // no update
printf("%*s |", ru.has_update?ru.vnew_max_length+3:0, "" );
if(opt_linstall)
printf("%*s | ", ru.has_update?ru.vnew_max_length+3:0, "" );
if(print_only_install)
{
if(opt_linstall && nisize)
print_size(it.current_install_size, true, "", 0, ztd::color::none, 2, size_index, " : ", (int) std::max(log10(ru.max_download_size) - 3*size_index + 0 , 0.0) + 5);
}
else
{
if(opt_linstall && nisize)
print_size(it.has_update?it.new_install_size:it.current_install_size, true, "", 0, ztd::color::none, 2, size_index, " : ", (int) std::max(log10(ru.max_download_size) - 3*size_index + 0 , 0.0) + 5);
if(it.has_update && dlsize)
print_size(it.download_size, true, "", 0, ztd::color::none, 2, size_index, " : ", (int) std::max(log10(ru.max_download_size) - 3*size_index + 0 , 0.0) + 5 );
if(it.has_update && nusize)
print_size(it.net_size, true, "", 0, ztd::color::none, 2, size_index, "", (int) std::max(log10(ru.max_net_size) - 3*size_index + 0 , 0.0) + 5 );
}
printf("\n");
}
}