Python + bash
Если вам часто требуется запускать shell команды из Python-кода, какой способ вы используете?
Самый низкоуровневый это функция os.system(), либо os.popen(). Рекомендованный способ это subprocess.call(). Но это всё еще достаточно неудобно.
Советую обратить своё внимание на очень крутую библиотеку sh.
Что она умеет?
🔸 удобный синтаксис вызова команд как функций
# os
import os
os.system("tar cvf demo.tar ~/")
# subprocess
import subprocess
subprocess.call(['tar', 'cvf', 'demo.tar', '~/'])
# sh
import sh
sh.tar('cvf', 'demo.tar', "~/")
🔸 простое создание функции-алиаса для длинной команды
fn = sh.lsof.bake('-i', '-P', '-n')
output = sh.grep(fn(), 'LISTEN')
в этом примере также задействован пайпинг
🔸 удобный вызов команд от sudo
with sh.contrib.sudo:
print(ls("/root"))
Такой запрос спросит пароль. Чтобы это работало нужно соответствующим способом настроить юзера.
А вот вариант с вводом пароля через код.
password = "secret"
sudo = sh.sudo.bake("-S", _in=password+"\n")
print(sudo.ls("/root"))
Это не все фишки. Больше интересных примеров смотрите в документации.
Специально для Windows💀 юзеров
#libs#linux
#Policy_Brief: Coercion Over Consent: #Ethiopia’s dangerous mandatory Digital ID experiment
In this policy brief, Mohamed A. argues that Ethiopia's mandatory Digital ID (#Fayda) is a "flawed and dangerous policy," not because identification itself is problematic, but because enforcement lacks legal safeguards. He emphasizes that centralizing sensitive data risks turning governance into a tool of "surveillance, control, and exclusion."
According to him, Ethiopia is "importing the concept as if it were a proven model." In Ethiopia's fragile institutional context, this amounts to "recklessness disguised as modernization," especially with foreign funding raising unresolved questions about "who controls the data."
The author urges authorities to "pause enforcement" until trust and oversight are established, arguing that without them, mandatory ID is "not progress—it is a poorly designed and dangerous policy."
https://addisstandard.com/?p=54995
🚨 Public announcements 🚨
We’re excited to announce a *TikTok Challenge* to showcase your creativity and skills! 🎥
Theme: Highlight the features and benefits of our *Passenger Online Booking* service.
How to Participate:
1️⃣ Create an engaging TikTok video in *Amharic, English, Afaan Oromo, Af Somali, Afar*.
2️⃣ Include the Online Booking requirements is *National ID* in your video.
3️⃣ Be creative, original, and fun!
Deadline: Submit your video by Monday, February 17, 2025.
🎉 Prize:
The winner will receive a *cash bonus* and *special recognition* for their outstanding creativity!
Join the content creators' group by scanning the QR code to submit your videos. We can’t wait to see your creations!
#EthioDjiboutiRailway#ComingSoon#TravelMadeEasy#StayTuned#DigitalEthiopia#Fayda