+ Add package regex match
+ Add target all option * Restructure commands
This commit is contained in:
parent
4f9f1b0a3d
commit
52a35fe7d1
24 changed files with 366 additions and 226 deletions
6
Makefile
6
Makefile
|
|
@ -8,11 +8,12 @@ NAME = zupdate
|
|||
LDFLAGS = -lpthread
|
||||
|
||||
CC=g++
|
||||
CXXFLAGS= -I$(IDIR) -Wall -std=c++17 -fopenmp
|
||||
CXXFLAGS= -I$(IDIR) -Wall -std=c++17
|
||||
ifeq ($(DEBUG),true)
|
||||
CXXFLAGS += -g
|
||||
CC=clang++
|
||||
else
|
||||
CXXFLAGS += -O2
|
||||
CXXFLAGS += -O2 -fopenmp
|
||||
endif
|
||||
ifeq ($(STATIC),true)
|
||||
LDFLAGS += -l:libztd.a
|
||||
|
|
@ -28,6 +29,7 @@ DEPS = $(shell if [ -n "$(ld $(IDIR))" ] ; then ls $(IDIR)/*.hpp $(IDIR)/*.h 2>/
|
|||
# automatically finds .c and .cpp and makes the corresponding .o rule
|
||||
OBJ = $(shell ls $(SRCDIR)/*.cpp $(SRCDIR)/*.c 2>/dev/null | sed 's|\.cpp|.o|g;s|\.c|.o|g;s|$(SRCDIR)/|$(ODIR)/|g')
|
||||
|
||||
|
||||
$(ODIR)/%.o: $(SRCDIR)/%.c $(DEPS)
|
||||
$(CC) $(CXXFLAGS) -c -o $@ $<
|
||||
|
||||
|
|
|
|||
2
commands/apt_ext_size
Normal file
2
commands/apt_ext_size
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
#!/bin/sh
|
||||
apt-cache show --no-all-versions %s 2>/dev/null| grep -E '^Version:|^Installed-Size:|^Size:' | awk '{if(NR==2) tmp=$2*1024;else print $2}END{printf "%%u\\n", tmp}'
|
||||
|
|
@ -1,2 +1,3 @@
|
|||
sudo apt-get update >/dev/null || return $?
|
||||
apt list --upgradable 2>/dev/null | tail -n +2 | awk -F "/" '{print $1" "$2}' | tr -d ']' | awk '{print $1" "$7" -> "$3}'
|
||||
#!/bin/sh
|
||||
sudo apt-get update >/dev/null || exit $?
|
||||
apt list --upgradable 2>/dev/null | tail -n +2 | cut -d'/' -f1
|
||||
|
|
|
|||
3
commands/apt_fetch_all
Normal file
3
commands/apt_fetch_all
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
sudo apt-get update >/dev/null || exit $?
|
||||
dpkg-query -f '${binary:Package}\n' -W | cut -d ':' -f1
|
||||
2
commands/apt_local_size
Normal file
2
commands/apt_local_size
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
#!/bin/sh
|
||||
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}'
|
||||
2
commands/pacman_ext_size
Normal file
2
commands/pacman_ext_size
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
#!/bin/sh
|
||||
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'
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
CHECKUPDATES_DB="${TMPDIR:-/tmp}/checkup-db-${USER}/"
|
||||
#!/bin/sh
|
||||
CHECKUPDATES_DB="${TMPDIR:-/tmp}/checkup-db-$USER/"
|
||||
DBPath="$(pacman-conf DBPath)"
|
||||
mkdir -p "$CHECKUPDATES_DB"
|
||||
ln -sf "${DBPath}/local" "$CHECKUPDATES_DB" > /dev/null 2>&1
|
||||
fakeroot pacman -Sy --dbpath "$CHECKUPDATES_DB" --logfile /dev/null >/dev/null || return $?
|
||||
pacman -Qu --dbpath "$CHECKUPDATES_DB/" 2> /dev/null | grep -v '\[.*\]'
|
||||
exit 0
|
||||
ln -sf "$DBPath/local" "$CHECKUPDATES_DB" > /dev/null 2>&1
|
||||
fakeroot pacman -Sy --dbpath "$CHECKUPDATES_DB" --logfile /dev/null >/dev/null || exit $?
|
||||
pacman -Qu --dbpath "$CHECKUPDATES_DB/" 2> /dev/null | cut -d ' ' -f1 | grep -v '\[.*\]'
|
||||
|
|
|
|||
7
commands/pacman_fetch_all
Normal file
7
commands/pacman_fetch_all
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/sh
|
||||
CHECKUPDATES_DB="${TMPDIR:-/tmp}/checkup-db-$USER/"
|
||||
DBPath="$(pacman-conf DBPath)"
|
||||
mkdir -p "$CHECKUPDATES_DB"
|
||||
ln -sf "$DBPath/local" "$CHECKUPDATES_DB" > /dev/null 2>&1
|
||||
fakeroot pacman -Sy --dbpath "$CHECKUPDATES_DB" --logfile /dev/null >/dev/null || exit $?
|
||||
pacman -Qn --dbpath "$CHECKUPDATES_DB/" 2> /dev/null | cut -d ' ' -f1 | grep -v '\[.*\]'
|
||||
2
commands/pacman_local_size
Normal file
2
commands/pacman_local_size
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
#!/bin/sh
|
||||
pacman -Qi %s | grep -E '^Version|^Installed Size' | cut -d':' -f2- | tr -d ' ' | sed 's/ //g;1!s/iB$//g;1!s/B//g'
|
||||
18
generate_commands.sh
Executable file
18
generate_commands.sh
Executable file
|
|
@ -0,0 +1,18 @@
|
|||
#!/bin/sh
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
file=include/commands_gen.h
|
||||
|
||||
echo "#ifndef COMMANDS_GEN_H
|
||||
#define COMMANDS_GEN_H
|
||||
" > "$file"
|
||||
|
||||
for I in $(find commands -type f)
|
||||
do
|
||||
name=$(basename "$I" | tr '[:lower:]' '[:upper:]')_COMMAND
|
||||
printf '#define %s "%s"\n' "$name" "$(sed '/^#/d' "$I" | tocstr)" >> "$file"
|
||||
done
|
||||
|
||||
echo "
|
||||
#endif" >> "$file"
|
||||
|
|
@ -1,25 +1,22 @@
|
|||
#ifndef COMMANDS_H
|
||||
#define COMMANDS_H
|
||||
|
||||
#include "commands_gen.h"
|
||||
|
||||
// pacman
|
||||
#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 || return $?\npacman -Qu --dbpath \"$CHECKUPDATES_DB/\" 2> /dev/null | grep -v '\\[.*\\]'\nexit 0"
|
||||
#define AUR_FETCH_COMMAND "yay -Qau"
|
||||
#define AUR_FETCH_COMMAND "yay -Qau | cut -d' ' -f1"
|
||||
#define AUR_FETCH_ALL_COMMAND "yay -Qm | cut -d' ' -f1"
|
||||
|
||||
#define PACMAN_UPDATE_COMMAND "sudo pacman -Syu"
|
||||
#define PACMAN_UPDATE_COMMAND_NOCONFIRM "sudo pacman -Syu --noconfirm"
|
||||
#define AUR_UPDATE_COMMAND "yay -Sau"
|
||||
#define AUR_UPDATE_COMMAND_NOCONFIRM "yay -Sau --noconfirm"
|
||||
|
||||
#define PACMAN_EXT_SIZE_COMMAND "pacman -Si --dbpath \"${TMPDIR:-/tmp}/checkup-db-${USER}/\" --logfile /dev/null %s |grep -E 'Download Size|Installed Size'|cut -d':' -f2|tr -d ' '|cut -d'i' -f1 | tr -d 'B'|numfmt --from=iec"
|
||||
#define PACMAN_LOCAL_SIZE_COMMAND "pacman -Qi %s |grep 'Installed Size'|cut -d':' -f2|tr -d ' '|cut -d'i' -f1 | tr -d 'B'|numfmt --from=iec|tr -d '\n'"
|
||||
#define YAY_UPDATE_COMMAND "yay -Syu"
|
||||
#define YAY_UPDATE_COMMAND_NOCONFIRM "yay -Syu --noconfirm"
|
||||
|
||||
// apt/dpkg
|
||||
#define APT_FETCH_COMMAND "sudo apt-get update >/dev/null 2>&1 || return $?\napt list --upgradable 2>/dev/null | tail -n +2 | awk -F \"/\" '{print $1\" \"$2}' | tr -d ']' | awk '{print $1\" \"$7\" -> \"$3}'"
|
||||
#define APT_UPDATE_COMMAND "sudo apt-get update && sudo apt-get full-upgrade"
|
||||
#define APT_UPDATE_COMMAND_NOCONFIRM "sudo apt-get update && sudo apt-get -y full-upgrade"
|
||||
|
||||
#define APT_EXT_SIZE_COMMAND "apt-cache show --no-all-versions %s 2>/dev/null| grep -E '^Installed-Size:|^Size:' | awk 'NR==1 {print $2*1024} NR==2 {print $2}' | tac"
|
||||
#define APT_LOCAL_SIZE_COMMAND "dpkg -s %s 2>/dev/null| grep 'Installed-Size:' | cut -d' ' -f2 | awk '{print $1*1024}'"
|
||||
|
||||
|
||||
#endif //COMMANDS_H
|
||||
|
|
|
|||
13
include/commands_gen.h
Normal file
13
include/commands_gen.h
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#ifndef COMMANDS_GEN_H
|
||||
#define COMMANDS_GEN_H
|
||||
|
||||
#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 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"
|
||||
#define APT_FETCH_ALL_COMMAND "sudo apt-get update >/dev/null || exit $?\ndpkg-query -f '${binary:Package}\\n' -W | cut -d ':' -f1"
|
||||
#define APT_EXT_SIZE_COMMAND "apt-cache show --no-all-versions %s 2>/dev/null| grep -E '^Version:|^Installed-Size:|^Size:' | awk '{if(NR==2) tmp=$2*1024;else print $2}END{printf \"%%u\\\\n\", tmp}'"
|
||||
#define PACMAN_FETCH_ALL_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 -Qn --dbpath \"$CHECKUPDATES_DB/\" 2> /dev/null | cut -d ' ' -f1 | grep -v '\\[.*\\]'"
|
||||
|
||||
#endif
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
#include "repos.hpp"
|
||||
|
||||
//functions
|
||||
int fetch_update(repo_update* r, const std::string& name, const std::string& command);
|
||||
int fetch_update(repo_update* r, const std::string& name, const std::string& command, const std::vector<std::string>& args);
|
||||
|
||||
int import_sizes(repo_update* ru, const char* ext_size_command, const char* loc_size_command);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef OPT_BOOL_H
|
||||
#define OPT_BOOL_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// OPTIONS
|
||||
//help
|
||||
extern bool opt_help;
|
||||
|
|
@ -12,14 +14,16 @@ extern bool opt_pall;
|
|||
extern bool opt_notitles;
|
||||
extern bool opt_nocolor;
|
||||
extern bool opt_plist;
|
||||
extern bool opt_linstall;
|
||||
extern bool opt_plistraw;
|
||||
extern bool opt_psizes;
|
||||
extern bool opt_pdownload;
|
||||
extern bool opt_pinstall;
|
||||
extern bool opt_pnet;
|
||||
//size
|
||||
extern unsigned int size_index;
|
||||
extern uint8_t size_index;
|
||||
//operation
|
||||
extern bool opt_rall;
|
||||
extern bool opt_update;
|
||||
extern bool opt_noconfirm;
|
||||
//package man
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#define PACKAGE_MAN_HPP
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// types
|
||||
enum package_manager { none, pacman, apt, dnf };
|
||||
|
|
@ -12,8 +13,8 @@ extern package_manager cur_pkgman;
|
|||
// functions
|
||||
bool exec_find(const std::string& name);
|
||||
|
||||
int pacman_process(bool yay);
|
||||
int pacman_process(const std::vector<std::string>& args, bool yay);
|
||||
|
||||
int apt_process();
|
||||
int apt_process(const std::vector<std::string>& args);
|
||||
|
||||
#endif //PACKAGE_MAN_HPP
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
#include "colors.hpp"
|
||||
|
||||
//constants
|
||||
extern const char* size_suffixes[6];
|
||||
extern const char* size_suffixes[7];
|
||||
extern const int size_print_padding;
|
||||
|
||||
//tool
|
||||
|
|
@ -18,9 +18,9 @@ std::string strpf(std::string const& format, std::string const& var);
|
|||
//functions
|
||||
void help();
|
||||
|
||||
std::pair<double, const char*> convertN(const long int size, unsigned int n);
|
||||
std::pair<double, const char*> convertN(const int64_t size, uint32_t n);
|
||||
|
||||
std::pair<double, const char*> convertHReadable(const long int size);
|
||||
std::pair<double, const char*> convertHReadable(const int64_t size);
|
||||
|
||||
void print_separator(uint32_t length, ztd::color color, char sepchar='=');
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ void print_update(repo_update& ru, ztd::color color, bool dlsize=false, bool nis
|
|||
|
||||
void print_update_sizes(repo_update& ru, ztd::color color, bool dlsize, bool nisize, bool cisize, bool notitle, uint32_t padsize);
|
||||
|
||||
void print_size(long int size, bool printTitle=false, std::string title="", int padding=0, ztd::color color=ztd::color::none, unsigned int precision=2, unsigned int sizepow=2, const char* line_end="\n", int sizepad=-1);
|
||||
void print_size(int64_t size, bool printTitle=false, std::string title="", int padding=0, ztd::color color=ztd::color::none, uint32_t precision=2, uint32_t sizepow=2, const char* line_end="\n", int sizepad=-1);
|
||||
|
||||
void print_listraw(repo_update& ru);
|
||||
|
||||
|
|
|
|||
|
|
@ -11,27 +11,34 @@ typedef struct package_update
|
|||
std::string current_version;
|
||||
std::string new_version;
|
||||
|
||||
long unsigned int download_size;
|
||||
long unsigned int new_install_size;
|
||||
long unsigned int current_install_size;
|
||||
long int net_size;
|
||||
uint64_t download_size;
|
||||
uint64_t new_install_size;
|
||||
uint64_t current_install_size;
|
||||
int64_t net_size;
|
||||
|
||||
bool has_update;
|
||||
|
||||
} package_update;
|
||||
|
||||
typedef struct repo_update
|
||||
{
|
||||
std::vector<package_update> packages;
|
||||
std::string name;
|
||||
unsigned int name_max_length;
|
||||
unsigned int vcur_max_length;
|
||||
unsigned int vnew_max_length;
|
||||
uint32_t name_max_length;
|
||||
uint32_t vcur_max_length;
|
||||
uint32_t vnew_max_length;
|
||||
|
||||
long unsigned int download_size;
|
||||
long unsigned int new_install_size;
|
||||
long unsigned int current_install_size;
|
||||
long int net_size;
|
||||
uint64_t download_size;
|
||||
uint64_t new_install_size;
|
||||
uint64_t current_install_size;
|
||||
int64_t net_size;
|
||||
|
||||
long unsigned int max_download_size;
|
||||
long unsigned int max_net_size;
|
||||
uint64_t max_install_size;
|
||||
uint64_t max_download_size;
|
||||
uint64_t max_net_size;
|
||||
|
||||
uint64_t n_updates;
|
||||
bool has_update;
|
||||
|
||||
} repo_update;
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ std::pair<std::string, std::string> color_diff(std::string const& str1, std::str
|
|||
std::string r1, r2;
|
||||
{
|
||||
//CORE FUNCTION
|
||||
unsigned int i=0, j=0;
|
||||
uint32_t i=0, j=0;
|
||||
|
||||
while( i < str1.size() && i < str2.size() )
|
||||
{
|
||||
|
|
|
|||
161
src/fetch.cpp
161
src/fetch.cpp
|
|
@ -10,109 +10,146 @@
|
|||
#include "commands.h"
|
||||
#include "print.hpp"
|
||||
|
||||
#define KB_MULT 1024.0
|
||||
#define MB_MULT 1048576.0
|
||||
#define GB_MULT 1073741824.0
|
||||
#define TB_MULT 1099511627776.0
|
||||
#define PB_MULT 1125899906842624.0
|
||||
#define EB_MULT 1152921504606846976.0
|
||||
|
||||
uint64_t sizeconvert(std::string const& in)
|
||||
{
|
||||
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;
|
||||
default: return std::stoul(in);
|
||||
}
|
||||
}
|
||||
|
||||
package_update new_package()
|
||||
{
|
||||
package_update ret;
|
||||
ret.download_size = 0;
|
||||
ret.new_install_size = 0;
|
||||
ret.current_install_size = 0;
|
||||
ret.net_size = 0;
|
||||
ret.has_update = false;
|
||||
return ret;
|
||||
}
|
||||
|
||||
//functions
|
||||
int fetch_update(repo_update* r, const std::string& name, const std::string& command)
|
||||
int fetch_update(repo_update* r, const std::string& name, const std::string& command, std::vector<std::string> const& args)
|
||||
{
|
||||
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;
|
||||
std::pair<std::string, int> cp = ztd::shp(command);
|
||||
r->has_update=false;
|
||||
r->n_updates=0;
|
||||
|
||||
std::string sup;
|
||||
if(args.size()>0)
|
||||
{
|
||||
sup += "|grep -E '";
|
||||
for(auto it: args)
|
||||
{
|
||||
sup+="(^"+it+"$)|";
|
||||
}
|
||||
sup.pop_back();
|
||||
sup += '\'';
|
||||
}
|
||||
|
||||
std::pair<std::string, int> cp = ztd::shp(command+sup+"\nexit 0");
|
||||
if(cp.second != 0)
|
||||
return cp.second;
|
||||
std::string str=cp.first;
|
||||
|
||||
unsigned long int i=0,j=0;
|
||||
while(i<str.size())
|
||||
size_t i=0,j=0;
|
||||
while(j<str.size())
|
||||
{
|
||||
package_update pkg;
|
||||
//name
|
||||
while( str[i]!=' ' )
|
||||
i++;
|
||||
package_update pkg = new_package();
|
||||
i=str.find('\n',j);
|
||||
pkg.name = str.substr(j,i-j);
|
||||
if(pkg.name.size() > r->name_max_length)
|
||||
r->name_max_length = pkg.name.size();
|
||||
//end name
|
||||
i++;
|
||||
//current version
|
||||
j=i;
|
||||
while( str[i]!=' ' )
|
||||
i++;
|
||||
pkg.current_version = str.substr(j,i-j);
|
||||
if(pkg.current_version.size() > r->vcur_max_length)
|
||||
r->vcur_max_length = pkg.current_version.size();
|
||||
//end current version
|
||||
i++;
|
||||
//skip arrow
|
||||
while( str[i]!=' ' )
|
||||
i++;
|
||||
//end arrow
|
||||
i++;
|
||||
//new version
|
||||
j=i;
|
||||
while( str[i]!='\n' )
|
||||
i++;
|
||||
pkg.new_version = str.substr(j,i-j);
|
||||
if(pkg.new_version.size() > r->vnew_max_length)
|
||||
r->vnew_max_length = pkg.new_version.size();
|
||||
//end new version
|
||||
i++;
|
||||
j=i;
|
||||
j=i+1;
|
||||
r->packages.push_back(pkg);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void get_ext_sizes(package_update* pkg, const char* command)
|
||||
{
|
||||
std::string sizes=ztd::sh(strpf(command, pkg->name));
|
||||
unsigned int i=0, j=0;
|
||||
while(sizes[i]!='\n')
|
||||
i++;
|
||||
pkg->download_size = std::stoul(sizes.substr(0,i));
|
||||
i++;
|
||||
j=i;
|
||||
while(sizes[i]!='\n')
|
||||
i++;
|
||||
pkg->new_install_size = std::stoul(sizes.substr(j,i-j));
|
||||
std::string str=ztd::sh(strpf(command, pkg->name));
|
||||
uint32_t i=0, j=0;
|
||||
i=str.find('\n');
|
||||
pkg->new_version = str.substr(0,i);
|
||||
j=i+1;
|
||||
i=str.find('\n',j);
|
||||
pkg->download_size = sizeconvert(str.substr(j,i-j));
|
||||
j=i+1;
|
||||
i=str.find('\n',j);
|
||||
pkg->new_install_size = sizeconvert(str.substr(j,i-j));
|
||||
}
|
||||
void get_loc_size(package_update* pkg, const char* command)
|
||||
{
|
||||
std::string size=ztd::sh(strpf(command, pkg->name));
|
||||
if(size.size() > 0)
|
||||
pkg->current_install_size = std::stoul(size);
|
||||
else
|
||||
pkg->current_install_size = 0;
|
||||
std::string str=ztd::sh(strpf(command, pkg->name));
|
||||
uint32_t i=0, j=0;
|
||||
i=str.find('\n',i);
|
||||
pkg->current_version = str.substr(0,i);
|
||||
j=i+1;
|
||||
i=str.find('\n',j);
|
||||
pkg->current_install_size = sizeconvert(str.substr(j,i-j));
|
||||
}
|
||||
|
||||
int import_sizes(repo_update* ru, const char* ext_size_command, const char* loc_size_command)
|
||||
{
|
||||
const unsigned int n=ru->packages.size();
|
||||
const uint32_t n=ru->packages.size();
|
||||
#pragma omp parallel for
|
||||
for(unsigned int i=0; i<n; i++) //parallel
|
||||
for(uint32_t i=0; i<n; i++) //parallel
|
||||
{
|
||||
package_update* pkg = &(ru->packages[i]);
|
||||
get_ext_sizes(pkg, ext_size_command);
|
||||
get_loc_size(pkg, loc_size_command);
|
||||
pkg->net_size = (long int) pkg->new_install_size - (long int) pkg->current_install_size;
|
||||
if(ext_size_command!=NULL) get_ext_sizes(pkg, ext_size_command);
|
||||
if(loc_size_command!=NULL) get_loc_size(pkg, loc_size_command);
|
||||
if(pkg->current_version != "" && pkg->new_version != "" && pkg->new_version != pkg->current_version)
|
||||
{
|
||||
pkg->has_update=true;
|
||||
ru->has_update=true;
|
||||
}
|
||||
else
|
||||
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)
|
||||
{
|
||||
ru->max_download_size=std::max(ru->max_download_size, pkg.download_size);
|
||||
ru->max_net_size=std::max(ru->max_net_size, (long unsigned int) labs(pkg.net_size));
|
||||
// string lengths
|
||||
ru->name_max_length = std::max(ru->name_max_length, (uint32_t) pkg.name.size());
|
||||
ru->vnew_max_length = std::max(ru->vnew_max_length, (uint32_t) pkg.current_version.size());
|
||||
ru->vcur_max_length = std::max(ru->vcur_max_length, (uint32_t) pkg.new_version.size());
|
||||
|
||||
ru->download_size += pkg.download_size;
|
||||
ru->new_install_size += pkg.new_install_size;
|
||||
// biggest sizes
|
||||
ru->max_install_size = std::max(ru->max_install_size, pkg.has_update ? pkg.new_install_size : pkg.current_install_size);
|
||||
ru->max_download_size = std::max(ru->max_download_size, pkg.download_size);
|
||||
ru->max_net_size = std::max(ru->max_net_size, (uint64_t) labs(pkg.net_size));
|
||||
|
||||
// size sums
|
||||
if(pkg.has_update) ru->download_size += pkg.download_size;
|
||||
ru->new_install_size += pkg.has_update ? pkg.new_install_size : pkg.current_install_size;
|
||||
ru->current_install_size += pkg.current_install_size;
|
||||
|
||||
if(pkg.has_update) ru->n_updates++;
|
||||
}
|
||||
ru->net_size = (long int) ru->new_install_size - (long int) ru->current_install_size;
|
||||
ru->net_size = (int64_t) ru->new_install_size - (int64_t) ru->current_install_size;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,11 +7,12 @@
|
|||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
std::vector<std::string> args;
|
||||
//option process start
|
||||
try
|
||||
{
|
||||
create_options();
|
||||
process_options(argc, argv);
|
||||
args=options.process(argc, argv);
|
||||
options_bool();
|
||||
process_combines();
|
||||
}
|
||||
|
|
@ -74,9 +75,9 @@ int main(int argc, char* argv[])
|
|||
switch(cur_pkgman)
|
||||
{
|
||||
case pacman :
|
||||
return pacman_process(exec_find("yay")); break;
|
||||
return pacman_process(args, exec_find("yay")); break;
|
||||
case apt :
|
||||
return apt_process(); break;
|
||||
return apt_process(args); break;
|
||||
default :
|
||||
std::cerr << "Unsupported package manager\n";
|
||||
return 1;
|
||||
|
|
|
|||
|
|
@ -11,14 +11,16 @@ bool opt_pall=false;
|
|||
bool opt_notitles=false;
|
||||
bool opt_nocolor=false;
|
||||
bool opt_plist=false;
|
||||
bool opt_linstall=false;
|
||||
bool opt_plistraw=false;
|
||||
bool opt_psizes=false;
|
||||
bool opt_pdownload=false;
|
||||
bool opt_pinstall=false;
|
||||
bool opt_pnet=false;
|
||||
//size
|
||||
unsigned int size_index=2;
|
||||
uint8_t size_index=2;
|
||||
//operation
|
||||
bool opt_rall=false;
|
||||
bool opt_update=false;
|
||||
bool opt_noconfirm=false;
|
||||
//package man
|
||||
|
|
|
|||
109
src/options.cpp
109
src/options.cpp
|
|
@ -4,7 +4,11 @@ ztd::option_set options;
|
|||
|
||||
void help()
|
||||
{
|
||||
printf("zupdate [options]\n\nOptions:\n");
|
||||
printf("zupdate [option...] [package...]\n");
|
||||
printf("Safely view package updates in a fancy list format.\n");
|
||||
printf("Supported package managers: pacman, apt\n");
|
||||
printf("\n");
|
||||
printf("Options:\n");
|
||||
options.print_help(5,23);
|
||||
printf("\n");
|
||||
printf("Option order does not matter\n");
|
||||
|
|
@ -15,67 +19,68 @@ void help()
|
|||
|
||||
void create_options()
|
||||
{
|
||||
options.add(ztd::option("\r [HELP]"));
|
||||
options.add(ztd::option('h', "help", false, "Print this help message"));
|
||||
options.add(ztd::option("\r [PRINT]"));
|
||||
options.add(ztd::option('p', "print", false, "Print all update info"));
|
||||
options.add(ztd::option('l', "list", false, "Print a detailed list of packages"));
|
||||
options.add(ztd::option('L', "list-raw", false, "Print a raw list of packages"));
|
||||
options.add(ztd::option('s', "size", false, "Print all sizes"));
|
||||
options.add(ztd::option('d', "download-size", false, "Download size (repo only)"));
|
||||
options.add(ztd::option('i', "install-size", false, "Install size (repo only)"));
|
||||
options.add(ztd::option('n', "net-size", false, "Net difference size (repo only)"));
|
||||
options.add(ztd::option('k', "no-titles", false, "Don't print titles on -d -i and -n"));
|
||||
options.add(ztd::option('C', "no-color", false, "Don't print colors"));
|
||||
options.add(ztd::option("\r [OPERATION]"));
|
||||
options.add(ztd::option('u', "update", false, "Update targeted repositories"));
|
||||
options.add(ztd::option('y', "noconfirm", false, "Doesn't ask for confirmation"));
|
||||
options.add(ztd::option("\r [PKGMAN]"));
|
||||
options.add(ztd::option( "pacman", false, "Force pacman as package manager"));
|
||||
options.add(ztd::option( "apt", false, "Force apt as package manager"));
|
||||
options.add(ztd::option("\r [TARGET]"));
|
||||
options.add(ztd::option('r', "repo", false, "Target official repository (pacman only)"));
|
||||
options.add(ztd::option('a', "aur", false, "Target AUR (pacman only, yay required)"));
|
||||
options.add(ztd::option("\r [SIZE]"));
|
||||
options.add(ztd::option('B', "byte", false, "Print sizes in bytes"));
|
||||
options.add(ztd::option('K', "kilobyte", false, "Print sizes in kilobytes"));
|
||||
options.add(ztd::option('M', "megabyte", false, "Print sizes in megabytes"));
|
||||
options.add(ztd::option('G', "gigabyte", false, "Print sizes in gigabytes"));
|
||||
}
|
||||
|
||||
void process_options(int argc, char** argv)
|
||||
{
|
||||
options.process(argc, argv);
|
||||
options.add(
|
||||
ztd::option("\r [HELP]"),
|
||||
ztd::option('h', "help", false, "Print this help message"),
|
||||
ztd::option("\r [PRINT]"),
|
||||
ztd::option('p', "print", false, "Print all update info"),
|
||||
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('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("\r [PKGMAN]"),
|
||||
ztd::option( "pacman", false, "Force pacman as package manager"),
|
||||
ztd::option( "apt", false, "Force apt as package manager"),
|
||||
ztd::option("\r [TARGET]"),
|
||||
ztd::option('A', "all", false, "Target all packages instead of just updated ones"),
|
||||
ztd::option('r', "repo", false, "Target official repository (pacman only)"),
|
||||
ztd::option('a', "aur", false, "Target AUR (pacman only, yay required)"),
|
||||
ztd::option("\r [SIZE]"),
|
||||
ztd::option('B', "byte", false, "Print sizes in bytes"),
|
||||
ztd::option('K', "kilobyte", false, "Print sizes in kilobytes"),
|
||||
ztd::option('M', "megabyte", false, "Print sizes in megabytes"),
|
||||
ztd::option('G', "gigabyte", false, "Print sizes in gigabytes")
|
||||
);
|
||||
}
|
||||
|
||||
void options_bool()
|
||||
{
|
||||
//help
|
||||
opt_help = options.find('h')->activated;
|
||||
opt_help = options['h'];
|
||||
//targets
|
||||
opt_repo = options.find('r')->activated;
|
||||
opt_aur = options.find('a')->activated;
|
||||
opt_repo = options['r'];
|
||||
opt_aur = options['a'];
|
||||
//print
|
||||
opt_pall = options.find('p')->activated;
|
||||
opt_notitles = options.find('k')->activated;
|
||||
opt_nocolor = options.find('C')->activated;
|
||||
opt_plist = options.find('l')->activated;
|
||||
opt_plistraw = options.find('L')->activated;
|
||||
opt_psizes = options.find('s')->activated;
|
||||
opt_pdownload = options.find('d')->activated;
|
||||
opt_pinstall = options.find('i')->activated;
|
||||
opt_pnet = options.find('n')->activated;
|
||||
opt_pall = options['p'];
|
||||
opt_notitles = options['k'];
|
||||
opt_nocolor = options['C'];
|
||||
opt_plist = options['l'];
|
||||
opt_plistraw = options['L'];
|
||||
opt_psizes = options['s'];
|
||||
opt_pdownload = options['d'];
|
||||
opt_pinstall = options['i'];
|
||||
opt_pnet = options['n'];
|
||||
opt_linstall = options['I'];
|
||||
//size
|
||||
if(options.find('B')->activated) size_index = 0;
|
||||
if(options.find('K')->activated) size_index = 1;
|
||||
if(options.find('M')->activated) size_index = 2;
|
||||
if(options.find('G')->activated) size_index = 3;
|
||||
if(options['B']) size_index = 0;
|
||||
if(options['K']) size_index = 1;
|
||||
if(options['M']) size_index = 2;
|
||||
if(options['G']) size_index = 3;
|
||||
//operation
|
||||
opt_update = options.find('u')->activated;
|
||||
opt_noconfirm = options.find('y')->activated;
|
||||
opt_rall = options['A'];
|
||||
opt_update = options['u'];
|
||||
opt_noconfirm = options['y'];
|
||||
//packageman
|
||||
opt_pacman = options.find("pacman")->activated;
|
||||
opt_apt = options.find("apt")->activated;
|
||||
opt_pacman = options["pacman"];
|
||||
opt_apt = options["apt"];
|
||||
}
|
||||
|
||||
void process_combines()
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
|
||||
#include <ztd/shell.hpp>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
package_manager cur_pkgman = none;
|
||||
|
||||
bool exec_find(const std::string& name)
|
||||
|
|
@ -35,11 +37,7 @@ uint32_t req_pad_size(repo_update& ru)
|
|||
void repo_print_process(repo_update& ru, ztd::color cl, bool print_size=true)
|
||||
{
|
||||
//only if there are packages
|
||||
if(opt_plistraw)
|
||||
{
|
||||
print_listraw(ru);
|
||||
}
|
||||
else if(ru.packages.size() > 0)
|
||||
if(ru.packages.size() > 0)
|
||||
{
|
||||
//list
|
||||
if( opt_plist )
|
||||
|
|
@ -54,10 +52,12 @@ void repo_print_process(repo_update& ru, ztd::color cl, bool print_size=true)
|
|||
//sizes
|
||||
if( print_size )
|
||||
print_update_sizes(ru, cl, opt_pdownload, opt_pinstall, opt_pnet, opt_notitles, padsize);
|
||||
if(opt_plistraw)
|
||||
print_listraw(ru);
|
||||
}
|
||||
}
|
||||
|
||||
int pacman_process(bool yay)
|
||||
int pacman_process(const std::vector<std::string>& args, bool yay)
|
||||
{
|
||||
int r=0, r2=0;
|
||||
|
||||
|
|
@ -74,12 +74,12 @@ int pacman_process(bool yay)
|
|||
#pragma omp section
|
||||
{
|
||||
if(opt_repo)
|
||||
r = fetch_update(&repo, "REPO", PACMAN_FETCH_COMMAND);
|
||||
r = fetch_update(&repo, "REPO", opt_rall ? PACMAN_FETCH_ALL_COMMAND : PACMAN_FETCH_COMMAND, args);
|
||||
}
|
||||
#pragma omp section
|
||||
{
|
||||
if(opt_aur && yay)
|
||||
r2 = fetch_update(&aur, "AUR", AUR_FETCH_COMMAND);
|
||||
r2 = fetch_update(&aur, "AUR", opt_rall ? AUR_FETCH_ALL_COMMAND : AUR_FETCH_COMMAND, args);
|
||||
}
|
||||
}
|
||||
if(r!=0)
|
||||
|
|
@ -88,48 +88,57 @@ int pacman_process(bool yay)
|
|||
return r2;
|
||||
}
|
||||
|
||||
//process
|
||||
if(opt_repo)
|
||||
{
|
||||
// size fetch
|
||||
if( combine_size )
|
||||
if(opt_repo)
|
||||
{
|
||||
r = import_sizes(&repo, PACMAN_EXT_SIZE_COMMAND, PACMAN_LOCAL_SIZE_COMMAND);
|
||||
}
|
||||
if(r!=0)
|
||||
return r;
|
||||
|
||||
repo_print_process(repo, ztd::color::b_white);
|
||||
|
||||
if(opt_update)
|
||||
if(opt_aur && yay)
|
||||
{
|
||||
signal(SIGINT, SIG_IGN);
|
||||
if(opt_noconfirm)
|
||||
r = ztd::shr(PACMAN_UPDATE_COMMAND_NOCONFIRM);
|
||||
else
|
||||
r = ztd::shr(PACMAN_UPDATE_COMMAND);
|
||||
|
||||
r = import_sizes(&aur, NULL, PACMAN_LOCAL_SIZE_COMMAND);
|
||||
}
|
||||
if(r!=0)
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
//process
|
||||
if(opt_repo)
|
||||
{
|
||||
repo_print_process(repo, ztd::color::b_white);
|
||||
}
|
||||
if(opt_aur && yay)
|
||||
{
|
||||
repo_print_process(aur, ztd::color::b_cyan, false);
|
||||
}
|
||||
|
||||
|
||||
if(opt_update)
|
||||
{
|
||||
signal(SIGINT, SIG_IGN);
|
||||
const char* update_command=NULL;
|
||||
if(opt_aur && yay && opt_repo)
|
||||
{
|
||||
if(opt_noconfirm)
|
||||
r = ztd::shr(AUR_UPDATE_COMMAND_NOCONFIRM);
|
||||
update_command=YAY_UPDATE_COMMAND_NOCONFIRM;
|
||||
else
|
||||
r = ztd::shr(AUR_UPDATE_COMMAND);
|
||||
|
||||
if(r!=0)
|
||||
return r;
|
||||
update_command=YAY_UPDATE_COMMAND;
|
||||
}
|
||||
else if(opt_aur && yay)
|
||||
{
|
||||
if(opt_noconfirm)
|
||||
update_command=AUR_UPDATE_COMMAND_NOCONFIRM;
|
||||
else
|
||||
update_command=AUR_UPDATE_COMMAND;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(opt_noconfirm)
|
||||
update_command=PACMAN_UPDATE_COMMAND_NOCONFIRM;
|
||||
else
|
||||
update_command=PACMAN_UPDATE_COMMAND;
|
||||
}
|
||||
execl("/bin/sh", "/bin/sh", "-c", update_command, NULL);
|
||||
return errno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -148,7 +157,7 @@ std::string apt_getrepo()
|
|||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
int apt_process()
|
||||
int apt_process(const std::vector<std::string>& args)
|
||||
{
|
||||
int r=0;
|
||||
|
||||
|
|
@ -175,7 +184,7 @@ int apt_process()
|
|||
|
||||
if( combine_fetch )
|
||||
{
|
||||
r = fetch_update(&repo, apt_getrepo(), APT_FETCH_COMMAND);
|
||||
r = fetch_update(&repo, apt_getrepo(), opt_rall ? APT_FETCH_ALL_COMMAND : APT_FETCH_COMMAND, args);
|
||||
}
|
||||
if(r!=0)
|
||||
return r;
|
||||
|
|
@ -191,14 +200,11 @@ int apt_process()
|
|||
|
||||
if(opt_update)
|
||||
{
|
||||
signal(SIGINT, SIG_IGN);
|
||||
if(opt_noconfirm)
|
||||
r = ztd::shr(APT_UPDATE_COMMAND_NOCONFIRM);
|
||||
execl("/bin/sh", "/bin/sh", "-c", APT_UPDATE_COMMAND_NOCONFIRM, NULL);
|
||||
else
|
||||
r = ztd::shr(APT_UPDATE_COMMAND);
|
||||
|
||||
if(r!=0)
|
||||
return r;
|
||||
execl("/bin/sh", "/bin/sh", "-c", APT_UPDATE_COMMAND, NULL);
|
||||
return errno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
#include "opt_bool.h"
|
||||
|
||||
//constants
|
||||
const char* size_suffixes[6] = { "B", "KiB", "MiB", "GiB", "TiB", "PiB"};
|
||||
const char* size_suffixes[7] = { "B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"};
|
||||
const int size_print_padding=-21;
|
||||
|
||||
//tool
|
||||
|
|
@ -24,21 +24,21 @@ std::string strpf(std::string const& format, std::string const& var)
|
|||
}
|
||||
|
||||
//functions
|
||||
std::pair<double, const char*> convertN(const long int size, unsigned int n)
|
||||
std::pair<double, const char*> convertN(const int64_t size, uint32_t n)
|
||||
{
|
||||
double ret = size;
|
||||
for(unsigned int i=0; i<n; i++)
|
||||
for(uint32_t i=0; i<n; i++)
|
||||
{
|
||||
ret /= 1024;
|
||||
}
|
||||
return std::make_pair( ret , size_suffixes[n] );
|
||||
}
|
||||
|
||||
std::pair<double, const char*> convertHReadable(const long int size)
|
||||
std::pair<double, const char*> convertHReadable(const int64_t size)
|
||||
{
|
||||
double ret = size;
|
||||
unsigned char pow1k=0;
|
||||
while(abs(ret) >= 1024.0)
|
||||
uint8_t pow1k=0;
|
||||
while(std::abs(ret) >= 1024.0)
|
||||
{
|
||||
ret /= 1024;
|
||||
pow1k++;
|
||||
|
|
@ -66,11 +66,21 @@ void print_update(repo_update& ru, ztd::color color, bool dlsize, bool nisize, b
|
|||
{
|
||||
if(ru.packages.size() > 0)
|
||||
{
|
||||
printf("%s[%s] %lu updates%s\n", p_color(color), ru.name.c_str(), ru.packages.size(), p_color(no_color) );
|
||||
printf("%s[%s] ", p_color(color), ru.name.c_str());
|
||||
bool print_pkgcount = (ru.n_updates != ru.packages.size());
|
||||
if(print_pkgcount)
|
||||
printf("%lu package%s", ru.packages.size(), ru.packages.size()>1?"s":"");
|
||||
if(print_pkgcount && ru.has_update)
|
||||
printf(" : ");
|
||||
if(ru.has_update)
|
||||
printf("%lu update%s", ru.n_updates, ru.n_updates>1?"s":"");
|
||||
printf("%s\n", p_color(no_color));
|
||||
int c_padsize = (opt_nocolor ? 0 : 20);
|
||||
for(auto it : ru.packages)
|
||||
{
|
||||
std::string v1;
|
||||
std::string v2;
|
||||
std::string v1,v2;
|
||||
if(it.has_update)
|
||||
{
|
||||
if(!opt_nocolor)
|
||||
{
|
||||
auto pv = color_diff(it.current_version, it.new_version);
|
||||
|
|
@ -82,11 +92,28 @@ void print_update(repo_update& ru, ztd::color color, bool dlsize, bool nisize, b
|
|||
v1 = it.current_version;
|
||||
v2 = it.new_version;
|
||||
}
|
||||
int c_padsize = (opt_nocolor ? 0 : 20) ;
|
||||
printf(" %*s %*s -> %*s | ", -1*(ru.name_max_length + 2), it.name.c_str(), -1*(ru.vcur_max_length + c_padsize) , v1.c_str(), -1*(ru.vnew_max_length + c_padsize) , v2.c_str());
|
||||
if(dlsize)
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!opt_nocolor)
|
||||
v1 += ztd::color(ztd::color::b_white).code();
|
||||
v1 += it.current_version;
|
||||
if(!opt_nocolor)
|
||||
{
|
||||
v1 += ztd::color(ztd::color::b_red).code();
|
||||
v1 += ztd::color(ztd::color::none).code();
|
||||
}
|
||||
}
|
||||
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());
|
||||
else // no update
|
||||
printf("%*s |", ru.has_update?ru.vnew_max_length+3:0, "" );
|
||||
if(opt_linstall)
|
||||
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(nusize)
|
||||
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");
|
||||
}
|
||||
|
|
@ -95,7 +122,6 @@ void print_update(repo_update& ru, ztd::color color, bool dlsize, bool nisize, b
|
|||
|
||||
void print_update_sizes(repo_update& ru, ztd::color color, bool dlsize, bool nisize, bool nusize, bool notitle, uint32_t padsize)
|
||||
{
|
||||
bool separator = !notitle && (dlsize || nisize || nusize) ;
|
||||
if(dlsize)
|
||||
print_size(ru.download_size, !notitle, "Total Download Size:", size_print_padding, color, 2, size_index, "\n", padsize);
|
||||
if(nisize)
|
||||
|
|
@ -104,7 +130,7 @@ void print_update_sizes(repo_update& ru, ztd::color color, bool dlsize, bool nis
|
|||
print_size(ru.net_size, !notitle, "Net Upgrade Size:", size_print_padding, color, 2, size_index, "\n", padsize);
|
||||
}
|
||||
|
||||
void print_size(long int size, bool printTitle, std::string title, int padding, ztd::color color, unsigned int precision, unsigned int sizepow, const char* line_end, int sizepad)
|
||||
void print_size(int64_t size, bool printTitle, std::string title, int padding, ztd::color color, uint32_t precision, uint32_t sizepow, const char* line_end, int sizepad)
|
||||
{
|
||||
auto tpair = convertN(size, sizepow);
|
||||
if( printTitle )
|
||||
|
|
@ -116,7 +142,6 @@ void print_size(long int size, bool printTitle, std::string title, int padding,
|
|||
if(sizepow == 0)
|
||||
{
|
||||
precision = 0;
|
||||
// sizepad = 9;
|
||||
}
|
||||
if(!printTitle)
|
||||
{
|
||||
|
|
@ -129,6 +154,9 @@ void print_listraw(repo_update& ru)
|
|||
{
|
||||
for(auto it : ru.packages)
|
||||
{
|
||||
printf("%s %s -> %s\n", it.name.c_str(), it.current_version.c_str(), it.new_version.c_str());
|
||||
printf("%s %s", it.name.c_str(), it.current_version.c_str());
|
||||
if(it.has_update)
|
||||
printf(" -> %s", it.new_version.c_str());
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue