#! /usr/bin/perl ### ### Setup program for Odin services ### ### (c) 2015 Mark Wooding ### ###----- Licensing notice --------------------------------------------------- ### ### This file is part of the `odin.gg' service, `odin-cgi'. ### ### `odin-cgi' is free software; you can redistribute it and/or modify ### it under the terms of the GNU Affero General Public License as ### published by the Free Software Foundation; either version 3 of the ### License, or (at your option) any later version. ### ### `odin-cgi' is distributed in the hope that it will be useful, ### but WITHOUT ANY WARRANTY; without even the implied warranty of ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ### GNU Affero General Public License for more details. ### ### You should have received a copy of the GNU Affero General Public ### License along with `odin-cgi'; if not, see ### . use lib "lib"; use Odin; my $db = Odin::open_db; my %newlang, %oldlang; open my $fh, "-|", "highlight", "-p" or die "highlight: $!"; while (<$fh>) { my ($descr, $lang) = /^(.*\S)\s*:\s*(\S+)(?:\s.*|)$/; next if !defined $lang or $lang eq "txt"; $newlang{"hl:$lang"} = $descr; } close $fh or die "close highlight: $! $?"; $newlang{"txt"} = "Plain text"; $newlang{"md"} = "Markdown"; Odin::xact { my $h = $db->selectall_hashref ("SELECT lang, descr FROM odin_pastebin_lang", "lang"); for my $k (keys %$h) { $oldlang{$k} = $h->{$k}{descr}; } for my $lang (keys %oldlang) { if (!exists $newlang{$lang}) { print ";; delete stale language `$lang' (`$oldlang{$lang}')\n"; $db->do("DELETE FROM odin_pastebin_lang WHERE lang = ?", undef, $lang); } } for my $lang (keys %newlang) { if (!exists $oldlang{$lang}) { print ";; insert new language `$lang' (`$newlang{$lang}')\n"; $db->do("INSERT INTO odin_pastebin_lang (lang, descr) VALUES (?, ?)", undef, $lang, $newlang{$lang}); } elsif ($oldlang{$lang} ne $newlang{$lang}) { print ";; change description for `$lang' ", "(`$oldlang{$lang}' -> `$newlang{$lang}')\n"; $db->do("UPDATE odin_pastebin_lang SET descr = ? WHERE lang = ?", undef, $newlang{$lang}, $lang); } } } $db;