Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
BlankSystemDaemon
Mar 13, 2009




Kassad posted:

Nvidia is starting to provide open source kernel modules

Production-ready for datacenter GPUs, "alpha quality" for desktop GPUs. Needs a Turing or newer GPU.
They also moved all the bits needed for anyone to use it for anything into a RISC-V secure enclave, which is why it only works on Turing+ - because anything older doesn't have that secure enclave.

Adbot
ADBOT LOVES YOU

Takes No Damage
Nov 20, 2004

The most merciful thing in the world, I think, is the inability of the human mind to correlate all its contents. We live on a placid island of ignorance in the midst of black seas of infinity, and it was not meant that we should voyage far.


Grimey Drawer
Is there a magic one-line command (or tiny bash script) I can run to prepend an incrementing number to filenames sorted by Date Modified?

For example, if I have these files in a folder:
aasdf.txt, 2 hours old
basdf.txt, 1 hour old
casdf.txt, 3 hours old

I'd like to run a command or bash script to rename them to:
01 basfd.txt
02 aasdf.txt
03 casdf.txt

I know I can list files by Date Modified with 'ls -tr' and could probably set up some kind of loop that looks like:

count=01
for file in *.txt do
mv "$file" "$count$file"
count++
done

But I'm not finding a way to mash the two together and make sure they're numbered according to 'ls -tr'

Pablo Bluth
Sep 7, 2007

I've made a huge mistake.
FILES=$(ls -tr)
for filename in $FILES; do
#stuff
done

Edit: if no files have spaces in them. If they do, try:

(
IFS=$'\n'
FILES=$(ls -tr1)
for filename in $FILES; do
#stuff
done
)

That temporary changes the field separator from space to newline.

Pablo Bluth fucked around with this message at 09:33 on May 13, 2022

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Is there some kind of trigger/hook, for lack of a better word, that can listen to and preempt suspend events?

Basically what I think I want to do is this: if I hit 'suspend' or leave the PC unattended for X minutes, instead of immediately going into sleep mode, it should perform some maintenance tasks (backup sync, app upgrade, etc.) and then suspend. Should I need to get the computer off right now, I'll do a shutdown instead of suspending.

I suppose I could just write a script ending in 'systemctl suspend' as the last command, but then I would have to launch that script instead of using the default buttons / shortcuts, and jury-rig some way to have it trigger after inactivity. It would be much more elegant if I could stick the script somewhere that says 'whenever the system would suspend, first run this script and wait for it to finish'

Context: Fedora 36 Kinoite (KDE Silverblue), desktop PC.

BlankSystemDaemon
Mar 13, 2009




The BSDs have /etc/rc.suspend and /etc/rc.resume, which according to acpiconf(8) gets read by devd(8) before the ACPI events are handled.

BlankSystemDaemon fucked around with this message at 14:33 on May 13, 2022

BattleMaster
Aug 14, 2000

BlankSystemDaemon posted:

The BSDs have /etc/rc.suspend and /etc/rc.resume, which according to acpiconf(8) gets read by devd(8) before the ACPI events are handled.

sir, this is the linux thread

Nitrousoxide
May 30, 2011

do not buy a oneplus phone



NihilCredo posted:

Is there some kind of trigger/hook, for lack of a better word, that can listen to and preempt suspend events?

Basically what I think I want to do is this: if I hit 'suspend' or leave the PC unattended for X minutes, instead of immediately going into sleep mode, it should perform some maintenance tasks (backup sync, app upgrade, etc.) and then suspend. Should I need to get the computer off right now, I'll do a shutdown instead of suspending.

I suppose I could just write a script ending in 'systemctl suspend' as the last command, but then I would have to launch that script instead of using the default buttons / shortcuts, and jury-rig some way to have it trigger after inactivity. It would be much more elegant if I could stick the script somewhere that says 'whenever the system would suspend, first run this script and wait for it to finish'

Context: Fedora 36 Kinoite (KDE Silverblue), desktop PC.

Can system.d do conditional events like this? That'd be my guess. I've never been able to wrap my head around system.d scripting though so I can't help you there.

You'd probably have do userspace ones though for Kinoite given the immutable nature of the system space and I don't know if they'd have the permissions to run updates?

BattleMaster
Aug 14, 2000

systemd has suspend.target so I thought maybe you could add a service that requires suspend.target, which would be triggered when it reaches suspend.target. Looking into that I also found this:

