feat: adapt planet picture generator

This commit is contained in:
Emmanuel BENOîT 2024-12-31 19:51:45 +01:00
parent aebea3dd7c
commit 4d48fba21b
Signed by: Emmanuel BENOîT
SSH key fingerprint: SHA256:l7PFUUF5TCDsvYeQC9OnTNz08dFY7Fvf4Hv3neIqYpg
2 changed files with 59 additions and 29 deletions

17
Dockerfile.planetgen Normal file
View file

@ -0,0 +1,17 @@
FROM debian:12-slim
ADD ./planetgen /opt/planetgen
RUN <<EOF
set -e
export DEBIAN_FRONTEND=noninteractive
export DEBCONF_NONINTERACTIVE_SEEN=true
apt-get update && apt-get dist-upgrade -uy
apt-get install -y perl povray
mkdir -p /var/spool/pgen/{input,output}
chown -R www-data:www-data /var/spool/pgen
EOF
VOLUME /var/spool/pgen/input /var/spool/pgen/output
ENTRYPOINT ["/opt/planetgen/planetmaker.pl"]

View file

@ -1,45 +1,58 @@
#!/usr/bin/perl
#
# Checks the /tmp/pgen/req-<version>-<start>-<count> files at regular
# Checks the input dir for req-<version>-<start>-<count> files at regular
# intervals and generate planets accordingly.
#
# Syntax : ./planetmaker.pl
#
$outDir = "/mnt/planets";
use strict; use warnings;
close(STDIN);
close(STDERR);
close(STDOUT);
if (fork())
{
exit(0);
}
use FindBin qw($Bin);
require File::Temp;
use File::Temp ();
use File::Temp qw/ :seekable /;
chdir("/opt/planetgen");
mkdir("/tmp/pgen", 01777) if (! -d "/tmp/pgen");
while (1)
{
chop($find = `find /tmp/pgen/ -name 'req-*-*-*'`);
if ($find ne "")
{
@list = split /\n/, $find;
my $outDir = $ENV{PGEN_OUTPUT} || "/tmp/pgen-out";
my $inDir = $ENV{PGEN_INPUT} || "/tmp/pgen-input";
foreach my $name (@list)
{
unlink($name);
my ($junk,$version,$first,$count) = split /-/, $name;
chdir $Bin;
print "Entering main loop\n";
print " Input directory: $inDir\n";
print " Output directory: $outDir\n";
mkdir($inDir, 01777) unless -d $inDir;
mkdir($outDir, 00755) unless -d $outDir;
for ($i=$first;$i<$first+$count;$i++)
{
my $fn = "/tmp/pgen/out.pov";
`./generate.pl $fn`;
`povray +W80 +H80 +O$outDir/$version/l/$i.png -D -V $fn >/dev/null 2>&1`;
`povray +W30 +H30 +O$outDir/$version/s/$i.png -D -V $fn >/dev/null 2>&1`;
unlink($fn);
}
while (1) {
opendir(my $dir, $inDir) or die "Could not open $inDir: $! $_";
my @list = grep {
-f "$inDir/$_" && /^req-[a-z0-9]+-\d+-\d+$/
} readdir $dir;
close $dir;
foreach my $name (@list) {
unlink("$inDir/$name");
my ($junk,$version,$first,$count) = split /-/, $name;
print "Generating planets for $version.\n";
print " First planet $first.\n";
print " $count planets\n";
my $verDir = "$outDir/$version";
foreach my $suffix ("", "/l", "/s") {
my $dir = $verDir . $suffix;
mkdir($dir) unless -d $dir
}
for (my $i=$first;$i<$first+$count;$i++) {
my $fn = File::Temp->new(SUFFIX => '.pov');
`./generate.pl $fn`;
`povray +W80 +H80 +O$verDir/l/$i.png -D -V $fn >/dev/null 2>&1`;
`povray +W30 +H30 +O$verDir/s/$i.png -D -V $fn >/dev/null 2>&1`;
unlink($fn);
}
}
sleep(60);
print "Sleeping...\n";
}