add treefmt and format everything

This commit is contained in:
Ingolf Wagner 2023-04-26 09:23:56 +02:00
parent b2054c4b33
commit ff9ac63676
No known key found for this signature in database
GPG key ID: 76BF5F1928B9618B
9 changed files with 123 additions and 85 deletions

View file

@ -1,8 +1,10 @@
#!/usr/bin/env bash
set -e set -e
defaultDevice=PCH defaultDevice=PCH
start_jack(){ start_jack() {
internal_device_number=-1 internal_device_number=-1
komplete_device_number=$(aplay -l | grep Vestax | cut -d":" -f1 | cut -d" " -f2) komplete_device_number=$(aplay -l | grep Vestax | cut -d":" -f1 | cut -d" " -f2)
@ -39,30 +41,27 @@ start_jack(){
# #
# to find configuration options do # to find configuration options do
# jack_control dp # jack_control dp
if [[ $device_number -eq -1 ]] if [[ $device_number -eq -1 ]]; then
then
# we use alsa in reality, but pulse opens up all the pulse # we use alsa in reality, but pulse opens up all the pulse
# sink and source stuff # sink and source stuff
# jack_control ds pulse # not working for some reason # jack_control ds pulse # not working for some reason
jack_control ds alsa jack_control ds alsa
jack_control dps device hw:$defaultDevice jack_control dps device hw:$defaultDevice
else else
jack_control ds alsa jack_control ds alsa
jack_control dps device hw:$device_number # use usb card jack_control dps device "hw:$device_number" # use usb card
fi fi
jack_control dps duplex True # record and playback ports jack_control dps duplex True # record and playback ports
jack_control dps hwmon False # no hardware monitoring jack_control dps hwmon False # no hardware monitoring
jack_control dps rate 48000 # use cd sample rate jack_control dps rate 48000 # use cd sample rate
# nperiods are the splitup of the # nperiods are the splitup of the
# sound-ring-buffer. 2 are ok for internal cards # sound-ring-buffer. 2 are ok for internal cards
# but for usb you should use 3 because # but for usb you should use 3 because
# you can have to write in junks to the card # you can have to write in junks to the card
# so there is one backup slice in the middle # so there is one backup slice in the middle
if [[ $internal_device_number -ne -1 ]] if [[ $internal_device_number -ne -1 ]]; then
then
jack_control dps nperiods 3 jack_control dps nperiods 3
fi fi
@ -82,7 +81,7 @@ start_jack(){
jack_control start jack_control start
} }
stop_jack(){ stop_jack() {
jack_control exit jack_control exit
} }
@ -92,14 +91,18 @@ status_jack() {
jack_control status jack_control status
} }
case $1 in case $1 in
start) start_jack start)
;; start_jack
stop) stop_jack ;;
;; stop)
restart) stop_jack ; start_jack stop_jack
;; ;;
*) status_jack restart)
;; stop_jack
start_jack
;;
*)
status_jack
;;
esac esac

View file

@ -1,50 +1,48 @@
#!/usr/bin/env bash
function stop_program(){ function stop_program() {
echo "stop $1" echo "stop $1"
sudo systemctl stop $1 sudo systemctl stop "$1"
} }
function start_program(){ function start_program() {
echo "start $1" echo "start $1"
sudo systemctl stop $1 sudo systemctl stop "$1"
} }
function start() {
function start(){ echo "starting programs again"
echo "starting programs again" echo "-----------------------"
echo "-----------------------" echo
echo start_program backup.on-porani.insecure.timer
start_program backup.on-porani.insecure.timer start_program backup.on-workhorse.insecure.timer
start_program backup.on-workhorse.insecure.timer start_program backup.on-workout.insecure.timer
start_program backup.on-workout.insecure.timer start_program syncthing.service
start_program syncthing.service start_program tlp.service
start_program tlp.service start_program tor.service
start_program tor.service
} }
function stop(){ function stop() {
echo "stopping programs" echo "stopping programs"
echo "-----------------" echo "-----------------"
echo echo
stop_program backup.on-porani.insecure.timer stop_program backup.on-porani.insecure.timer
stop_program backup.on-workhorse.insecure.timer stop_program backup.on-workhorse.insecure.timer
stop_program backup.on-workout.insecure.timer stop_program backup.on-workout.insecure.timer
stop_program syncthing.service stop_program syncthing.service
stop_program tlp.service stop_program tlp.service
stop_program tor.service stop_program tor.service
} }
# ---- # ----
# main # main
# ---- # ----
stop stop
echo echo
echo -n "wait to start again -> " echo -n "wait to start again -> "
read read -r
echo echo
start start