https://www.freedesktop.org/software/systemd/man/systemd-suspend.service.html

quote:

Immediately before entering system suspend and/or hibernation systemd-suspend.service (and the other mentioned units, respectively) will run all executables in /usr/lib/systemd/system-sleep/ and pass two arguments to them. The first argument will be "pre", the second either "suspend", "hibernate", "hybrid-sleep", or "suspend-then-hibernate" depending on the chosen action. An environment variable called "SYSTEMD_SLEEP_ACTION" will be set and contain the sleep action that is processing. This is primarily helpful for "suspend-then-hibernate" where the value of the variable will be "suspend", "hibernate", or "suspend-after-failed-hibernate" in cases where hibernation has failed. Immediately after leaving system suspend and/or hibernation the same executables are run, but the first argument is now "post". All executables in this directory are executed in parallel, and execution of the action is not continued until all executables have finished.

Note that scripts or binaries dropped in /usr/lib/systemd/system-sleep/ are intended for local use only and should be considered hacks. If applications want to react to system suspend/hibernation and resume, they should rather use the Inhibitor interface.

The inhibitor interface it mentions is here

https://www.freedesktop.org/wiki/Software/systemd/inhibit/

and seems like it has a less hacky way of causing something to happen before the suspend happens.

BattleMaster
Aug 14, 2000

So I have something that works with just a systemd unit file. Works On My Machinetm (Debian 11, XFCE desktop) but it just uses a systemd unit file so it should work on anything with systemd like Fedora, I guess.

code:
[Unit]
Description=On Suspend
DefaultDependencies=no
Requires=sleep.target
After=sleep.target
Before=systemd-suspend.service

[Service]
Type=oneshot
ExecStart=touch /var/on-suspend

[Install]
WantedBy=sleep.target
The command it executes is trivial but I just wanted to see if the timestamp of its creation matches the time I hit suspend in XFCE.

Put it in /etc/systemd/system/ as a .service file. Edit the ExecStart to whatever command you want and Description to a more useful name, and then sudo systemctl enable <filename>.service

Note that it uses sleep.target, not suspend.target. I found documentation referring to suspend.target like I linked in the previous post (edit: and even in the drat man page for systemd-suspend.service on my own machine) but it looks like it's actually called sleep.target in the actual source for systemd-suspend.service on my machine (???) so maybe different versions of systemd have different names for the targets.

edit: Here's the source of systemd-suspend.service from my machine (found in /usr/lib/systemd/system/systemd-suspend.service) to show what I based mine on:

code:
[Unit]
Description=Suspend
Documentation=man:systemd-suspend.service(8)
DefaultDependencies=no
Requires=sleep.target
After=sleep.target

[Service]
Type=oneshot
ExecStart=/lib/systemd/systemd-sleep suspend

BattleMaster fucked around with this message at 15:26 on May 13, 2022

BlankSystemDaemon
Mar 13, 2009




BattleMaster posted:

sir, this is the linux thread
I'm sorry, I can't hear you, you're gonna need to speak up - the sound of my T480s running FreeBSD and playing a MPEG-TS stream (from DVB-C via HDHomeRun+TVHeadend) is too deafeningly silent. :v:

ExcessBLarg!
Sep 1, 2001

Takes No Damage posted:

Is there a magic one-line command (or tiny bash script) I can run to prepend an incrementing number to filenames sorted by Date Modified?
You can do this with Bash, but I find relying on external processes to provide file names (which you need here to sort) can be brittle at times. Using a modified IFS can help, but what if your filename has a newline?

For something like this I might use a Ruby one-liner:
code:
ruby -e 'Dir["*"].sort_by {|f| File.mtime(f)}.each_with_index {|f, i| File.rename(f, "%02d %s" % [i+1, f])}'

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt


Thank you, those were some :five: answers.

