From 036e05c4d89f224e71e07f6d43154d63cbe85e69 Mon Sep 17 00:00:00 2001 From: Malte Tammena Date: Wed, 22 Dec 2021 21:37:23 +0100 Subject: [PATCH] Clean up some more --- README.md | 5 +- flake.nix | 491 +++++++++++++++++++------------------- malte/colors.nix | 1 + malte/home.nix | 1 - malte/kakoune.nix | 2 +- malte/yubikey.pub | 1 + scripts/hwp2021pizzazz.py | 169 ------------- 7 files changed, 244 insertions(+), 426 deletions(-) create mode 100644 malte/yubikey.pub delete mode 100755 scripts/hwp2021pizzazz.py diff --git a/README.md b/README.md index 51254c8..52f5c40 100644 --- a/README.md +++ b/README.md @@ -1,4 +1 @@ -# Nix config - -## Don't make it public! -- hwp2021pizzazz not public +# My NixOS configurations diff --git a/flake.nix b/flake.nix index 1cc2bb5..cf4b79c 100644 --- a/flake.nix +++ b/flake.nix @@ -32,247 +32,110 @@ "fend" = { url = "github:MalteT/fend/flake"; }; }; - outputs = { self, nixpkgs, nixos-hardware, home-manager, ... }@inputs: - let - publicSshKey = - "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDXnYMJtwgvSNpjysKzvRCjzyyQRB4yDtzynD7c5ALDZfRHvrgGQS11vk96ExClo66ll3vrFci5mBmGJf4/+yPBb3qiiovEHobjh5nIDHXYTg7tJDHivKIMQ3w8DmZwBKSLFlsH/UZe8NJVGrGRHGofWnTY/yw/FdbAkaKqvF/V+WGP7kR+dQ1pIqXXpP3phAu0WfO+E2838XxHAxLtm35GkE40GCX9dhXmjurxCeTSaJE6OYQ4/+z73fOZc1ebV/Ze6UZsGhOtzJPBIH19Ft0v9x86KoZabqgK3KDSHn9QKcM+Mm7o3tOthfQPlg1tCoxGueDJFI/0+AyjwBmQ1CUvNXpfmL4NE+6GRwRfZNsWoW0nPmC1B/c3rWk+JXYsxGQhvVeDk+1HXCFKghdPTSgpESua03A4UqLNadERYC9s2Q5TzSYQsV/8fpg4gCxlVRl/g1aUvbaCL09jmUkDJ4i36X+g8rvux5Q2CTpskLuhHeFVcC4/c1XXF+cJTwl1GjppEL0JFKgcjIwlyE8neR4PVlOq3UQqZdZEvzZigaLxtpwZMKNGhdIqS2/qqo/LlJ66/Y7TohimhsCRyHHqbf85Cha1z0Ct+9GtTdn9hpeC6Sb2Et+iN4gxdm+SWqPybZipeBL7b+ir5Ssxq1vIf/sbqKh7Kz699dwKSeRaAmJiew== openpgp:0xC43C0C72"; + outputs = { self, nixpkgs, nixos-hardware, home-manager, ... }@inputs: { - in rec { + colmena = { + meta = { nixpkgs = import nixpkgs { system = "x86_64-linux"; }; }; - colmena = { - meta = { - nixpkgs = import nixpkgs { system = "x86_64-linux"; }; - machinesFile = ./build-machines; - }; - - helix-texta = { name, nodes, pkgs, ... }: { - imports = [ self.nixosModules.helix-texta ]; - config.deployment = { - allowLocalDeployment = true; - targetHost = null; - }; - }; - - achatina-fulica = { ... }: { - imports = [ self.nixosModules.achatina-fulica ]; - config.deployment = { - targetHost = "cal.tammena.rocks"; - targetUser = "root"; - }; - }; - - cornu-aspersum = { ... }: { - imports = [ self.nixosModules.cornu-aspersum ]; - config.deployment = { - targetHost = "ccqcraft.de"; - targetUser = "root"; - }; - }; - - elysia-clarki = { ... }: { - imports = [ self.nixosModules.elysia-clarki ]; - config.deployment = { - targetHost = "elysia-clarki"; - targetUser = "root"; - }; + helix-texta = { name, nodes, pkgs, ... }: { + imports = [ self.nixosModules.helix-texta ]; + config.deployment = { + allowLocalDeployment = true; + targetHost = null; }; }; - nixosModules = { - helix-texta = { pkgs, config, ... }: { - imports = [ - ./hosts/helix-texta.nix - ./modules/light-actkbd.nix - ./modules/scanner.nix - self.nixosModules.thinkpad-p1-gen3 - home-manager.nixosModules.home-manager - self.nixosModules.home-manager - self.nixosModules.x86_64-linux-basics - ]; + achatina-fulica = { ... }: { + imports = [ self.nixosModules.achatina-fulica ]; + config.deployment = { + targetHost = "cal.tammena.rocks"; + targetUser = "root"; + }; + }; - config = { - nix = { - # add binary caches - binaryCachePublicKeys = [ - #"elysia-clarki:aGVlotez1OXr8OHYZxgw+LH93sJEVzrKIS0aoVfKtpc=" - "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" - "nixpkgs-wayland.cachix.org-1:3lwxaILxMRkVhehr5StQprHdEo4IrE8sRho9R9HOLYA=" - ]; - binaryCaches = nixpkgs.lib.mkForce [ - #"http://cache.home.dyn.tammena.rocks" - "https://cache.nixos.org" - "https://nixpkgs-wayland.cachix.org" - ]; - }; + cornu-aspersum = { ... }: { + imports = [ self.nixosModules.cornu-aspersum ]; + config.deployment = { + targetHost = "ccqcraft.de"; + targetUser = "root"; + }; + }; - environment.systemPackages = - [ inputs.colmena.packages.${config.nixpkgs.system}.colmena ]; + elysia-clarki = { ... }: { + imports = [ self.nixosModules.elysia-clarki ]; + config.deployment = { + targetHost = "elysia-clarki"; + targetUser = "root"; + }; + }; + }; - # Overwrite basics - services.openssh.enable = false; - programs.mosh.enable = false; + nixosModules = { + helix-texta = { pkgs, config, ... }: { + imports = [ + ./hosts/helix-texta.nix + ./modules/light-actkbd.nix + ./modules/scanner.nix + self.nixosModules.thinkpad-p1-gen3 + home-manager.nixosModules.home-manager + self.nixosModules.home-manager + self.nixosModules.x86_64-linux-basics + ]; - # Overlays only relevant to my primary laptop - nixpkgs.overlays = [ - inputs.nixpkgs-wayland.overlay - inputs.fenix.overlay - (import ./overlays/sane-backends.nix) - (import ./overlays/logisim.nix) + config = { + nix = { + # add binary caches + binaryCachePublicKeys = [ + "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" + "nixpkgs-wayland.cachix.org-1:3lwxaILxMRkVhehr5StQprHdEo4IrE8sRho9R9HOLYA=" + ]; + binaryCaches = nixpkgs.lib.mkForce [ + "https://cache.nixos.org" + "https://nixpkgs-wayland.cachix.org" ]; }; - }; - achatina-fulica = { pkgs, ... }: { - imports = [ - self.nixosModules.x86_64-linux-basics - inputs.glados.nixosModules.glados - ./hosts/achatina-fulica.nix - ./hardware/netcup-minimal.nix - ./modules/nginx-reverse-proxy.nix - ./modules/radicale.nix - ./modules/grafana.nix + environment.systemPackages = + [ inputs.colmena.packages.${config.nixpkgs.system}.colmena ]; + + # Overwrite basics + services.openssh.enable = false; + programs.mosh.enable = false; + + # Overlays only relevant to my primary laptop + nixpkgs.overlays = [ + inputs.nixpkgs-wayland.overlay + inputs.fenix.overlay + (import ./overlays/sane-backends.nix) + (import ./overlays/logisim.nix) ]; }; - - cornu-aspersum = { pkgs, ... }: { - imports = [ - self.nixosModules.x86_64-linux-basics - #inputs.glados.nixosModules.glados - ./hosts/cornu-aspersum.nix - ./hardware/netcup-rs-2000-g9.nix - ./modules/nginx-reverse-proxy.nix - ./modules/ccqcraft.nix - #./modules/radicale.nix - #./modules/grafana.nix - ]; - }; - - elysia-clarki = { pkgs, ... }: { - imports = [ - self.nixosModules.x86_64-linux-basics - ./hosts/elysia-clarki.nix - ./hardware/intel-nuc.nix - ./modules/local-build-service.nix - ./modules/nginx-reverse-proxy.nix - ./modules/binary-cache.nix - ./modules/ccqcraft-backups.nix - ]; - - config = { - # Override kernel version for zfs - boot.kernelPackages = pkgs.linuxPackages_5_10; - }; - }; }; - nixosModules.thinkpad-p1-gen3 = { pkgs, config, lib, ... }: { + achatina-fulica = { ... }: { imports = [ - nixos-hardware.nixosModules.common-cpu-intel - nixos-hardware.nixosModules.common-gpu-nvidia - nixos-hardware.nixosModules.common-pc-laptop - nixos-hardware.nixosModules.common-pc-laptop-ssd - nixos-hardware.nixosModules.common-pc-laptop-acpi_call - ./hardware/thinkpad-p1-gen3.nix + self.nixosModules.x86_64-linux-basics + inputs.glados.nixosModules.glados + ./hosts/achatina-fulica.nix + ./hardware/netcup-minimal.nix + ./modules/nginx-reverse-proxy.nix + ./modules/radicale.nix + ./modules/grafana.nix ]; }; - homeManagerConfigurations.malte = - home-manager.lib.homeManagerConfiguration { - system = "x86_64-linux"; - username = "malte"; - configuration = ./malte/home.nix; - homeDirectory = "/home/malte"; - }; - - nixosModules.home-manager = { pkgs, ... }: { - home-manager.verbose = true; - home-manager.useGlobalPkgs = true; - home-manager.useUserPackages = true; - home-manager.users.malte.imports = [ ./malte/home.nix ]; - }; - - # Necessary for flakes to work - nixosModules.nixUnstable = { pkgs, ... }: { - nix.registry.nixpkgs.flake = nixpkgs; - nix.package = pkgs.nixUnstable; - nix.extraOptions = '' - experimental-features = nix-command flakes - ''; - nixpkgs.overlays = [ (self: super: { nix = super.nixUnstable; }) ]; - }; - - # Some basics that every machine should have - nixosModules.x86_64-linux-basics = { pkgs, ... }: { + cornu-aspersum = { ... }: { imports = [ - inputs.custom-udev-rules.nixosModule - inputs.sops-nix.nixosModules.sops - self.nixosModules.nixUnstable - ./modules/neovim.nix - ]; - # Basic system things - system.configurationRevision = pkgs.lib.mkIf (self ? rev) self.rev; - nixpkgs.config = { - allowUnfree = true; - joypixels.acceptLicense = true; - }; - hardware.enableAllFirmware = true; - hardware.enableRedistributableFirmware = true; - # Make sure that I can log in - users.users.root = { openssh.authorizedKeys.keys = [ publicSshKey ]; }; - # Basic packages - environment.systemPackages = with pkgs; [ git sops htop ]; - # Enable mosh for some SSH superpower - programs.mosh.enable = pkgs.lib.mkDefault true; - services.openssh.enable = pkgs.lib.mkDefault true; - # My timezone - time.timeZone = "Europe/Berlin"; - # Default locale on all systems - i18n.defaultLocale = "en_US.UTF-8"; - # Some boot defaults - boot.kernelPackages = pkgs.lib.mkDefault pkgs.linuxPackages_latest; - boot.loader.timeout = pkgs.lib.mkDefault 1; - boot.loader.systemd-boot.configurationLimit = 50; - # This is set explicitly in all configurations, let's just do it here - networking.useDHCP = false; - # Add some useful overlays - nixpkgs.overlays = [ - (self: super: { - # Add FiraCode as a package, but use NerdFonts - firaCodeNerd = super.nerdfonts.override { fonts = [ "FiraCode" ]; }; - # Add the emulator - "2a-emulator" = - inputs.emulator-2a.packages.x86_64-linux."2a-emulator"; - # Add my mensa tool - mensa = inputs.mensa.packages.x86_64-linux.mensa; - fend = inputs.fend.packages.x86_64-linux.fend; - }) - # Some program adjustments - (import ./overlays/cataclysm-dda.nix) + self.nixosModules.x86_64-linux-basics + ./hosts/cornu-aspersum.nix + ./hardware/netcup-rs-2000-g9.nix + ./modules/nginx-reverse-proxy.nix + ./modules/ccqcraft.nix ]; }; - # My thinkpad P1 - nixosConfigurations.helix-texta = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - modules = [ self.nixosModules.helix-texta ]; - }; - - # Currently hosted by NetCup - nixosConfigurations.achatina-fulica = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - modules = [ self.nixosModules.achatina-fulica ]; - }; - - # Currently hosted by NetCup (mostly Minecraft server) - nixosConfigurations.cornu-aspersum = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - modules = [ self.nixosModules.cornu-aspersum ]; - }; - - # Server @home - nixosConfigurations.elysia-clarki = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - modules = [ + elysia-clarki = { pkgs, ... }: { + imports = [ self.nixosModules.x86_64-linux-basics ./hosts/elysia-clarki.nix ./hardware/intel-nuc.nix @@ -280,42 +143,168 @@ ./modules/nginx-reverse-proxy.nix ./modules/binary-cache.nix ./modules/ccqcraft-backups.nix + ]; - ({ pkgs, ... }: { - # Override kernel version for zfs - boot.kernelPackages = pkgs.linuxPackages_5_10; - }) + config = { + # Override kernel version for zfs + boot.kernelPackages = pkgs.linuxPackages_5_10; + }; + }; + }; + + nixosModules.thinkpad-p1-gen3 = { ... }: { + imports = [ + nixos-hardware.nixosModules.common-cpu-intel + nixos-hardware.nixosModules.common-gpu-nvidia + nixos-hardware.nixosModules.common-pc-laptop + nixos-hardware.nixosModules.common-pc-laptop-ssd + nixos-hardware.nixosModules.common-pc-laptop-acpi_call + ./hardware/thinkpad-p1-gen3.nix + ]; + }; + + homeManagerConfigurations.malte = + home-manager.lib.homeManagerConfiguration { + system = "x86_64-linux"; + username = "malte"; + configuration = ./malte/home.nix; + homeDirectory = "/home/malte"; + }; + + nixosModules.home-manager = { ... }: { + home-manager.verbose = true; + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.users.malte.imports = [ ./malte/home.nix ]; + }; + + # Necessary for flakes to work + nixosModules.nixUnstable = { pkgs, ... }: { + nix.registry.nixpkgs.flake = nixpkgs; + nix.package = pkgs.nixUnstable; + nix.extraOptions = '' + experimental-features = nix-command flakes + ''; + nixpkgs.overlays = [ (self: super: { nix = super.nixUnstable; }) ]; + }; + + # Some basics that every machine should have + nixosModules.x86_64-linux-basics = { pkgs, ... }: { + imports = [ + inputs.custom-udev-rules.nixosModule + inputs.sops-nix.nixosModules.sops + self.nixosModules.nixUnstable + ./modules/neovim.nix + ]; + # Basic system things + system.configurationRevision = pkgs.lib.mkIf (self ? rev) self.rev; + nixpkgs.config = { + allowUnfree = true; + joypixels.acceptLicense = true; + }; + hardware.enableAllFirmware = true; + hardware.enableRedistributableFirmware = true; + # Make sure that I can log in + users.users.root = { + openssh.authorizedKeys.keyFiles = [ ./malte/yubikey.pub ]; + }; + # Basic packages + environment.systemPackages = with pkgs; [ git sops htop ]; + # Enable mosh for some SSH superpower + programs.mosh.enable = pkgs.lib.mkDefault true; + services.openssh.enable = pkgs.lib.mkDefault true; + # My timezone + time.timeZone = "Europe/Berlin"; + # Default locale on all systems + i18n.defaultLocale = "en_US.UTF-8"; + # Some boot defaults + boot.kernelPackages = pkgs.lib.mkDefault pkgs.linuxPackages_latest; + boot.loader.timeout = pkgs.lib.mkDefault 1; + boot.loader.systemd-boot.configurationLimit = 50; + # This is set explicitly in all configurations, let's just do it here + networking.useDHCP = false; + # Add some useful overlays + nixpkgs.overlays = [ + (self: super: { + # Add FiraCode as a package, but use NerdFonts + firaCodeNerd = super.nerdfonts.override { fonts = [ "FiraCode" ]; }; + # Add the emulator + "2a-emulator" = + inputs.emulator-2a.packages.x86_64-linux."2a-emulator"; + # Add my mensa tool + mensa = inputs.mensa.packages.x86_64-linux.mensa; + fend = inputs.fend.packages.x86_64-linux.fend; + }) + # Some program adjustments + (import ./overlays/cataclysm-dda.nix) + ]; + }; + + # My thinkpad P1 + nixosConfigurations.helix-texta = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ self.nixosModules.helix-texta ]; + }; + + # Currently hosted by NetCup + nixosConfigurations.achatina-fulica = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ self.nixosModules.achatina-fulica ]; + }; + + # Currently hosted by NetCup (mostly Minecraft server) + nixosConfigurations.cornu-aspersum = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ self.nixosModules.cornu-aspersum ]; + }; + + # Server @home + nixosConfigurations.elysia-clarki = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + self.nixosModules.x86_64-linux-basics + ./hosts/elysia-clarki.nix + ./hardware/intel-nuc.nix + ./modules/local-build-service.nix + ./modules/nginx-reverse-proxy.nix + ./modules/binary-cache.nix + ./modules/ccqcraft-backups.nix + + ({ pkgs, ... }: { + # Override kernel version for zfs + boot.kernelPackages = pkgs.linuxPackages_5_10; + }) + ]; + }; + + devShell.x86_64-linux = + let pkgs = import nixpkgs { system = "x86_64-linux"; }; + in pkgs.mkShell { + packages = [ + (with pkgs; + writeScriptBin "rebuild" '' + #!${stdenv.shell} + if [ -z $1 ]; then + echo "Need 'switch|boot|...'" + exit 1 + fi + + today=`${coreutils}/bin/date +%Y-%m-%d` + branch=`${git}/bin/git branch --show-current` + rev=`${git}/bin/git log -1 --format=%h` + dirty=`${git}/bin/git diff --quiet || echo '~'` + + NIXOS_LABEL_VERSION=$today-$branch-$rev$dirty + + # Extract build secrets + echo Extracting build secrets.. + ${sops}/bin/sops --extract '["multimc-client-id"]' -d secrets/secrets.yaml > build-secrets/multimc-client-id + + sudo ${nixos-rebuild}/bin/nixos-rebuild $1 --flake . + '') + inputs.colmena.packages.x86_64-linux.colmena ]; }; - devShell.x86_64-linux = - let pkgs = import nixpkgs { system = "x86_64-linux"; }; - in pkgs.mkShell { - packages = [ - (with pkgs; - writeScriptBin "rebuild" '' - #!${stdenv.shell} - if [ -z $1 ]; then - echo "Need 'switch|boot|...'" - exit 1 - fi - - today=`${coreutils}/bin/date +%Y-%m-%d` - branch=`${git}/bin/git branch --show-current` - rev=`${git}/bin/git log -1 --format=%h` - dirty=`${git}/bin/git diff --quiet || echo '~'` - - NIXOS_LABEL_VERSION=$today-$branch-$rev$dirty - - # Extract build secrets - echo Extracting build secrets.. - ${sops}/bin/sops --extract '["multimc-client-id"]' -d secrets/secrets.yaml > build-secrets/multimc-client-id - - sudo ${nixos-rebuild}/bin/nixos-rebuild $1 --flake . - '') - inputs.colmena.packages.x86_64-linux.colmena - ]; - }; - - }; + }; } diff --git a/malte/colors.nix b/malte/colors.nix index 18f696b..39a4e8f 100644 --- a/malte/colors.nix +++ b/malte/colors.nix @@ -121,5 +121,6 @@ in { secondary = "458588"; warn = "FE8019"; error = "CC241D"; + yellow = "D79921"; }; } diff --git a/malte/home.nix b/malte/home.nix index cd53a2a..5b5d867 100644 --- a/malte/home.nix +++ b/malte/home.nix @@ -54,7 +54,6 @@ in { (fixGdk "losslesscut" losslesscut-bin) (fixGdk "skypeforlinux" skype) (pkgs.callPackage ../pkgs/2i-emulator.nix { }) - (script "hwp2021pizzazz" ../scripts/hwp2021pizzazz.py) (fenix.latest.withComponents [ "cargo" "clippy" diff --git a/malte/kakoune.nix b/malte/kakoune.nix index d33784b..e44d5b9 100644 --- a/malte/kakoune.nix +++ b/malte/kakoune.nix @@ -17,7 +17,7 @@ ]; keyMappings = [ - { #Enter LSP Usermode + { # Enter LSP Usermode docstring = "LSP mode"; mode = "user"; key = "l"; diff --git a/malte/yubikey.pub b/malte/yubikey.pub new file mode 100644 index 0000000..e4b2444 --- /dev/null +++ b/malte/yubikey.pub @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDXnYMJtwgvSNpjysKzvRCjzyyQRB4yDtzynD7c5ALDZfRHvrgGQS11vk96ExClo66ll3vrFci5mBmGJf4/+yPBb3qiiovEHobjh5nIDHXYTg7tJDHivKIMQ3w8DmZwBKSLFlsH/UZe8NJVGrGRHGofWnTY/yw/FdbAkaKqvF/V+WGP7kR+dQ1pIqXXpP3phAu0WfO+E2838XxHAxLtm35GkE40GCX9dhXmjurxCeTSaJE6OYQ4/+z73fOZc1ebV/Ze6UZsGhOtzJPBIH19Ft0v9x86KoZabqgK3KDSHn9QKcM+Mm7o3tOthfQPlg1tCoxGueDJFI/0+AyjwBmQ1CUvNXpfmL4NE+6GRwRfZNsWoW0nPmC1B/c3rWk+JXYsxGQhvVeDk+1HXCFKghdPTSgpESua03A4UqLNadERYC9s2Q5TzSYQsV/8fpg4gCxlVRl/g1aUvbaCL09jmUkDJ4i36X+g8rvux5Q2CTpskLuhHeFVcC4/c1XXF+cJTwl1GjppEL0JFKgcjIwlyE8neR4PVlOq3UQqZdZEvzZigaLxtpwZMKNGhdIqS2/qqo/LlJ66/Y7TohimhsCRyHHqbf85Cha1z0Ct+9GtTdn9hpeC6Sb2Et+iN4gxdm+SWqPybZipeBL7b+ir5Ssxq1vIf/sbqKh7Kz699dwKSeRaAmJiew== openpgp:0xC43C0C72 diff --git a/scripts/hwp2021pizzazz.py b/scripts/hwp2021pizzazz.py deleted file mode 100755 index 1e5c57c..0000000 --- a/scripts/hwp2021pizzazz.py +++ /dev/null @@ -1,169 +0,0 @@ -#! /usr/bin/env nix-shell -#! nix-shell -i python -p python39 p7zip - -# Execute in a directory of your choice, like this: -# > hwp2021pizzazz.py downloaded_all_submissions_from_moodle.zip - -CORRECT_PDF = "Korrektur.pdf" -DONE_PDF = "Korrektur-export.pdf" -TARGET = "target" -GROUPS = { - "44": ["Gerhard Wilhelm", "Paul Quast"], - "45": ["Moussa Rais", "mohamad jaara"], - "46": ["Raoul Kirchner", "Paul Bachmann"], - "47": ["Dominik Masson", "Christopher Helbig"], - "48": ["Mats Brockmann", "Max Martin Freiberg"], - "49": ["Ahmad Alahmad", "Leo Dirk Stiebling"], - "50": ["Dorjan Domi", "Matthias Schütze - Stuhr"], - "51": ["Phil-Alexander Hofmann", "Leo Haßbargen"], - "52": ["Tom Wawerek", "Mose Schmiedel"], - "53": ["Cedric Klaus", "Martin Götze"], - "54": ["Dharshan Seesurn", "Anna Matusevich"], - "55": ["Yaowei Zhang", "Yuechunqiu Wu"], - "56": ["Mahmoud Sheikh-bakri", "Christopher Käding"], - "57": ["Melanie Qaiser", "William Albert"], - "58": ["Nick Meier", "Marco Zwillus"], - "59": ["Patric Riedel", "Rodrigue Ekango"], -} - -import sys -import os -import pathlib -import subprocess -import shutil - -def run(*args, cwd=None): - res = subprocess.run(list(args), cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - if res.returncode != 0: - print(*args, "failed with", res.returncode, "..") - print("-.- STDOUT -.-") - print(res.stdout) - print("-.- STDERR -.-") - print(res.stderr) - sys.exit(2) - -def remove_tree(path): - shutil.rmtree(path) - -def flatten(l): - new = [] - for ll in l: - for el in ll: - new.append(el) - return new - -def delete_garbage_dirs(): - print("Removing much stuff (garbage and your home directory)..") - dirs = os.listdir(TARGET) - names = flatten(GROUPS.values()) - for d in dirs: - found = False - for name in names: - if name in d: - found = True - break - if not found: - remove_tree(os.path.join(TARGET, d)) - - -def unzip_main(main_file): - print("Unzipping main file..") - os.mkdir(TARGET) - extract_archive(main_file, TARGET) - - -def extract_archive(src, dst): - shutil.unpack_archive(src, dst) - #patoolib.extract_archive(src, outdir=dst) - - -def print_submission_info(): - print("") - for group, usernames in GROUPS.items(): - # Submission exists? - group_path = os.path.join(TARGET, group) - submissions = len(os.listdir(group_path)) - if submissions == 0: - submission_reaction = "nope" - elif submissions == 1: - submission_reaction = "YEA!" - else: - submission_reaction = "wHaT" - # Corrected? - status = 0 - for submission in os.listdir(group_path): - submission_path = os.path.join(group_path, submission) - if os.path.exists(os.path.join(submission_path, DONE_PDF)): - status = 2 - elif os.path.exists(os.path.join(submission_path, CORRECT_PDF)) and status < 1: - status = 1 - if status == 0: - print('{}: {} [ ]'.format(group, submission_reaction)) - elif status == 1: - print('{}: {} [~]'.format(group, submission_reaction)) - elif status == 2: - print('{}: {} [X]'.format(group, submission_reaction)) - - -def sort_into_group_dirs(): - print("Shuffling submissions..") - dirs = os.listdir(TARGET) - for group, usernames in GROUPS.items(): - group_folder = os.path.join(TARGET, group) - os.mkdir(group_folder) - for d in dirs: - d_path = os.path.join(TARGET, d) - for username in usernames: - if username in d: - shutil.move(d_path, group_folder) - - -def extract_submissions(): - print("Unzipping student presents..") - for group in GROUPS.keys(): - group_path = os.path.join(TARGET, group) - for submission in os.listdir(group_path): - sub_path = os.path.join(group_path, submission) - for archive in os.listdir(sub_path): - archive_path = os.path.join(sub_path, archive) - extract_archive(archive_path, sub_path) - - -def copy_pdfs_for_correction(): - print("Finding the pdfs..") - for group in GROUPS.keys(): - group_path = os.path.join(TARGET, group) - for submission in os.listdir(group_path): - sub_path = os.path.join(group_path, submission) - pdfs = list(pathlib.Path(sub_path).glob("**/*.pdf")) - if len(pdfs) == 1: - shutil.copy(pdfs[0], os.path.join(sub_path, CORRECT_PDF)) - -def extractfiles(zipname, output_dir): - """Extract files with 7z utils.""" - res = subprocess.run(["7z", "x", "-aoa", "-bd", zipname, f"-o{output_dir}"], stderr=subprocess.STDOUT, stdout=subprocess.PIPE) - return(res) - - -def register_extensions(): - """Register additionnal archive formats supported by 7zip in shutil.""" - shutil.register_unpack_format('rar', ['.rar', '.RAR'], extractfiles) - shutil.register_unpack_format('7z', ['.7z', '.7Z'], extractfiles) - - -if not os.path.exists(TARGET): - if len(sys.argv) >= 2: - register_extensions() - main_file = sys.argv[1] - unzip_main(main_file) - delete_garbage_dirs() - sort_into_group_dirs() - extract_submissions() - copy_pdfs_for_correction() - else: - print("Give me much main zip.. moron!") - sys.exit(1) -else: - print("Skipping the zipping so no data lost for hooman!") - -print_submission_info()