View file

@ -10,7 +10,7 @@ from tempfile import TemporaryDirectory
def nginx_config() -> str: def nginx_config() -> str:
reload_config ="/etc/nginx/nginx.conf" reload_config = "/etc/nginx/nginx.conf"
if os.path.exists(reload_config): if os.path.exists(reload_config):
return reload_config return reload_config
out = subprocess.check_output(["systemctl", "cat", "nginx"]) out = subprocess.check_output(["systemctl", "cat", "nginx"])
@ -26,8 +26,9 @@ def main():
config_path = nginx_config() config_path = nginx_config()
with TemporaryDirectory() as temp_dir: with TemporaryDirectory() as temp_dir:
temp_path = os.path.join(temp_dir, "nginx.conf") temp_path = os.path.join(temp_dir, "nginx.conf")
with open(temp_path, "wb+") as temp_file, \ with open(temp_path, "wb+") as temp_file, open(
open(config_path, "rb") as config_file: config_path, "rb"
) as config_file:
shutil.copyfileobj(config_file, temp_file) shutil.copyfileobj(config_file, temp_file)
temp_file.flush() temp_file.flush()
subprocess.check_call(["nginxfmt", temp_file.name]) subprocess.check_call(["nginxfmt", temp_file.name])

View file

@ -19,29 +19,33 @@ class GitLogger:
commits = (self.repo.commit(logEntry) for logEntry in self.repo.iter_commits()) commits = (self.repo.commit(logEntry) for logEntry in self.repo.iter_commits())
return (self.to_dict(x) for x in commits) return (self.to_dict(x) for x in commits)
def to_dict(self,commit): def to_dict(self, commit):
"""create a dict out of a commit that is easy to json serialize""" """create a dict out of a commit that is easy to json serialize"""
time_difference = commit.authored_datetime - commit.committed_datetime time_difference = commit.authored_datetime - commit.committed_datetime
return { return {
"author_email" : commit.author.email, "author_email": commit.author.email,
"author_name" : commit.author.name, "author_name": commit.author.name,
"authored_date" : commit.authored_datetime.isoformat(), "authored_date": commit.authored_datetime.isoformat(),
"files": [{"file":file,"changes":changes} for file,changes in commit.stats.files.items()], "files": [
"committed_date" : commit.committed_datetime.isoformat(), {"file": file, "changes": changes}
"committer_email" : commit.committer.email, for file, changes in commit.stats.files.items()
"committer_name" : commit.committer.name, ],
"date_difference_in_seconds" : abs( time_difference.total_seconds() ), "committed_date": commit.committed_datetime.isoformat(),
"encoding" : commit.encoding, "committer_email": commit.committer.email,
"hash" : commit.hexsha, "committer_name": commit.committer.name,
"message" : commit.message , "date_difference_in_seconds": abs(time_difference.total_seconds()),
"summary" : commit.summary, "encoding": commit.encoding,
"size" : commit.size, "hash": commit.hexsha,
"stats_total" : commit.stats.total, "message": commit.message,
"parents" : [parent.hexsha for parent in commit.parents], "summary": commit.summary,
"size": commit.size,
"stats_total": commit.stats.total,
"parents": [parent.hexsha for parent in commit.parents],
} }
@click.command() @click.command()
@click.argument("path", type=click.Path(exists=True), envvar='PWD') @click.argument("path", type=click.Path(exists=True), envvar="PWD")
@click.option("--host") @click.option("--host")
@click.option("--index") @click.option("--index")
@click.option("--port", default=9200) @click.option("--port", default=9200)
@ -52,24 +56,18 @@ def main(path, host, index, port):
exit(1) exit(1)
print("Sending commits from %s to %s on index %s" % (path, host, index)) print("Sending commits from %s to %s on index %s" % (path, host, index))
es = Elasticsearch([ es = Elasticsearch([{"host": host, "port": port}])
{'host': host, 'port': port}
])
for entry in GitLogger(path).log(): for entry in GitLogger(path).log():
try: try:
es.index( es.index(index=index, doc_type="commit", id=entry["hash"], body=entry)
index=index,
doc_type="commit",
id=entry["hash"],
body=entry
)
except Exception as e: except Exception as e:
print(json.dumps(entry)) print(json.dumps(entry))
print(e.info) print(e.info)
exit(1) exit(1)
else: else:
for entry in GitLogger(path).log(): for entry in GitLogger(path).log():
print(json.dumps( entry )) print(json.dumps(entry))
if __name__ == '__main__':
if __name__ == "__main__":
main() main()