I'll try the systemd unit file first, then it if fails the magic folder. Running an inhibitor, as cool and Star Trek-esque as it sounds, is definitely overkill as I'd need to learn to code against system APIs (I'm a filthy high-level dev), package it as a RPM to install it on Silverblue, and keep it running at all times - which would require a systemd file in the first place! I might do it as a learning exercise at some point.

Mr. Crow
May 22, 2008

Snap City mayor for life

BlankSystemDaemon posted:

I'm sorry, I can't hear you, you're gonna need to speak up - the sound of my T480s running FreeBSD and playing a MPEG-TS stream (from DVB-C via HDHomeRun+TVHeadend) is too deafeningly silent. :v:

I'm sorry can you repeat that I'm to busy playing modern video games to focus :smuggo:

Mr. Crow
May 22, 2008

Snap City mayor for life

NihilCredo posted:

Thank you, those were some :five: answers.

I'll try the systemd unit file first, then it if fails the magic folder. Running an inhibitor, as cool and Star Trek-esque as it sounds, is definitely overkill as I'd need to learn to code against system APIs (I'm a filthy high-level dev), package it as a RPM to install it on Silverblue, and keep it running at all times - which would require a systemd file in the first place! I might do it as a learning exercise at some point.

IIRC the sleep / reboot / shutdown targets all have time limits to the tasks so I don't know if trying to do it as above is the best approach, I will try and see if I can dig up in the man where it talks about it. Whoever found that filesystem approach I think is probably what you'll end up needing to do of its gonna be long running tasks.

At the very least test it with just sleeps in a bash script or something and don't jump straight trying to upgrade your system and have the install ripped apart halfway through it :lol: what a nightmare if that was what happens


I'm not finding what I was thinking of maybe its halt only, and the arch wiki suggests the unit file method so go hog wild

https://wiki.archlinux.org/title/Power_management#Sleep_hooks

Mr. Crow fucked around with this message at 17:51 on May 13, 2022

RFC2324
Jun 7, 2012

http 418

Mr. Crow posted:

I'm sorry can you repeat that I'm to busy playing modern video games to focus :smuggo:

No one should ever need more than nethack

BlankSystemDaemon
Mar 13, 2009




Mr. Crow posted:

I'm sorry can you repeat that I'm to busy playing modern video games to focus :smuggo:
The sad part is, I haven't even played a video game because I couldn't - I just don't feel like playing video games anymore, and haven't for a long time.

Is it possible to grow out of video games? :ohdear:

RFC2324 posted:

No one should ever need more than nethack
I haven't even ascended in a long time!

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Mr. Crow posted:

At the very least test it with just sleeps in a bash script or something and don't jump straight trying to upgrade your system and have the install ripped apart halfway through it :lol: what a nightmare if that was what happens

Silverblue :smuggo:


e: though to be fair, I doubt even a regular Fedora nowadays could get borked if the power fails during a dnf upgrade, or could it?

Takes No Damage
Nov 20, 2004

The most merciful thing in the world, I think, is the inability of the human mind to correlate all its contents. We live on a placid island of ignorance in the midst of black seas of infinity, and it was not meant that we should voyage far.


Grimey Drawer

Pablo Bluth posted:

FILES=$(ls -tr)
for filename in $FILES; do
#stuff
done

Edit: if no files have spaces in them. If they do, try:

(
IFS=$'\n'
FILES=$(ls -tr1)
for filename in $FILES; do
#stuff
done
)

That temporary changes the field separator from space to newline.

After sleeping on it, I figured I could do something like:
ls -tr >> sortfile.txt

then use sortfile.txt as an input for a 'read' command, I've done that before with wget. But it looks like your command would do something similar in fewer steps, I'll check it out.

ExcessBLarg! posted:

You can do this with Bash, but I find relying on external processes to provide file names (which you need here to sort) can be brittle at times. Using a modified IFS can help, but what if your filename has a newline?

For something like this I might use a Ruby one-liner:
code:
ruby -e 'Dir["*"].sort_by {|f| File.mtime(f)}.each_with_index {|f, i| File.rename(f, "%02d %s" % [i+1, f])}'

Is Ruby a good script to have passing familiarity with for little file management stuff like this, compared to bash or python or whatever? I haven't written proper code since C (not ++) in college, but knowing some common tips and tricks for general Linux OS shenanigans is always a good thing.

Nitrousoxide
May 30, 2011

do not buy a oneplus phone



NihilCredo posted:

Silverblue :smuggo:


e: though to be fair, I doubt even a regular Fedora nowadays could get borked if the power fails during a dnf upgrade, or could it?

I'm a big fan of Silverblue. I think Redhat also re-did the partitions for a 36 fresh install so you can actually setup BTRFS snapshotting now? I mean that's less useful for Silverblue since the system files are read-only, but having your home directory snapshotted would be nice for rollbacks as well.

pseudorandom name
May 6, 2007

NihilCredo posted:

Is there some kind of trigger/hook, for lack of a better word, that can listen to and preempt suspend events?

Yes, systemd-inhibit --list will show all the currently active ones on your system.

ExcessBLarg!
Sep 1, 2001

Takes No Damage posted:

Is Ruby a good script to have passing familiarity with for little file management stuff like this, compared to bash or python or whatever? I haven't written proper code since C (not ++) in college, but knowing some common tips and tricks for general Linux OS shenanigans is always a good thing.
Personally, I think so. It's a good replacement for awk/sed/perl. I still write plain shell scripts for "simple" tasks where I'm primarily calling external commands, but for text processing or complicated file manipulation it's pretty good.

Python is definitely a more popular language than Ruby, but due to its syntax you can't write one-liners in it very well and are forced (for better or worse) to write a full-blown script.

Twerk from Home
Jan 17, 2009

This avatar brought to you by the 'save our dead gay forums' foundation.
I'm looking for a simple TUI tool that will show real-time bandwidth usage across interfaces like https://github.com/tgraf/bmon, but doesn't segfault at higher network speeds. I had used bmon for this for years, but for whatever reason on Ubuntu 20.04 with bonded 10G lines, it's segfaulting after a couple of seconds whenever network traffic on a single interface is over 300MB/s-ish.

What are your favorite tools for peeking at real-time up/down bandwidth usage?

BlankSystemDaemon
Mar 13, 2009




Twerk from Home posted:

I'm looking for a simple TUI tool that will show real-time bandwidth usage across interfaces like https://github.com/tgraf/bmon, but doesn't segfault at higher network speeds. I had used bmon for this for years, but for whatever reason on Ubuntu 20.04 with bonded 10G lines, it's segfaulting after a couple of seconds whenever network traffic on a single interface is over 300MB/s-ish.

What are your favorite tools for peeking at real-time up/down bandwidth usage?
Well, for real-time up/down bandwidth usage, systat -ifstat -match lagg0 on FreeBSD works great - but I'm also a big fan of vnstat, which I believe does real-time monitoring too, and is cros-platform to boot.

BlankSystemDaemon fucked around with this message at 20:22 on May 13, 2022

Vinigre
Feb 18, 2011

Prepare your bladder for imminent release!

Twerk from Home posted:

I'm looking for a simple TUI tool that will show real-time bandwidth usage across interfaces like https://github.com/tgraf/bmon, but doesn't segfault at higher network speeds. I had used bmon for this for years, but for whatever reason on Ubuntu 20.04 with bonded 10G lines, it's segfaulting after a couple of seconds whenever network traffic on a single interface is over 300MB/s-ish.

What are your favorite tools for peeking at real-time up/down bandwidth usage?

I usually go with iftop for this, as it will break down the RX/TX traffic for a given interface into each host with a bar nice graph so I can see what the hell is making such a racket. I also like to use nload if I'm just looking for the overall usage of a given interface, again with a nice little graph that makes me feel warm inside.

Chilled Milk
Jun 22, 2003

No one here is alone,
satellites in every home

ExcessBLarg! posted:

Personally, I think so. It's a good replacement for awk/sed/perl. I still write plain shell scripts for "simple" tasks where I'm primarily calling external commands, but for text processing or complicated file manipulation it's pretty good.

Python is definitely a more popular language than Ruby, but due to its syntax you can't write one-liners in it very well and are forced (for better or worse) to write a full-blown script.

I'm biased because I've done a ton of Rails work over the years, but yeah. Ruby was originally designed for this exact thing. The stdlib makes it very easy to chain and whip stuff together. I'd rate it noticeably easier to work with for this sort of thing that python, but not by so wide a margin that you should switch if you were already comfortable. Bless you if you can slice and dice with awk/sed like a pro off the top of your head, but no shame in reaching for something designed for humans instead if you can.

qsvui
Aug 23, 2003
some crazy thing

BlankSystemDaemon posted:

The sad part is, I haven't even played a video game because I couldn't - I just don't feel like playing video games anymore, and haven't for a long time.

Is it possible to grow out of video games? :ohdear:

:same:

Haven't played in years and I have to say, I don't miss it.

euroshopper
Aug 14, 2021
I've been using KDE on Fedora for a year and a half and it's generally been pretty stable. I do find it extremely frustrating realizing that maintenance of KDE within these distros will always come second place to GNOME because of a lack of risk-taking. Noting that developers like Mozilla and Document Foundation already use GTK for their programs so I'm assuming it's just easier to develop within the environment that's also based on GTK etc.

It really seems no matter what GTK-based environments will always take first-priority (unless Red Hat or Canonical suddenly decided to switch their apps over to Qt within the nest 20 years, which is unlikely). Not knocking on Cinnamon or xfce but I can smell the GNOME residue all over 'em

euroshopper fucked around with this message at 04:07 on May 14, 2022

Computer viking
May 30, 2011
Now with less breakage.

Chilled Milk posted:

I'm biased because I've done a ton of Rails work over the years, but yeah. Ruby was originally designed for this exact thing. The stdlib makes it very easy to chain and whip stuff together. I'd rate it noticeably easier to work with for this sort of thing that python, but not by so wide a margin that you should switch if you were already comfortable. Bless you if you can slice and dice with awk/sed like a pro off the top of your head, but no shame in reaching for something designed for humans instead if you can.

My secret shame is that I use R for things like this. Having a table as a native data type in addition to the usual arrays and dictionaries feels like a natural fit for a lot of things.

ExcessBLarg!
Sep 1, 2001

euroshopper posted:

I do find it extremely frustrating realizing that maintenance of KDE within these distros will always come second place to GNOME because of a lack of risk-taking.
Historically GTK and GNOME have fallen within RedHat's sphere of influence. Even freedesktop.org, which is nominally independent, has a lot of cross-over with them. So yes you tend to see RedHat/GNOME/freedesktop.org driven "next-gen desktop" projects all take place in Fedora. Without debating the long-term value of their efforts, I do find them to generally be narrowly-focused. If your needs fall outside of that, Fedora is probably not a great fit.

KDE, meanwhile, has its own goals, but its also inextricably linked to Qt, which itself has always tried to be the best batteries-included cross-platform C++ UI toolkit.

I don't know that Firefox and LibreOffice are good examples to illustrate GTK's "marketshare superiority" or something like that. Both FireFox and LibreOffice are cross-platform behemoth projects that internally use their own abstraction layers (XUL, VCL) for which GTK is just one backend. So they're not necessarily chasing down the latest GTK/freedesktop.org developments either except where it directly benefits them. For a long time LibreOffice also had a Qt backend that was at parity to the GTK one, but I guess that's no longer the case. Perhaps for historical reasons, or perhaps due to the size of Qt 5, I think it's generally been more palatable for KDE-focused distributions to include GTK applications in addition to Qt, than GNOME-focused distribution to include Qt ones.

Anyways, have you tried a KDE-focused desktop?

euroshopper posted:

It really seems no matter what GTK-based environments will always take first-priority (unless Red Hat or Canonical suddenly decided to switch their apps over to Qt within the nest 20 years, which is unlikely).
I don't know about Canonical, but I don't think they're "all in" on GTK/GNOME either. They're mostly trying to figure out how to make money off cloud/IoT in which case desktop isn't their primary focus, even if it's their most popular (free) product. Mind you that Kubuntu (KDE) and Lubuntu (LXQt) are both official flavors ("official flavours") of Ubuntu.

ExcessBLarg!
Sep 1, 2001

Computer viking posted:

My secret shame is that I use R for things like this. Having a table as a native data type in addition to the usual arrays and dictionaries feels like a natural fit for a lot of things.
I'm a fan of R too, but its facilities for text-processing are definitely secondary to numerical processing/statistics, which makes it effectively the opposite of Ruby. For one, R doesn't have dictionaries. You can use lists as associative-arrays, but they're internally still just lists so key (name) lookups are O(N), not O(1).

For years I used a combination of Ruby-calling-Rscript for my work. These days though that might be better handled with Pandas which, somehow, combines the method-chaining magic of Ruby with R's data-frames and numeric capabilities, in a language that's actually neither of them.

ExcessBLarg! fucked around with this message at 12:59 on May 14, 2022

spiritual bypass
Feb 19, 2008

Grimey Drawer
Reading about these Ruby one liners has convinced me that it's the next language for me to pick up

Computer viking
May 30, 2011
Now with less breakage.

ExcessBLarg! posted:

I'm a fan of R too, but its facilities for text-processing are definitely secondary to numerical processing/statistics, which makes it effectively the opposite of Ruby. For one, R doesn't have dictionaries. You can use lists as associative-arrays, but they're internally still just lists so key (name) lookups are O(N), not O(1).

For years I used a combination of Ruby-calling-Rscript for my work. These days though that might be better handled with Pandas which, somehow, combines the method-chaining magic of Ruby with R's data-frames and numeric capabilities, in a language that's actually neither of them.

The only downside is that I really dislike working in pandas; something about it just does not mesh well with me. I enjoy plain python, though. :shrug:

Text processing in R is indeed not great. Using something like stringr helps, but then you suddenly depend on a package you need to install first. It would be fine for the concrete example above, though - file.info() gives you native date-time objects that should sort correctly, and you could glue the prefixes in with sprintf easily enough.

As for dictionaries, you could always use environments? A bit clunky, but they're proper hashmaps with decent performance. (Supposedly - I haven't benchmarked it myself)

As for Ruby - it is indeed neat. My boyfriend runs a website with nanoc, and his "compile articles into static html" Rakefile has gone a bit overboard over the years. I've helped him with it now and then without really knowing Ruby, and it does seem pleasant. One day I'll get around to learning it better.

Computer viking fucked around with this message at 13:38 on May 14, 2022

acetcx
Jul 21, 2011

NihilCredo posted:

Silverblue :smuggo:


e: though to be fair, I doubt even a regular Fedora nowadays could get borked if the power fails during a dnf upgrade, or could it?

A friend of mine who I encouraged to install Fedora 35 a few months back came to me with a broken system a few weeks ago. He’s new to anything Linux so I told him to use the graphical gnome software app to do updates and it seems after one of these updates it left the system unbootable. It couldn’t find an initramfs for the most recent kernel and booting into a previous one just presented a generic “something went wrong” message after switching to the desktop. I was able to switch to a terminal with ctrl+alt+f3 where I pulled up the logs from the last boot with journalctl -b -1 -e and those logs ended about 70% of the way through an update as if the power had been cut. He claims there was no power loss and everything seemed normal to him so we just reinstalled the OS since I’m not experienced enough to be able to recover the system from that state. I taught him how to use dnf for updates so hopefully it doesn’t happen again but welp.

ExcessBLarg!
Sep 1, 2001
Since folks have expressed an interest in Ruby I thought I'd explain this one a bit furhter:

ExcessBLarg! posted:

For something like this I might use a Ruby one-liner:
code:
ruby -e 'Dir["*"].sort_by {|f| File.mtime(f)}.each_with_index {|f, i| File.rename(f, "%02d %s" % [i+1, f])}'
Writing this in a less obfuscated way:
Ruby code:
#!/usr/bin/env -S ruby -w

filenames  = Dir.glob("*")
sorted_fns = filenames.sort_by {|fn| File.mtime(fn)}

sorted_fns.each_with_index do |filename, i|
    new_fn ="%02d %s" % [i+1, filename]
    File.rename(filename, new_fn)
end
Here, Dir and File are both classes whose instances implement directory/file streams--for example, if you had a directory with thousands of files then you could iterate over a Dir object to process them. Both also implement convenience methods for manipulating, or quickly returning the contents of a directory/file as an array of strings (of which, 'Dir["*']' is shorthand for 'Dir.glob("*")'). This code also relies on the Enumerable sort_by and each_with_index methods to sort the files with a custom mapping (mtime) and to generate an index for each filename in the array.

The equivalent in Python would be written as:
Python code:
#!/usr/bin/env -S python3 -Wd

import os

filenames  = [fn for fn in os.listdir() if fn[0] != "."]
sorted_fns = sorted(filenames, key=os.path.getmtime)

for i, filename in enumerate(sorted_fns):
    new_fn = f"{i:02d} {filename}"
    os.rename(filename, new_fn)
which is substantially similar to the Ruby version. If you were OK renaming any potential dot-files in the directory then you could simplify that list comprehension with os.listdir too.

You could also write the Python version as a one-liner:
code:
python3 -c 'import os; [os.rename(f, f"{i:02d} {f}") for i, f in enumerate(sorted(os.listdir(), key=os.path.getmtime))]'
but the problem here is that you have to abuse a list comprehension to perform the rename operation. This is a problem because python one-liners can only consist of a single statement (or something, I'm not sure of the actual restriction here) so you can't have both "import os" and a traditional for loop. This restriction generally makes it difficult to write one-liners in Python, but I think it's a fair statement to say that such things aren't a priority for most folks who write Python.

euroshopper
Aug 14, 2021

ExcessBLarg! posted:

Historically GTK and GNOME have fallen within RedHat's sphere of influence. Even freedesktop.org, which is nominally independent, has a lot of cross-over with them. So yes you tend to see RedHat/GNOME/freedesktop.org driven "next-gen desktop" projects all take place in Fedora. Without debating the long-term value of their efforts, I do find them to generally be narrowly-focused. If your needs fall outside of that, Fedora is probably not a great fit.

Wasn't really specifically referring to Fedora/RedHat. My grievance is that the most popular and maintained distros tend to be GTK-based and the KDE distros that do exist tend to be derivatives or 'flavors' of the aforementioned GTK distros. OpenSUSE seems to be the main exception to this and isn't really marketed towards consumers (ex-Windows users more or less) in the way Ubuntu or Fedora is.

Volguus
Mar 3, 2009

euroshopper posted:

Wasn't really specifically referring to Fedora/RedHat. My grievance is that the most popular and maintained distros tend to be GTK-based and the KDE distros that do exist tend to be derivatives or 'flavors' of the aforementioned GTK distros. OpenSUSE seems to be the main exception to this and isn't really marketed towards consumers (ex-Windows users more or less) in the way Ubuntu or Fedora is.

KDE, however, is very well maintained in Fedora, and is (in my opinion) one of the better flavours of it. Yes, Gnome is where they put the majority of their efforts, but there's only so much polishing a turd one can do.

euroshopper
Aug 14, 2021

Volguus posted:

KDE, however, is very well maintained in Fedora, and is (in my opinion) one of the better flavours of it. Yes, Gnome is where they put the majority of their efforts, but there's only so much polishing a turd one can do.

Genuinely have no idea why people poo poo on Plasma that much lol. It's pretty fast and has been increasingly light on resources w/o looking dated (sorry xfce/MATE). There are an increasing number of environments that are just GNOME 3+ forks which in turn retains all the design inconsistencies. Can't imagine it'll get better with some of the most commonly used apps being ported to GTK 4.

I like Cinnamon but they haven't really revamped their design philosophy in an exiting way which, ngl, was one of the main reasons why I hadn't installed a Linux Mint distro since abt 3 years ago.

euroshopper fucked around with this message at 22:45 on May 14, 2022

ExcessBLarg!
Sep 1, 2001

euroshopper posted:

My grievance is that the most popular and maintained distros tend to be GTK-based and the KDE distros that do exist tend to be derivatives or 'flavors' of the aforementioned GTK distros.
What makes Kubuntu "derivative" other than not being called Ubuntu? What if Ubuntu renamed itself Gubuntu?

One point in Kububtu's favor is that it's been around since 2005, whereas Ubuntu was faffing around with Unity for some time.

euroshopper posted:

OpenSUSE seems to be the main exception to this and isn't really marketed towards consumers (ex-Windows users more or less) in the way Ubuntu or Fedora is.
Perhaps it doesn't have quite the userbase of Fedora or Ubuntu but SUSE has been around forever.

ExcessBLarg! fucked around with this message at 23:32 on May 14, 2022

euroshopper
Aug 14, 2021

ExcessBLarg! posted:

What makes Kubuntu "derivative" other than not being called Ubuntu? What if Ubuntu renamed itself Gubuntu?

Ubuntu gets most of the attention when it comes to development/financial support/making it look pretty. Kubuntu literally just slaps the default Plasma theme onto the Ubuntu base without changing much. Also important to note that Kubuntu almost became defunct when Canonical ended their sponsorship (big reason is they had very little faith in Plasma 4)

Adbot
ADBOT LOVES YOU

ExcessBLarg!
Sep 1, 2001

euroshopper posted:

Ubuntu gets most of the attention when it comes to development/financial support/making it look pretty.
How much Canonical staff time goes into the GNOME integration though?

Ubuntu dropped sponsorship of both GNOME and KDE when they adopted Unity as their flagship desktop. But they've since pivoted again away from the desktop to a cloud/IoT focus. Their readoption of GNOME was part motivated by their users' preference, but also because there isn't any value for Canonical in distancing from what RedHat/Fedora are doing (aside from Snaps).

euroshopper posted:

Kubuntu literally just slaps the default Plasma theme onto the Ubuntu base without changing much.
Is there any indication that Kubuntu users actually want anything different than the upstream KDE experience? What's the point of changing stuff just for the sake of change?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply