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,3 +1,5 @@
#!/usr/bin/env bash
set -e set -e
defaultDevice=PCH defaultDevice=PCH
@ -39,8 +41,7 @@ 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
@ -48,21 +49,19 @@ start_jack(){
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
@ -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)
stop_jack
;; ;;
restart) stop_jack ; start_jack restart)
stop_jack
start_jack
;; ;;
*) status_jack *)
status_jack
;; ;;
esac esac

View file

@ -1,15 +1,15 @@
#!/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 "-----------------------"
@ -34,17 +34,15 @@ function stop(){
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

@ -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

@ -26,7 +26,10 @@ class GitLogger:
"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": [
{"file": file, "changes": changes}
for file, changes in commit.stats.files.items()
],
"committed_date": commit.committed_datetime.isoformat(), "committed_date": commit.committed_datetime.isoformat(),
"committer_email": commit.committer.email, "committer_email": commit.committer.email,
"committer_name": commit.committer.name, "committer_name": commit.committer.name,
@ -40,8 +43,9 @@ class GitLogger:
"parents": [parent.hexsha for parent in commit.parents], "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,17 +56,10 @@ 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)
@ -71,5 +68,6 @@ def main(path, host, index, port):
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"]