View file

@ -1,5 +1,6 @@
from git import Repo from git import Repo
import os import os
repo = Repo("/home/palo/dev/nixpkgs") repo = Repo("/home/palo/dev/nixpkgs")
a = repo.head.log()[0] a = repo.head.log()[0]
current_hash = a.newhexsha current_hash = a.newhexsha
@ -7,7 +8,14 @@ commit = repo.commit(current_hash)
commit.author commit.author
commit.committed_date commit.committed_date
import json import json
json.dumps( { "commit_name" : commit.author.name, "message" : commit.message , "changes": commit.stats.files } )
json.dumps(
{
"commit_name": commit.author.name,
"message": commit.message,
"changes": commit.stats.files,
}
)
commit.committed_date commit.committed_date
commit.committer.email commit.committer.email
commit.parents commit.parents

View file

@ -93,6 +93,11 @@ in
memoryUsage memoryUsage
treefmt
shellcheck
shfmt
black
#gitlog2json #gitlog2json
pciutils pciutils

View file

@ -8,7 +8,7 @@
{ {
flakeIgnore = [ "E265" "E225" "W292" ]; flakeIgnore = [ "E265" "E225" "W292" ];
} }
(lib.fileContents ../../assets/nginx-show-config.sh); (lib.fileContents ../../assets/nginx-show-config.py);
in in
[ [
pkgs.mosh pkgs.mosh

View file

@ -368,7 +368,7 @@ ssh-keygen -t ed25519 -N "" -f /mnt/etc/secrets/initrd/ssh_host_ed25519_key
# Install NixOS # Install NixOS
#PATH="$PATH" NIX_PATH="$NIX_PATH" `which nixos-install` --no-root-passwd --root /mnt --max-jobs 40 #PATH="$PATH" NIX_PATH="$NIX_PATH" `which nixos-install` --no-root-passwd --root /mnt --max-jobs 40
PATH="$PATH" `which nixos-install` --no-root-passwd --root /mnt --max-jobs 40 PATH="$PATH" $( which nixos-install` --no-root-passwd --root /mnt --max-jobs 40 )
umount /mnt/boot-{1,2} umount /mnt/boot-{1,2}
umount /mnt umount /mnt

25
treefmt.toml Normal file
View file

@ -0,0 +1,25 @@
# One CLI to format the code tree - https://github.com/numtide/treefmt
[formatter.nix]
command = "nixpkgs-fmt"
includes = [ "*.nix"]
[formatter.shell]
command = "shfmt"
options = [
"-i",
"2", # indent 2
"-s", # simplify the code
"-w", # write back to the file
]
includes = ["*.sh"]
excludes = ["./scripts/hetzner-dedicated-wipe-and-install-nixos.sh"]
[formatter.shellcheck]
command = "shellcheck"
includes = ["*.sh"]
excludes = ["./scripts/hetzner-dedicated-wipe-and-install-nixos.sh"]
[formatter.python]
command = "black"
includes = ["*.py"]