Bartender.pm 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package Bartender;
  2. use Dancer2;
  3. use Data::Dumper;
  4. use POSIX ();
  5. our $VERSION = '0.1';
  6. get '/' => sub {
  7. send_file '/index.html';
  8. };
  9. =pod
  10. $VAR1 = {
  11. 'projetId' => 'abro-tele2',
  12. 'projetPadPrincipal' => 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Principal/export/txt',
  13. 'projetPadGarde' => 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Garde/export/txt',
  14. 'projetPadAutre1' => '',
  15. 'dossier' => 'abroretention'
  16. };
  17. =cut
  18. get '/shake' => sub {
  19. my %param = params;
  20. my $opt_dossier = $param{dossier};
  21. my $opt_base = $param{projetPadPrincipal};
  22. my $opt_garde = $param{projetPadGarde};
  23. my $opt_projet = $param{projetId};
  24. system("/home/sniperovitch/cocktail/cocktail -d $opt_dossier -b '$opt_base' -g '$opt_garde' -p $opt_projet &");
  25. send_file '/index.html';
  26. };
  27. get '/status' => sub {
  28. my %param = params;
  29. my $opt_dossier = $param{dossier};
  30. my $opt_projet = $param{projetId};
  31. my $compilation_status;
  32. if(-e "/tmp/exegetes/$opt_dossier/$opt_projet.lock") {
  33. $compilation_status = "En cours de compilation...";
  34. }
  35. elsif(-e "/tmp/exegetes/$opt_dossier/$opt_projet.pdf") {
  36. my @stat = stat "/tmp/exegetes/$opt_dossier/$opt_projet.pdf";
  37. my $ctime = $stat[10];
  38. my $date_time = POSIX::strftime("%Y-%m-%d %H:%M:%S", localtime($ctime) );
  39. $compilation_status = $date_time;
  40. }
  41. else {
  42. $compilation_status = "Aucune compilation.";
  43. }
  44. header 'Content-Type' => 'application/json';
  45. return to_json { text => $compilation_status };
  46. };
  47. true;