1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2019-2020 Matias De lellis <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @author Matias De lellis <[email protected]> |
6
|
|
|
* |
7
|
|
|
* @license GNU AGPL version 3 or any later version |
8
|
|
|
* |
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
12
|
|
|
* License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU Affero General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
namespace OCA\FaceRecognition\Command; |
24
|
|
|
|
25
|
|
|
use Symfony\Component\Console\Command\Command; |
|
|
|
|
26
|
|
|
use Symfony\Component\Console\Helper\Table; |
|
|
|
|
27
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
|
|
|
28
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
|
|
|
29
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
|
|
|
30
|
|
|
|
31
|
|
|
use OCA\FaceRecognition\Model\IModel; |
32
|
|
|
|
33
|
|
|
use OCA\FaceRecognition\Model\ModelManager; |
34
|
|
|
|
35
|
|
|
class SetupCommand extends Command { |
36
|
|
|
|
37
|
|
|
/** @var ModelManager */ |
38
|
|
|
protected $modelManager; |
39
|
|
|
|
40
|
|
|
/** @var OutputInterface */ |
41
|
|
|
protected $logger; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param ModelManager |
45
|
|
|
*/ |
46
|
|
|
public function __construct(ModelManager $modelManager) |
47
|
|
|
{ |
48
|
|
|
parent::__construct(); |
49
|
|
|
|
50
|
|
|
$this->modelManager = $modelManager; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
protected function configure() { |
54
|
|
|
$this |
55
|
|
|
->setName('face:setup') |
56
|
|
|
->setDescription('Download and Setup the model used for the analysis') |
57
|
|
|
->addOption( |
58
|
|
|
'model', |
59
|
|
|
'm', |
60
|
|
|
InputOption::VALUE_OPTIONAL, |
61
|
|
|
'The identifier number of the model to install', |
62
|
|
|
null |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param InputInterface $input |
68
|
|
|
* @param OutputInterface $output |
69
|
|
|
* @return int |
70
|
|
|
*/ |
71
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) { |
72
|
|
|
$this->logger = $output; |
73
|
|
|
|
74
|
|
|
$modelId = $input->getOption('model'); |
75
|
|
|
if (is_null($modelId)) { |
76
|
|
|
$this->logger->writeln('You must indicate the ID of the model to install'); |
77
|
|
|
$this->dumpModels(); |
78
|
|
|
return 0; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$model = $this->modelManager->getModel($modelId); |
82
|
|
|
if (is_null($model)) { |
83
|
|
|
$this->logger->writeln('Invalid model Id'); |
84
|
|
|
return 1; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$modelDescription = $model->getId() . ' (' . $model->getName(). ')'; |
88
|
|
|
|
89
|
|
|
if (!$model->meetDependencies()) { |
90
|
|
|
$this->logger->writeln('You do not meet the dependencies to install the model ' . $modelDescription); |
91
|
|
|
return 1; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
if ($model->isInstalled()) { |
95
|
|
|
$this->logger->writeln('The files of model ' . $modelDescription . ' are already installed'); |
96
|
|
|
$this->modelManager->setDefault($modelId); |
97
|
|
|
$this->logger->writeln('The model ' . $modelDescription . ' was configured as default'); |
98
|
|
|
|
99
|
|
|
return 0; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
$this->logger->writeln('The model ' . $modelDescription . ' will be installed'); |
103
|
|
|
$model->install(); |
104
|
|
|
$this->logger->writeln('Install model ' . $modelDescription . ' successfully done'); |
105
|
|
|
|
106
|
|
|
$this->modelManager->setDefault($modelId); |
107
|
|
|
$this->logger->writeln('The model ' . $modelDescription . ' was configured as default'); |
108
|
|
|
|
109
|
|
|
return 0; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Print list of models |
114
|
|
|
*/ |
115
|
|
|
private function dumpModels() { |
116
|
|
|
$table = new Table($this->logger); |
117
|
|
|
$table->setHeaders(['Id', 'Name', 'Description']); |
118
|
|
|
|
119
|
|
|
$models = $this->modelManager->getAllModels(); |
120
|
|
|
foreach ($models as $model) { |
121
|
|
|
$table->addRow([$model->getId(), $model->getName(), $model->getDescription()]); |
122
|
|
|
} |
123
|
|
|
$table->render(); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
} |
127
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths