New inxi / pinxi features: user RAM reports! And much more! Testers?
SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
This will take a bit, it's one of those cases where old syntax has to keep working and new also, which is a tricky but not super hard puzzle.
Should be running later today.
Code:
my $slpkg = '/etc/slpkg/repositories.toml';
open my $fh, '<', $slpkg or die "Could not open '$slpkg': $!";
my @enabled_repos;
my $current_repo;
my $repo_enabled = 0;
my $section_name;
while (my $line = <$fh>) {
# Ignore comment and empty lines ;)
next if $line =~ /^\s*#/ || $line =~ /^\s*$/;
if ($line =~ /^\[(.+)\]$/) {
if ($repo_enabled && defined $current_repo) {
push @enabled_repos, $current_repo;
print "Adding enabled repo: $current_repo in section $section_name\n";
}
$section_name = $1;
$repo_enabled = 0;
$current_repo = undef;
}
if ($line =~ /ENABLE\s*=\s*true/) {
$repo_enabled = 1;
print "'$section_name' is enabled\n";
}
if ($line =~ /^REPO\s*=\s*"([^"]+)"/) {
$current_repo = $1;
print "$section_name repo: $current_repo\n";
}
}
if ($repo_enabled && defined $current_repo) {
push @enabled_repos, $current_repo;
print "Adding enabled last section repo: $current_repo\n";
}
close $fh;
Just trying to safe some of your time... Something like this is working and skip # or empty lines.... But ofcource you know better
Ideally this will handle the old syntax as well as the new.
I'll do that by adding a switch to detect the new, then do things based on that switch.
Trying to create data objects out of stacked lines when looping through them is always tricky, but a lot of the repos do that style, but this one will have to be slightly more clever to do both transparently.
Luckily this is very easy to test using fake repo data files, for old and new.
I'm a little behind, so this will probably be working tomorrow.
Most of the logic was in place, it just has to be fine tuned, and also, I'd like to add in the (default) to the repo that is default since that's useful information.
It just takes a little patience to do it with this type of slightly complicated data that can be one of two things.
This required using hashes, which in perl don't retain the creation order, so I can't make the list of repos match the actual order they occur in the repo file, but it was too hard to do it otherwise due to having to handle 2 unrelated syntaxes in the formatting.
It will probably a while before this becomes next inxi because I just did one, so will wait a bit to see if more fixes show up, which they usually do.
Thank you rizitis for confirming fix, and that all the other slackware repo types are working too, which is appreciated.
And thanks to marav for noticing that slpkg had broken due to syntax change.
Stuff like this I just can't track myself consistently.
I'm glad I waited until today, my first two ideas on how to do it were bad, and were kind of ugly hacks, the new logic is quite robust and future proof I think. That's the kind of fix where part of me goes: why didn't I do all the complex repos like this?! In this case it's because I didn't need to since I only had to handle one syntax per type. I do wish I hadn't lost the ordering of the repos in the actual file, but can't have everything. This was a brain-twister though. Solution maybe not elegant, but it's solid and I think will work, unless there's an unknown syntax type for these files, I'm hoping there isn't. It basically runs pretests to look for [REPOSITORIES] or [SOMETHING_ELSE] to set the switches if new or legacy then just treats each separately, but puts the data into a hash which is then predictable and easy to work with.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.