Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Simple selective within date range re-emerge exercise? [fix]
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
CaptainBlood
Advocate
Advocate


Joined: 24 Jan 2010
Posts: 3628

PostPosted: Mon Apr 01, 2024 10:46 pm    Post subject: Simple selective within date range re-emerge exercise? [fix] Reply with quote

Assuming there is a list of installed packages in the form CAT/PN:SLOT:REPO

How to rebuild only packages which have been installed prior to a specific (HH:MM:SS DD/MM/YYYY)?

I guess I can manage it, but it would be tedious and lasting process.

Anyone with a ready made solution to this?

Thks 4 ur attention, interest & support.
_________________
USE="-* ..." in /etc/portage/make.conf here.
LT: "I've been doing a passable imitation of the Fontana di Trevi, except my medium is mucus. Sooo much mucus. "


Last edited by CaptainBlood on Tue Apr 02, 2024 12:49 pm; edited 2 times in total
Back to top
View user's profile Send private message
Ralphred
Guru
Guru


Joined: 31 Dec 2013
Posts: 501

PostPosted: Tue Apr 02, 2024 2:37 am    Post subject: Reply with quote

I think it's easier than you've made it sound; all the info you need is in /var/db/pkg. So
Code:
#!/bin/bash

input_file="/path/to/list"
output_file="/path/to/filtered_list"
time_point=1707385898

function check() {
    when=$(cat /var/db/pkg/$1/$2-[0-9]*/BUILD_TIME)
    slot=$(cat /var/db/pkg/$1/$2-[0-9]*/SLOT)
    repo=$(cat /var/db/pkg/$1/$2-[0-9]*/repository)

    [[ $when -lt $timepoint ]] && echo "$1/$2:$3:$4" >> $output_file && continue
    [[ $3 != $slot ]] && echo "$1/$2:$3:$4" >> $output_file && continue
    [[ $4 != $repo ]] && echo "$1/$2:$3:$4" >> $output_file && continue
}

while read atom;do
    check(echo $atom|sed 's/\// /;s/:/ /g')
done < $input_file

This is totally on the fly and untested, just a PoC, so don't expect it to actually work, also 'continue' may need to be 'return', and you may want to invoke `date` to set $time_point.
Back to top
View user's profile Send private message
logrusx
Veteran
Veteran


Joined: 22 Feb 2018
Posts: 1550

PostPosted: Tue Apr 02, 2024 5:00 am    Post subject: Reply with quote

Try to improvise on this: https://forums.gentoo.org/viewtopic-p-8821469.html#8821469

Best Regards,
Georgi
Back to top
View user's profile Send private message
Goverp
Advocate
Advocate


Joined: 07 Mar 2007
Posts: 2011

PostPosted: Tue Apr 02, 2024 8:19 am    Post subject: Reply with quote

I suspect you could do something with "qlop -d" and "sort -u" - indeed I think I have done so at some point in the past. But Ralphred's may be easier! (I haven't tried it, but I know there'a a lot you can do with /var/db/pkg.)
_________________
Greybeard
Back to top
View user's profile Send private message
CaptainBlood
Advocate
Advocate


Joined: 24 Jan 2010
Posts: 3628

PostPosted: Tue Apr 02, 2024 12:37 pm    Post subject: Reply with quote

Thks 2 all of you.

Came with
Code:
equery d app-arch/xz-utils|grep "/"|while read line;do qlist -v -I $line;done|while read line;do if [[ -n $(qlop -q $line --date $(qlop virtual/libintl|tail -1|awk '{ print $1 }') --date $(qlop app-arch/xz-utils|tail -1|awk '{ print $1 }')) ]];then echo =$line;fi;done|xargs emerge -1 -p


As you may bisect, issue rose because of a concurrent emergency app-arch/xz-utils downgrade while processing profile migration.
Hence requrement to rebuikf of prior to downgrade already migrated app-arch/xz-utils dependent packages.

The first --date package stands for the beginning of the profile migration
The last --date package stands for the app-arch/xz-utils downgrading emerge.

Maybe can be simplified...

EDIT:
Code:
equery d xz-utils|grep "/"|while read line;do if [[ -n $(qlop -q $line --date $(qlop virtual/libintl|tail -1|awk '{ print $1 }') --date $(qlop xz-utils|tail -1|awk '{ print $1 }')) ]];then echo =$line;fi;done|xargs emerge -1 -p


Thks 4 ur attention, interest & support.
_________________
USE="-* ..." in /etc/portage/make.conf here.
LT: "I've been doing a passable imitation of the Fontana di Trevi, except my medium is mucus. Sooo much mucus. "


Last edited by CaptainBlood on Tue Apr 02, 2024 1:15 pm; edited 3 times in total
Back to top
View user's profile Send private message
bstaletic
Apprentice
Apprentice


Joined: 05 Apr 2014
Posts: 253

PostPosted: Tue Apr 02, 2024 12:49 pm    Post subject: Reply with quote

Not tested but something like this

Code:

import portage
import datetime
import subprocess

installed_db = portage.db[portage.root]['vartree'].dbapi
date_time_cutoff = '22:00:00 05/05/2023'
list_of_atoms = [ ... ]

datetime_point = datetime.datetime.strptime(date_time_cutoff, '%H:%M:%S %d/%m/%Y)
epoch_cutoff = datetime_point.timestamp()

atoms = []
for input_atom in list_of_atoms:
        atoms.extend(installed_db.match(input_atom)
filtered_atoms = list(filter(lambda atom: int(installed_db.aux_get(atom, ['BUILD_TIME'])) < epoch_cutoff, atoms))
       
result = subprocess.run(f'emerge -av1 {" ".join(filtered_atoms)}')


Maybe you don't need the installed_db.match shenanigans.
Maybe you care about sub-second timstamps.
Maybe...
Anyway, not tested, use at your own risk.

EDIT: Was too late, I guess.
Back to top
View user's profile Send private message
CaptainBlood
Advocate
Advocate


Joined: 24 Jan 2010
Posts: 3628

PostPosted: Tue Apr 02, 2024 1:18 pm    Post subject: Reply with quote

bstaletic wrote:
Was too late, I guess.
Never, confront and learn always rule.

Thks 4 ur attention, interest & support.
_________________
USE="-* ..." in /etc/portage/make.conf here.
LT: "I've been doing a passable imitation of the Fontana di Trevi, except my medium is mucus. Sooo much mucus. "
Back to top
View user's profile Send private message
bstaletic
Apprentice
Apprentice


Joined: 05 Apr 2014
Posts: 253

PostPosted: Tue Apr 02, 2024 1:51 pm    Post subject: Reply with quote

Now that I know what you were trying to achieve, here's a cleaner python implementation:

Code:
import portage
import subprocess

installed_db = portage.db[portage.root]['vartree'].dbapi
start = int(installed_db.aux_get(installed_db.match('libintl')[0], ['BUILD_TIME'])[0])
end = int(installed_db.aux_get(installed_db.match('xz-utils')[0], ['BUILD_TIME'])[0])
all_deps = list(filter(lambda atom: 'xz-utils' in any(['xz-utils' in d for d in installed_db.aux_get(atom, ['RDEPEND', 'DEPEND'])) and start < installed_db.aux_get(atom, ['BUILD_TIME'])[0] < end, installed_db.cpv_all()))
subprocess.run(['emerge', '-av1'] + all_deps)


This one spawns fewer subprocesses than the bash version.
I'll admit, I had fun writing this. I know it's not the most readable thing in the world!
Back to top
View user's profile Send private message
CaptainBlood
Advocate
Advocate


Joined: 24 Jan 2010
Posts: 3628

PostPosted: Tue Apr 02, 2024 2:26 pm    Post subject: Reply with quote

@bstaletic,

Initially I expected it to be more difficult. :roll:
Was then blaming myself being python illiterate, as it might be a easy way to achieve. :cry:

Now forced 2 learn a bit. :idea:

Thks 4 ur attention, interest & support.
_________________
USE="-* ..." in /etc/portage/make.conf here.
LT: "I've been doing a passable imitation of the Fontana di Trevi, except my medium is mucus. Sooo much mucus. "
Back to top
View user's profile Send private message
CaptainBlood
Advocate
Advocate


Joined: 24 Jan 2010
Posts: 3628

PostPosted: Wed Apr 03, 2024 10:53 pm    Post subject: Reply with quote

bstaletic wrote:
Now that I know what you were trying to achieve, here's a cleaner python implementation:

Code:
import portage
import subprocess

installed_db = portage.db[portage.root]['vartree'].dbapi
start = int(installed_db.aux_get(installed_db.match('libintl')[0], ['BUILD_TIME'])[0])
end = int(installed_db.aux_get(installed_db.match('xz-utils')[0], ['BUILD_TIME'])[0])
all_deps = list(filter(lambda atom: 'xz-utils' in any(['xz-utils' in d for d in installed_db.aux_get(atom, ['RDEPEND', 'DEPEND'])) and start < installed_db.aux_get(atom, ['BUILD_TIME'])[0] < end, installed_db.cpv_all()))
subprocess.run(['emerge', '-av1'] + all_deps)


This one spawns fewer subprocesses than the bash version.
I'll admit, I had fun writing this. I know it's not the most readable thing in the world!
Code:
amd64 ~ # python ./xz-utils.py
  File "/root/./xz-utils.py", line 7
    all_deps = list(filter(lambda atom: 'xz-utils' in any(['xz-utils' in d for d in installed_db.aux_get(atom, ['RDEPEND', 'DEPEND'])) and start < installed_db.aux_get(atom, ['BUILD_TIME'])[0] < end, installed_db.cpv_all()))
                                                                                                                                     ^
SyntaxError: closing parenthesis ')' does not match opening parenthesis '['
Any clue?

Thks 4 ur attention, interest & support.
_________________
USE="-* ..." in /etc/portage/make.conf here.
LT: "I've been doing a passable imitation of the Fontana di Trevi, except my medium is mucus. Sooo much mucus. "
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21650

PostPosted: Wed Apr 03, 2024 11:26 pm    Post subject: Reply with quote

The posted code fragment has a syntax error due to unbalanced delimiters. It looks to me like the list comprehension passed to any should have been closed immediately before the close of any, but was not. Python's error seems to agree with me. Add a close bracket just before the close parenthesis of any.
Back to top
View user's profile Send private message
CaptainBlood
Advocate
Advocate


Joined: 24 Jan 2010
Posts: 3628

PostPosted: Thu Apr 04, 2024 12:21 am    Post subject: Reply with quote

CaptainBlood wrote:
EDIT:
Code:
equery d xz-utils|grep "/"|while read line;do if [[ -n $(qlop -q $line --date $(qlop virtual/libintl|tail -1|awk '{ print $1 }') --date $(qlop xz-utils|tail -1|awk '{ print $1 }')) ]];then echo =$line;fi;done|xargs emerge -1 -p


With profile migration achieved, let's check if any installed package escaped the process.

Code:
qlist -I -v|while read line;do if [[ -z $(qlop -q $line --date $(qlop virtual/libintl|tail -1|awk '{ print $1 }') --date $(qlop dev-db/pgadmin4|tail -1|awk '{ print $1 }')) ]];then echo =$line;fi;done|xargs emerge -1 -p


where the first --date package is the first emerged by the migration.
where the last --date package is the last emerged by the migration.

Because I rsynced meanwhile, some packages are causing issues, e.g. masked.
In this respect final
Code:
xargs echo
eases things.

Thks 4 ur attention, interest & support.
_________________
USE="-* ..." in /etc/portage/make.conf here.
LT: "I've been doing a passable imitation of the Fontana di Trevi, except my medium is mucus. Sooo much mucus. "
Back to top
View user's profile Send private message
bstaletic
Apprentice
Apprentice


Joined: 05 Apr 2014
Posts: 253

PostPosted: Fri Apr 05, 2024 4:28 pm    Post subject: Reply with quote

CaptainBlood wrote:
Any clue?


Late reply again, but @Hu has correctly addressed my typo.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum