Skip to content

Commit

Permalink
patch
Browse files Browse the repository at this point in the history
  • Loading branch information
lbr38 committed Dec 26, 2024
1 parent d5bc0b7 commit 7ff9187
Show file tree
Hide file tree
Showing 18 changed files with 465 additions and 273 deletions.
10 changes: 10 additions & 0 deletions www/controllers/Layout/Container/vars/tasks/log.vars.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
$taskController = new \Controllers\Task\Task();
$repoController = new \Controllers\Repo\Repo();
$output = '';
$legacyLog = false;

/**
* Get the log file of the task
Expand All @@ -21,6 +22,7 @@
if (!empty($taskInfo['Logfile']) and file_exists(MAIN_LOGS_DIR . '/' . $taskInfo['Logfile'])) {
$logfile = $taskInfo['Logfile'];
$output = file_get_contents(MAIN_LOGS_DIR . '/' . $logfile);
$legacyLog = true;

// If the task has a json log file (new format)
} else if (file_exists(MAIN_LOGS_DIR . '/' . $taskId . '.json')) {
Expand Down Expand Up @@ -106,14 +108,22 @@
include_once(ROOT . '/views/templates/tasks/' . $rawParams['action'] . '.inc.php');
$output .= ob_get_clean();

/**
* The container which will contain all the steps
*/
$output .= '<div class="steps-container" task-id="' . $taskId . '">';

/**
* Include steps
*/
foreach ($content['steps'] as $stepName => $step) {
ob_start();
include(ROOT . '/views/includes/containers/tasks/log/step.inc.php');
include(ROOT . '/views/includes/containers/tasks/log/step-content.inc.php');
$output .= ob_get_clean();
}

$output .= '</div>';
// If no log file found
} else {
throw new Exception('No log file found for this task.');
Expand Down
4 changes: 2 additions & 2 deletions www/controllers/Logging/Logging.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function generate() : void
}

if (!file_put_contents($this->logFile, json_encode(array('steps' => [])))) {
$this->logController->log('error', 'Task logging', 'Could not create task log file', $this->logFile);
$this->logController->log('error', 'Task logging', 'Could not create task log file ' . $this->logFile);
}
}

Expand All @@ -35,7 +35,7 @@ public function generate() : void
protected function getContent()
{
if (!file_exists($this->logFile)) {
$this->logController->log('error', 'Task logging', 'Task log file not found', $this->logFile);
$this->logController->log('error', 'Task logging', 'Task log file not found ' . $this->logFile);
return [];
}

Expand Down
8 changes: 4 additions & 4 deletions www/controllers/Logging/Step.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function new(string $name, string $title)
];

if (!file_put_contents($this->logFile, json_encode($content))) {
$this->logController->log('error', 'Task logging', 'Could not add new step "' . $name . '" to task log file', $this->logFile);
$this->logController->log('error', 'Task logging', 'Could not add new step "' . $name . '" to task log file ' . $this->logFile);
}

unset($content);
Expand Down Expand Up @@ -56,7 +56,7 @@ public function completed(string|null $message = null)
}

if (!file_put_contents($this->logFile, json_encode($content))) {
$this->logController->log('error', 'Task logging', 'Could not set step "' . $name . '" as completed in task log file', $this->logFile);
$this->logController->log('error', 'Task logging', 'Could not set step "' . $name . '" as completed in task log file ' . $this->logFile);
}

unset($content);
Expand Down Expand Up @@ -97,7 +97,7 @@ public function error(string $message)
}

if (!file_put_contents($this->logFile, json_encode($content))) {
$this->logController->log('error', 'Task logging', 'Could not set step "' . $name . '" as error in task log file', $this->logFile);
$this->logController->log('error', 'Task logging', 'Could not set step "' . $name . '" as error in task log file ' . $this->logFile);
}

unset($content);
Expand All @@ -123,7 +123,7 @@ public function stopped()
$content['steps'][$name]['duration'] = microtime(true) - $content['steps'][$name]['start'];

if (!file_put_contents($this->logFile, json_encode($content))) {
$this->logController->log('error', 'Task logging', 'Could not set step "' . $name . '" as stopped in task log file', $this->logFile);
$this->logController->log('error', 'Task logging', 'Could not set step "' . $name . '" as stopped in task log file ' . $this->logFile);
}

unset($content);
Expand Down
14 changes: 9 additions & 5 deletions www/controllers/Logging/SubStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function new(string $identifier, array $data)
}

if (!file_put_contents($this->logFile, json_encode($content))) {
$this->logController->log('error', 'Task logging', 'Could not add new sub step "' . $identifier . '" to task log file', $this->logFile);
$this->logController->log('error', 'Task logging', 'Could not add new sub step "' . $identifier . '" to task log file ' . $this->logFile);
}

unset($content);
Expand Down Expand Up @@ -65,7 +65,7 @@ public function completed(string|null $message = '')
$content['steps'][$name]['substeps'][$subName]['duration'] = microtime(true) - $content['steps'][$name]['substeps'][$subName]['start'];

if (!file_put_contents($this->logFile, json_encode($content))) {
$this->logController->log('error', 'Task logging', 'Could not set sub step "' . $subName . '" as completed in task log file', $this->logFile);
$this->logController->log('error', 'Task logging', 'Could not set sub step "' . $subName . '" as completed in task log file ' . $this->logFile);
}

unset($content);
Expand Down Expand Up @@ -96,7 +96,7 @@ public function warning(string $message)
$content['steps'][$name]['substeps'][$subName]['duration'] = microtime(true) - $content['steps'][$name]['substeps'][$subName]['start'];

if (!file_put_contents($this->logFile, json_encode($content))) {
$this->logController->log('error', 'Task logging', 'Could not set sub step "' . $subName . '" as warning in task log file', $this->logFile);
$this->logController->log('error', 'Task logging', 'Could not set sub step "' . $subName . '" as warning in task log file ' . $this->logFile);
}

unset($content);
Expand Down Expand Up @@ -125,7 +125,7 @@ public function stopped()
$content['steps'][$name]['substeps'][$subName]['duration'] = microtime(true) - $content['steps'][$name]['substeps'][$subName]['start'];

if (!file_put_contents($this->logFile, json_encode($content))) {
$this->logController->log('error', 'Task logging', 'Could not set sub step "' . $subName . '" as stopped in task log file', $this->logFile);
$this->logController->log('error', 'Task logging', 'Could not set sub step "' . $subName . '" as stopped in task log file ' . $this->logFile);
}

unset($content);
Expand All @@ -136,6 +136,10 @@ public function stopped()
*/
public function output(string $message, string|null $type = null)
{
if (empty($message)) {
return;
}

if (empty($type)) {
$type = 'info';
}
Expand All @@ -156,7 +160,7 @@ public function output(string $message, string|null $type = null)
];

if (!file_put_contents($this->logFile, json_encode($content))) {
$this->logController->log('error', 'Task logging', 'Could not add output to sub step "' . $subName . '" in task log file', $this->logFile);
$this->logController->log('error', 'Task logging', 'Could not add output to sub step "' . $subName . '" in task log file ' . $this->logFile);
}

unset($content);
Expand Down
39 changes: 17 additions & 22 deletions www/controllers/Task/Repo/Metadata/Deb.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Exception;

