serhii.net

In the middle of the desert you can say anything you want

23 Aug 2021

Day 965

Ethernet device ’not managed’ in network-manager

Couldn’t use ethernet because the device was ’not managed’ according to nm-applet.

Neither

sudo nmcli dev set enp0s31f6 managed yes

nor changing managed=false to managed=true in /etc/NetworkManager/NetworkManager.conf helped (after the usual service restarts).

But creating an this empty file did:

sudo touch /etc/NetworkManager/conf.d/10-globally-managed-devices.conf

Python temporary directories

Memory lapse on my side, I thought tempfile.gettempdir() returned a random temporary directory I can use. Nope, it returns the absolute address of /tmp or its equivalent on that platform. I was thinking about tempfile.gettempdir(). There are also tempfile.TemporaryDirectory(), which gets automatically removed after the context ends or the object is deleted.

It’s the kind of things I’m afraid of in shell scripts, where manually deleting a temporary directory could remove more than needed.

As usual, the python docu on topic 1 is a good thing to read.

Python pathlib removing directory tree

There’s no way to remove a directory with all its contents recursively using pathlib. 2

pathlib.rmdir() removes empty directories, pathlib.unlink() removes files.

The way to do this is external libs, a la shutil.rmtree().

Very very weird design decision, as removing stuff is in no way an uncommon operation.

But a recursive pathlib solution exists, from same StackOverflow answer:

from pathlib import Path

def rmdir(directory):
    directory = Path(directory)
    for item in directory.iterdir():
        if item.is_dir():
            rmdir(item)
        else:
            item.unlink()
    directory.rmdir()

rmdir(Path("dir/"))

Python serialization of dataclass, datetime, numpy and stuff

orjson looks interesting: Fast, correct Python JSON library supporting dataclasses, datetimes, and numpy | PythonRepo

Nel mezzo del deserto posso dire tutto quello che voglio.
comments powered by Disqus