Skip to content

Commit

Permalink
Improve workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
melmothx committed Jan 31, 2024
1 parent 056e360 commit 65305cf
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 17 deletions.
2 changes: 2 additions & 0 deletions lib/AmuseWikiFarm/Controller/BookCovers.pm
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ sub edit :Chained('find') :PathPart('edit') :Args(0) {
my %params = %{$c->request->body_params};
# post request
if (%params) {
# initialize again. This will refresh the template
$bc->initialize;
my $tokens = $bc->parse_template;
my $wd = $bc->working_dir;
# should always be fine.
Expand Down
28 changes: 21 additions & 7 deletions lib/AmuseWikiFarm/Schema/Result/Bookcover.pm
Original file line number Diff line number Diff line change
Expand Up @@ -605,23 +605,30 @@ sub produce_pdf {
my ($self, $logger) = @_;
$logger ||= sub {};
my $tex = $self->write_tex_file;
my $pdf = "$tex";
$pdf =~ s/\.tex/.pdf/;
$self->update({
compiled => undef,
zip_path => undef,
pdf_path => undef,
});
if (-f $pdf) {
log_info { "Removing $pdf" };
unlink $pdf or die $!;
}
$self->convert_images_to_cmyk($logger);

# this should happen only in the jobber, where we fork. But in
# case, return to the original directory.
$self->convert_images_to_cmyk($logger);
my $cwd = getcwd;
my $wd = $self->working_dir;
chdir $wd or die "Cannot chdir into $wd";

my ($in, $out, $err);
my @run = ("xelatex", '-interaction=nonstopmode', $tex->basename);
my $ok = run \@run, \$in, \$out, \$err;
chdir $cwd or die "Cannot chdir back into $cwd";
# log_info { "Compilation: $out $err" };
if ($ok) {
my $pdf = "$tex";
$pdf =~ s/\.tex/.pdf/;
$self->compiled();
$self->pdf_path($pdf);
if ($ok and -f $pdf) {
my $zipdir = Archive::Zip->new;
if ($zipdir->addTree("$wd", "bookcover-" . $wd->basename) == Archive::Zip::AZ_OK) {
my $zipfile = $wd->parent->child("bookcover-" . $wd->basename . ".zip");
Expand Down Expand Up @@ -655,6 +662,13 @@ sub username {
return;
}

sub initialize {
my $self = shift;
$self->create_working_dir;
$self->populate_tokens;
return $self->discard_changes;
}

before delete => sub {
my $self = shift;
if (my $wd = $self->working_dir) {
Expand Down
8 changes: 4 additions & 4 deletions lib/AmuseWikiFarm/Schema/Result/Job.pm
Original file line number Diff line number Diff line change
Expand Up @@ -995,14 +995,14 @@ sub dispatch_job_build_bookcover {
if (my $bc = $self->site->bookcovers->find($self->job_data->{id})) {
$logger->("Producing cover for " . $self->job_data->{id} . "\n");
my $res = $bc->produce_pdf($logger);
Dlog_info { "Result is $_" } $res;
# Dlog_info { "Result is $_" } $res;
if ($res->{success}) {
return sprintf("/bookcovers/bc/%i/download/bc-%i.pdf", $bc->bookcover_id, $bc->bookcover_id);
$logger->("SUCCESS!\n");
}
else {
log_info { "Failure: $res->{stderr} $res->{stdout}" };
$logger->("Failure compiling the cover!\n");
$logger->("FAILURE compiling the cover! Please contact your admin\n");
}
return sprintf("/bookcovers/bc/%i/edit", $bc->bookcover_id);
}
else {
$logger->("Cover data not found!");
Expand Down
6 changes: 1 addition & 5 deletions lib/AmuseWikiFarm/Schema/ResultSet/Bookcover.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ use DateTime;

sub create_and_initalize {
my ($self, $values) = @_;
my $bc = $self->create($values);
$bc->create_working_dir;
$bc->populate_tokens;
$bc->discard_changes;
return $bc;
return $self->create($values)->initialize;
}

sub expired {
Expand Down
17 changes: 16 additions & 1 deletion root/src/bookcovers/edit.tt
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
[% INCLUDE 'include/breadcrumbs.tt' %]

<div class="page-header">
<h1>[% loc('Create a book cover') %]</h1>
<h1>[% loc('Create a book cover') %]
[% IF bookcover.compiled %]
<div class="pull-right" style="font-size:20px">
<a class="bookcover-icon"
title="[% loc('PDF') %]"
href="[% c.uri_for_action('/bookcovers/download', [bookcover.bookcover_id], 'bookcover-' _ bookcover.bookcover_id _ '.pdf') %]">
[% loc('Download') %]
<i class="fa fa-file-pdf-o fa-lg"></i><span class="sr-only">[% loc('PDF') %]</span></a>

<a class="bookcover-icon"
title="[% loc('Zip') %]"
href="[% c.uri_for_action('/bookcovers/download', [bookcover.bookcover_id], 'bookcover-' _ bookcover.bookcover_id _ '.zip') %]">
<i class="fa fa-file-archive-o fa-lg"></i><span class="sr-only">[% loc('Zip') %]</span></a>
</div>
[% END %]
</h1>
</div>
<form action="[% c.uri_for_action('/bookcovers/edit', bookcover.bookcover_id) %]"
method="POST"
Expand Down
2 changes: 2 additions & 0 deletions root/src/bookcovers/listing.tt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<table class="table table-striped table-condensed table-bordered amw-datatable">
<thead>
<tr>
<th>[% loc('ID') %]</th>
<th>[% loc('Created') %]</th>
<th>[% loc('Title') %]</th>
<th>[% loc('User') %]</th>
Expand All @@ -28,6 +29,7 @@
<tbody>
[% FOREACH bc IN bookcovers %]
<tr>
<td>[% bc.bookcover_id | html %]</td>
<td>[% bc.created | html %]</td>
<td>[% bc.title | html %]</td>
<td>
Expand Down

0 comments on commit 65305cf

Please sign in to comment.