Just my blog
Blog about everything, mostly about tech stuff I made. Here is the list of stuff I'm using at my blog. Feel free to ask me about implementations.
- Mobaxterm SSH RDP FTP...
- Thunderbird Email client
- Filezilla FTP client/server
- Nirsoft Win utils
- Sysinternals Win utils
- Pi-Hole AD block by DNS
- NUT UPS manager
- Rpi MON Raspberry monitoring
- Free CAD 3D modelling
- Free Commander Far-like filemanager
- Bitwarden Password manager
- Django web framework
- celery multi-tasking
- celery-beat Celery + Django
- celery-results Celery + Django
- Pillow Python image lib
- wsgi mod Apache + Python
- requests best in WEB requests
- openpyxl make Excell docs
- p4python Perforce + Python
- paramiko SSH + Python
- pyvmomi ESXi Vcenter + Python
I'm using these libraries so you can ask me about them.
Raspberry 5 test-to-speech using Piper
How to make your Raspberry 5 talking with python lib Piper?
I wanted to make my Raspberry tell me about power outages and air alerts near my location.
The setup is pretty simple and described ar the repo:
I didn't want to waste my time making yet another Python venv and that's why I've chosen a simple binary mode.
Setup
Now about the setup:
- Raspberry 5.
- USB sound card with 3.5 jack.
- USB-powered speaker with a 3.5 jack.
Sound
CMD to change the volume programmatically:
amixer set Master 80% >> /dev/null
Sound devices and controls
You may have a problem with playing generated WAV files and making voice directly. So you need to choose devices for a different output.
To list devices run:
# List devices
aplay -L
# I only have USB card:
hw:CARD=Audio,DEV=0
USB Audio, USB Audio
Direct hardware device without any conversions
plughw:CARD=Audio,DEV=0
USB Audio, USB Audio
Hardware device with all software conversions
sysdefault:CARD=Audio
USB Audio, …
Installing NUT - Network Ups Tool Notifications and emails
Installing NUT - Network Ups Tool Notifications and emails
Notifications and email
- Start here: Installing NUT
Simple
Go to file:
sudo vi /etc/nut/upsmon.conf
# Email script for NOTIFYCMD
# Simple
NOTIFYCMD "/etc/nut/notifycmd.sh"
# Notification events
NOTIFYFLAG ONLINE SYSLOG+WALL+EXEC
NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC
NOTIFYFLAG LOWBATT SYSLOG+WALL+EXEC
NOTIFYFLAG FSD SYSLOG+WALL+EXEC
NOTIFYFLAG COMMOK SYSLOG+WALL+EXEC
NOTIFYFLAG COMMBAD SYSLOG+WALL+EXEC
NOTIFYFLAG SHUTDOWN SYSLOG+WALL+EXEC
NOTIFYFLAG REPLBATT SYSLOG+WALL+EXEC
NOTIFYFLAG NOCOMM SYSLOG+WALL+EXEC
NOTIFYFLAG NOPARENT SYSLOG+WALL+EXEC
Simple notification script
sudo vi /etc/nut/notifycmd.sh
#!/bin/bash
EMAIL='to@YOYR_EMAIL.com'
echo -e "Subject: UPS ALERT Basic: $NOTIFYTYPE\n\nUPS: $UPSNAME\r\nAlert type: $NOTIFYTYPE\n\n\nThis is a basic notification!" | msmtp $EMAIL
# Change group to nut
sudo chown :nut /etc/nut/notifycmd.sh
# Add execution
sudo chmod 774 /etc/nut/notifycmd.sh
# Restart the NUT services
sudo systemctl restart nut-server.service
sudo systemctl restart nut-driver.service
sudo systemctl restart nut-monitor.service
Extra notification script by Scheduler
Set signals
sudo vi /etc/nut/upsmon.conf
Installing NUT - Network Ups Tool
Install and use Network Ups Tool - an open source Uninterruptible Power Supply software
- UPS with connected devices:
- LG TV
- Soundbar
- NUC as a media centre (with NUT monitor for Windows)
- RPi5 as brain unit with NUT, Pi-Hole and DHCP.
- TP-Link Router.
In case of a power-loss event, PRi will notify me via email, NUC will power off on its own, TV can be powered off manually.
Powered-off TV and soundbar are neglectable in total power usage on battery, so I have about 1,5 to 2 hours of running Raspberry 5 and TP-Link to keep my internet on.
WSGI mod, Python, Django, Celery and a nice fella virtualenv
Old
Here I'll show how to use Python (3.8.0 in the current example, but legit for latest 3.+ versions, not for os.name == 'NT') and virtualenv to setup WGSI enabled website on Django (or any) with implemented Celery + Flower + RabbitMQ. This example is my own path used for automated test framework: Octopus (not available now, but have dev branch opened: Lobster)
Here only configurations and setup for Python 3.8.0, virtualenv, WSGI, Django, Celery (worker and beat services), Flower and that's it. Later I'll show Django + Celery configuration when they run together (sort of).
You may want to install Python at first: Read
When your modern and fancy python is installed, we'll make a virtual environment for our website. Never underestimate a power of virtualenv as I did, because since you start to use it, you will never understand how did you work without them …
!-->!-->!-->!-->!-->!-->!--> Read...Centos Python Installation Guide with no Pain
Old me installing Python
Centos 7 + Python 3(4,5,6,7,8) installation guide with no pain. As for me.
I can't even say how many times I have to update my python executables for web servers and how much pain I feel during this routine.
Usual Google\StackOverflow advice only describes one particular problem. But there're few of them, and they're different so you spent hours trying to collect them all and pick the right decision.
Then you just drop it and use yum for any latest python version available!
Here I'll show you and make a reminder for myself about how to install modern python in the best way, once, without pain.
I use Centos 7 typical install as for WebServer (minimal install could require to install tonnes of dev-libs and yum, be sure you prepared them before)
1. Preparations:
You need to install some compil libs.
yum …
!-->!-->!-->!-->!-->!-->!-->!-->!-->!-->!-->!-->!-->!-->!-->!-->!-->
Read...
Test design and implementation.
Old stuff, very old
Test design
Our test system has a pretty simple configuration, so I do not want to bother you with the detailed description of it. Simply - it's just a standalone execution of a test.py file with all requirements (test setup and tear down) in local internal test utility. Helper local utility has a usual amount of preparation functions, test data loading and some other configurations. In the very end of test loading, it just compares a node-set result of "real" scan (software and hardware nodes in a database after the scan) with predefined node-set (from test.py). Node set we usually expect at the end of the test should be added by the developer when product discovery pattern is ready or have a new feature or fix.
Now I'm trying to implement entirely new and somewhere different test design because current is not …
!-->!-->!-->!-->!-->!-->!-->!--> Read...Test automation or: How I Learned to Stop Worrying and Love Async __init__
Old stuff
Morning everybody…
I recommend reading this part of the blog only in the morning with a cup of dark and strong coffee.
I'll show you some new cases, and howto's to help you automate routines in the developer's life. There will be an example of my fails and win on different scenarios. The poor code I'll include also.
Very beginning
Firstly - I'll try to make this thread in English. And maybe later when I have time - to make Ukrainian and Russian translations, I'll make them.
"Octopus" story has started from a small plugin for Sublime Text editor. Later it will be ported to Atom.
I've started developing "Octopus" on spring-summer 2016, and I've not finished it yet! New functions and features were implemented continuously. Product transforms into a framework.
Now all processes executed automatically and simultaneously for 24/7. "Octopus" has …
!-->!-->!-->!-->!-->!-->!-->!-->!-->!-->!-->!-->!-->!-->!--> Read...Python - Django Celery - кейс длиною в вечность.
Вкратце: когда добавляешь пачку тасок на Celery worker'ы, случается так, что парочка из них отваливается или засыпает или еще чего. Долго не доходили руки поправить это недоразумение, поэтому я просто рестартовал все воркеры раз в пару дней или прямо перед началом проверки рутины, в общем очень сложно было поймать и воспроизвести тот случай, когда без каких-либо ошибок воркер просто молчал. И наконец дошоли руки запилить кривофикс, время покажет насколько он толковый, суть в следующем: В сразу после момента определения свободного воркера - запускать app.control.heartbeat()
и app.control.ping(timeout=10)
и если ответ пришел (в виде [{'alpha@host': {'ok': 'pong'}}]
) - значит воркер готов и можно передавать ему таску, пачку тасков, рутину и тп. Если ответ пришел отличным от этого - даем ошибку и ничего не запускаем далее. При плохом раскладе пользователю придется просто перезапустить задачу посредством нажатия кнопочки еще раз, а вот запланированная таска - умрет. Общий вид на код примерно такой: Набросавши …
Python 3 showing progressbar while subprocess.Popen
Have an interesting case I want to share and save for future. One small problem in this system: https://github.com/trianglesis/BMC_TPL_IDE is showing when some process is running and was not hanged up. Sometimes we need to run a huge amount of checks and tests and would be great to know if something hangs before killing it mannually. I used different scenarios and mostly a module pregressbar2, and this is what I finally can compose:
- Make worker which will execute job sorf of randomly:
-
import time import random print("START SOMETHING") for i in range(5): sec = random.randint(1, 3) print("Sleeping for: %d" % sec) time.sleep(sec) print("Making job, line: %d" % i) print("END SOMETHING")
-
- Make process executor:
-
import sys import subprocess import progressbar # Draw spinner: bar = progressbar.ProgressBar(max_value=progressbar.UnknownLength) # Execute some job with multiple lines on stdout: p = subprocess.Popen("C:\Python34\python.exe worker.py", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # Lines will be collected in list: result = …
-
VK_execute
Для всех страждущих наконец выкладываю нормальные примеры использования VK Script: https://github.com/triaglesis/vk_execute Там все мои примеры и по работе и просто тестовые. Самый быстрый вот такого плана, без внутреннего парсинга. Как только добавляешь внутрь вк скрипта какой-то проверочный код - КПД резко падает. Мой совет - вк_скрипт только для сбора всего "сырого" - дальше обрабатывать уже на сереверной стороне.
var posts_cnt; var posts; var post_list = []; var offset_posts = Args.global_offset_posts; offset_posts = parseInt(offset_posts); // var offset_posts = 0; var run_count = 0; var iter_count = 20; while (iter_count > run_count ) {posts = API.wall.get( {"owner_id":(Args.owner_id), "domain":(Args.domain), "offset":(offset_posts), "count":"100", "filter":"all", "extended":"0", "v":"5.42"} ); post_list.push(posts.items); offset_posts = offset_posts + 100; run_count = run_count + 1; posts_cnt = posts.count; }; return {"posts_cnt": posts_cnt, "run_count":run_count, "iter_count":iter_count, "offset_posts": offset_posts, "posts": post_list};
Read...