1
0
mirror of https://github.com/ToxicCrack/PrintABrick.git synced 2025-05-18 13:10:08 -07:00

Update readme and commands

This commit is contained in:
David Hübner 2017-05-28 19:36:00 +02:00
parent 124403a4b5
commit f4a472998b
4 changed files with 86 additions and 57 deletions

View File

@ -4,7 +4,8 @@ A Symfony project
## Install ## Install
### System requirements ### System requirements
* PHP needs to be a minimum version of PHP 5.5.9
* PHP needs to be a minimum version of PHP 7.0
* PHP Extensions * PHP Extensions
* FTP * FTP
* SOAP * SOAP
@ -12,12 +13,21 @@ A Symfony project
* PDO * PDO
* Zip * Zip
* *date.timezone* setting set in *php.ini* * *date.timezone* setting set in *php.ini*
* LDView OSMesa >= 4.2.1 [source](https://tcobbs.github.io/ldview/).
You can check if your system meets requirements by running `$ bin/symfony_requirements` You can check if your system meets requirements by running `$ bin/symfony_requirements`
For full requirements see Symfony 3.2 [docs](http://symfony.com/doc/3.2/reference/requirements.html). For full requirements see Symfony 3.2 [docs](http://symfony.com/doc/3.2/reference/requirements.html).
#### Required
* Elasticsearch
Instructions for installing and deploying Elasticsearch may be found [here](https://www.elastic.co/downloads/elasticsearch).
* POV-Ray
* stl2pov [source](http://www.povray.org/).
* ADMesh [source](https://github.com/rsmith-nl/stltools/releases/tag/3.3).
* LDView OSMesa >= 4.2.1 [source](https://tcobbs.github.io/ldview/).
### Installing ### Installing
#### Back-end #### Back-end
@ -26,12 +36,26 @@ For full requirements see Symfony 3.2 [docs](http://symfony.com/doc/3.2/referenc
#### Front-end #### Front-end
1. Install dependencies via [npm](https://www.npmjs.com/), `$ npm install` 1. Install dependencies via [npm](https://www.npmjs.com/), `$ npm install`
2. Compile assets by running [Gulp](http://gulpjs.com/), `$ gulp` 2. Install bower dependencies via [bower](https://bower.io), `$ bower install`
3. Compile assets by running [Gulp](http://gulpjs.com/), `$ gulp`
#### Database #### Initialization
##### Setup database
1. Set application parameters in *app/config/parameters.yml* 1. Set application parameters in *app/config/parameters.yml*
2. Generate an empty database by running command (if it does not yet exist) `$ php bin/console doctrine:database:create` 2. Generate an empty database by running command (if it does not yet exist) `$ bin/console doctrine:database:create`
3. Run doctrine migrations by running command`$ bin/console doctrine:migrations:migrate` 3. Create database tables/schema by running command`$ bin/console doctrine:schema:create`
3. Load LDraw models into database by running commad `$ php bin/console app:load:models <ldraw_dir> [--all] [--file=FILE] [--update]` 4. Load database fixtures `$ bin/console doctrine:fixtures:load`
4. Load Rebrickable data into database by running command `$ php bin/console app:load:rebrickable`
5. Load relations between LDraw models and Rebrickable parts by running command `$ php bin/console app:load:relation` ##### Load data
You can load initial application data by running command `$ bin/console app:init`
This command consists of multiple subcommands that can be called separately:
1. Load LDraw models into database by running commad `$ bin/console app:load:models [--ldraw=PATH] [--all] [--file=FILE] [--update] `
2. Load Rebrickable data into database by running command `$ bin/console app:load:rebrickable`
3. Load relations between LDraw models and Rebrickable parts by running command `$ bin/console app:load:relation`
4. Download images of models from rebrickable.com `$ bin/console app:load:images [--color=INT] [--rebrickable] [--missing]`
5. Populate Elastisearch index `$ bin/console fos:elastica:populate`
## Testing
You can run complete system tests by `$ phpunit`. These should cover the main system functions and the functionality of calling the third-party programs that are required are needed to seamlessly retrieve the necessary application data.

View File

@ -7,6 +7,7 @@ use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
class InitDataCommand extends ContainerAwareCommand class InitDataCommand extends ContainerAwareCommand
@ -15,11 +16,11 @@ class InitDataCommand extends ContainerAwareCommand
{ {
$this $this
->setName('app:init') ->setName('app:init')
->setDescription('Loads relations between LDraw models and Rebrickable parts.') ->setDescription('Loads initial data')
->setHelp('This command allows you to load relation between models and parts into database.') ->setHelp('This command allows you to load initial data of models and sets into aplication')
->setDefinition( ->setDefinition(
new InputDefinition([ new InputDefinition([
new InputArgument('ldraw', InputArgument::OPTIONAL, 'Path to LDraw library directory'), new InputOption('ldraw', 'l',InputOption::VALUE_OPTIONAL, 'Path to LDraw library directory'),
]) ])
); );
} }
@ -28,11 +29,16 @@ class InitDataCommand extends ContainerAwareCommand
{ {
$loadModelsCommand = $this->getApplication()->find('app:load:models'); $loadModelsCommand = $this->getApplication()->find('app:load:models');
$returnCode = $loadModelsCommand->run(new ArrayInput([ $loadModelsInput = [
'command' => 'app:load:models', 'command' => 'app:load:models',
'ldraw' => $input->getArgument('ldraw'),
'--all' => true, '--all' => true,
]), $output); ];
if($ldraw = $input->getOption('ldraw')) {
$loadModelsInput['--ldraw'] = $ldraw;
}
$returnCode = $loadModelsCommand->run(new ArrayInput($loadModelsInput), $output);
if ($returnCode) { if ($returnCode) {
return 1; return 1;
@ -58,9 +64,20 @@ class InitDataCommand extends ContainerAwareCommand
'command' => 'app:load:images', 'command' => 'app:load:images',
'--color' => -1, '--color' => -1,
'--rebrickable' => true, '--rebrickable' => true,
'--models' => true, '--missing' => true,
]), $output); ]), $output);
if ($returnCode) {
return 1;
}
$elasticIndex = $this->getApplication()->find('fos:elastic:populate');
$returnCode = $elasticIndex->run(null, $output);
if ($returnCode) {
return 1;
}
return 0; return 0;
} }
} }

View File

@ -19,9 +19,8 @@ class LoadModelImagesCommand extends ContainerAwareCommand
->setDefinition( ->setDefinition(
new InputDefinition([ new InputDefinition([
new InputOption('color', 'c', InputOption::VALUE_REQUIRED, 'Color ID of images to load.'), new InputOption('color', 'c', InputOption::VALUE_REQUIRED, 'Color ID of images to load.'),
new InputOption('url', 'u', InputOption::VALUE_REQUIRED, 'Url of zip file to load'),
new InputOption('rebrickable', 'r', InputOption::VALUE_NONE, 'Download images from Rebicable.com'), new InputOption('rebrickable', 'r', InputOption::VALUE_NONE, 'Download images from Rebicable.com'),
new InputOption('models', 'm', InputOption::VALUE_NONE, 'Load missing images of models'), new InputOption('missing', 'm', InputOption::VALUE_NONE, 'Load missing images of models'),
]) ])
); );
} }
@ -32,13 +31,12 @@ class LoadModelImagesCommand extends ContainerAwareCommand
$imageLoaderService->setOutput($output); $imageLoaderService->setOutput($output);
$color = $input->getOption('color'); $color = $input->getOption('color');
$url = $input->getOption('url');
if ($color !== null && $input->getOption('rebrickable')) { if ($color !== null && $input->getOption('rebrickable')) {
$imageLoaderService->loadColorFromRebrickable($color, $url); $imageLoaderService->loadColorFromRebrickable($color);
} }
if ($input->getOption('models')) { if ($input->getOption('missing')) {
$imageLoaderService->loadMissingModelImages(); $imageLoaderService->loadMissingModelImages();
} }
} }

View File

@ -2,6 +2,7 @@
namespace AppBundle\Command; namespace AppBundle\Command;
use AppBundle\Service\Loader\ModelLoader;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Command\LockableTrait; use Symfony\Component\Console\Command\LockableTrait;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
@ -22,10 +23,10 @@ class LoadModelsCommand extends ContainerAwareCommand
->setHelp('This command allows you to load LDraw library models into database while converting .dat files to .stl format.') ->setHelp('This command allows you to load LDraw library models into database while converting .dat files to .stl format.')
->setDefinition( ->setDefinition(
new InputDefinition([ new InputDefinition([
new InputArgument('ldraw', InputArgument::OPTIONAL, 'Path to LDraw library directory'), new InputOption('ldraw', 'l', InputOption::VALUE_OPTIONAL, 'Path to LDraw library directory'),
new InputOption('all', 'a', InputOption::VALUE_NONE, 'Load all models from LDraw libary folder (/parts directory)'), new InputOption('all', 'a', InputOption::VALUE_NONE, 'Load all models from LDraw libary folder (/parts directory)'),
new InputOption('file', 'f', InputOption::VALUE_REQUIRED, 'Load single modle into database'), new InputOption('file', 'f', InputOption::VALUE_REQUIRED, 'Load single modle into database'),
new InputOption('update', 'u', InputOption::VALUE_NONE, 'Overwrite already loaded models'), new InputOption('update', 'u', InputOption::VALUE_NONE, 'Update models'),
]) ])
); );
} }
@ -38,13 +39,10 @@ class LoadModelsCommand extends ContainerAwareCommand
return 1; return 1;
} }
/** @var ModelLoader $modelLoader */
$modelLoader = $this->getContainer()->get('service.loader.model'); $modelLoader = $this->getContainer()->get('service.loader.model');
$modelLoader->setOutput($output); $modelLoader->setOutput($output);
$modelLoader->setRewite($input->getOption('update')); $modelLoader->setRewrite($input->getOption('update'));
if (!($ldraw = $input->getArgument('ldraw'))) {
$ldraw = $modelLoader->downloadLibrary();
}
if (!$input->getOption('file') && !$input->getOption('all')) { if (!$input->getOption('file') && !$input->getOption('all')) {
$output->writeln('Either the --all or --file option is required'); $output->writeln('Either the --all or --file option is required');
@ -52,46 +50,38 @@ class LoadModelsCommand extends ContainerAwareCommand
return 1; return 1;
} }
if ($ldrawPath = realpath($ldraw)) { if($ldraw = $input->getOption('ldraw')) {
$modelLoader->setLDrawLibraryContext($ldrawPath); $modelLoader->setLDrawLibraryContext(realpath($ldraw));
} else {
$ldraw = $modelLoader->downloadLibrary($this->getContainer()->getParameter('app.ld_library_download_url'));
$modelLoader->setLDrawLibraryContext($ldraw);
}
if (($path = $input->getOption('file')) != null) { if (($path = $input->getOption('file')) != null) {
if ($file = realpath($path)) { if ($file = realpath($path)) {
$output->writeln([
"Loading model: {$path}",
]);
$modelLoader->loadOne($file);
$errorCount = $this->getContainer()->get('monolog.logger.loader')->countErrors();
$errors = $errorCount ? '<error>'.$errorCount.'</error>' : '<info>0</info>';
$output->writeln(['Done with "'.$errors.'" errors.']);
} else {
$output->writeln("File $path not found");
}
}
// Load all models inside ldraw/parts directory
if ($input->getOption('all')) {
$output->writeln([ $output->writeln([
'<fg=cyan>------------------------------------------------------------------------------</>', "Loading model: {$path}",
"<fg=cyan>Loading models from LDraw library:</> <comment>{$ldrawPath}</comment>",
'<fg=cyan>------------------------------------------------------------------------------</>',
]); ]);
$modelLoader->loadAll(); $modelLoader->loadOne($file);
$errorCount = $this->getContainer()->get('monolog.logger.loader')->countErrors(); $errorCount = $this->getContainer()->get('monolog.logger.loader')->countErrors();
$errors = $errorCount ? '<error>'.$errorCount.'</error>' : '<info>0</info>'; $errors = $errorCount ? '<error>'.$errorCount.'</error>' : '<info>0</info>';
$output->writeln(['Done with "'.$errors.'" errors.']); $output->writeln(['Done with "'.$errors.'" errors.']);
} else {
$output->writeln("File $path not found");
} }
} else { }
$output->writeln("<error>{$ldraw} is not a valid path!</error>");
$this->release();
return 1; // Load all models inside ldraw/parts directory
if ($input->getOption('all')) {
$modelLoader->loadAll();
$errorCount = $this->getContainer()->get('monolog.logger.loader')->countErrors();
$errors = $errorCount ? '<error>'.$errorCount.'</error>' : '<info>0</info>';
$output->writeln(['Done with "'.$errors.'" errors.']);
} }
$this->release(); $this->release();