class Deb
class Deb extends Metadata
{
private $root;
private $repo;
Expand All @@ -13,15 +13,9 @@ class Deb
private $arch;
private $gpgResign = false;
private $aptftparchive = '/usr/bin/apt-ftparchive';
private $logfile;
private $pid;
private $task;

public function __construct()
{
$this->task = new \Controllers\Task\Task(false);
}

public function setRoot(string $root)
{
$this->root = $root;
Expand Down Expand Up @@ -52,11 +46,6 @@ public function setGpgResign(string $gpgResign)
$this->gpgResign = $gpgResign;
}

public function setLogfile(string $logfile)
{
$this->logfile = $logfile;
}

public function setPid(string $pid)
{
$this->pid = $pid;
Expand All @@ -77,7 +66,7 @@ public function create()
/**
* Set task pid to the main pid passed
*/
$this->task->setPid($this->pid);
$this->taskController->setPid($this->pid);

/**
* Check if root path exists
Expand All @@ -93,6 +82,8 @@ public function create()
throw new Exception('Packages architecture(s) must be specified');
}

$this->loggingSubStepController->new('create-metadata', ['title' => 'GENERATING REPOSITORY METADATA']);

/**
* Define directory to create for the repository
*/
Expand Down Expand Up @@ -166,19 +157,20 @@ public function create()
* Create Packages file
*/
$myprocess = new \Controllers\Process('/usr/bin/apt-ftparchive generate ' . $this->root . '/apt-ftparchive.conf');
$myprocess->setBackground(true);
$myprocess->execute();

/**
* Retrieve PID of the launched process
* Then write PID to main PID file
*/
$this->task->addsubpid($myprocess->getPid());
$this->taskController->addsubpid($myprocess->getPid());

/**
* Print output to logfile
* Retrieve output from process
*/
$output = $myprocess->getOutput($this->logfile);
$output = $myprocess->getOutput();

$this->loggingSubStepController->output($output, 'pre');

if ($myprocess->getExitCode() != 0) {
echo '<img src="/assets/icons/error.svg" class="icon margin-left-5 margin-right-5 vertical-align-text-top" /><span class="redtext">failed to generate Packages metadata file</span><br>';
Expand All @@ -192,19 +184,20 @@ public function create()
* Generate Release file
*/
$myprocess = new \Controllers\Process('/usr/bin/apt-ftparchive -c ' . $this->root . '/dist.conf release ' . $this->root . '/dists/' . $this->dist . ' > ' . $this->root . '/dists/' . $this->dist . '/Release');
$myprocess->setBackground(true);
$myprocess->execute();

/**
* Retrieve PID of the launched process
* Then write PID to main PID file
*/
$this->task->addsubpid($myprocess->getPid());
$this->taskController->addsubpid($myprocess->getPid());

/**
* Print output to logfile
* Retrieve output from process
*/
$myprocess->getOutput($this->logfile);
$output = $myprocess->getOutput();

$this->loggingSubStepController->output($output, 'pre');

if ($myprocess->getExitCode() != 0) {
throw new Exception('Failed to generate Release metadata file');
Expand Down Expand Up @@ -243,13 +236,15 @@ public function create()
* Retrieve PID of the launched process
* Then write PID to main PID file
*/
$this->task->addsubpid($myprocess->getPid());
$this->taskController->addsubpid($myprocess->getPid());

if ($myprocess->getExitCode() != 0) {
throw new Exception('Failed to sign Release metadata file');
}

$myprocess->close();

$this->loggingSubStepController->completed();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions www/controllers/Task/Repo/Metadata/Rpm.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function create()
$this->createrepoArgs .= ' --groupfile=' . $this->root . '/comps.xml';
}

$this->loggingSubStepController->new('create-metadata', ['title' => 'CREATING REPOSITORY METADATA']);
$this->loggingSubStepController->new('create-metadata', ['title' => 'GENERATING REPOSITORY METADATA']);

/**
* Create repository metadata
Expand Down Expand Up @@ -140,7 +140,7 @@ public function create()
}
}

$this->loggingSubStepController->completed('Done');
$this->loggingSubStepController->completed();
}

/**
Expand Down Expand Up @@ -183,7 +183,7 @@ public function create()
}
}

$this->loggingSubStepController->completed('Done');
$this->loggingSubStepController->completed();
}
}
}
Loading

0 comments on commit 7ff9187

Please sign in to comment.