mirror of
https://github.com/ToxicCrack/PrintABrick.git
synced 2025-05-17 12:50:08 -07:00
Add LD library download method
This commit is contained in:
parent
cf7ebfb703
commit
3e2f33242d
@ -9,6 +9,8 @@ parameters:
|
||||
locale: en
|
||||
# rebrickable csv files root URL (http://rebrickable.com/media/downloads/ or local dir containing csv files)
|
||||
app.rebrickable_downloads_url: 'http://rebrickable.com/media/downloads/'
|
||||
app.ld_library_download_url: 'http://www.ldraw.org/library/updates/completeCA.zip'
|
||||
|
||||
app.media_root: "%kernel.root_dir%/../var/media/"
|
||||
|
||||
framework:
|
||||
|
@ -12,7 +12,7 @@ services:
|
||||
|
||||
service.loader.model:
|
||||
class: AppBundle\Service\Loader\ModelLoader
|
||||
arguments: ['@service.ldview', '@app.relation.mapper']
|
||||
arguments: ['@service.stl.converter', '@app.relation.mapper', '%app.ld_library_download_url%']
|
||||
parent: service.loader.base
|
||||
|
||||
service.loader.relation:
|
||||
|
@ -19,7 +19,7 @@ class InitDataCommand extends ContainerAwareCommand
|
||||
->setHelp('This command allows you to load relation between models and parts into database.')
|
||||
->setDefinition(
|
||||
new InputDefinition([
|
||||
new InputArgument('ldraw', InputArgument::REQUIRED, 'Path to LDraw library directory'),
|
||||
new InputArgument('ldraw', InputArgument::OPTIONAL, 'Path to LDraw library directory'),
|
||||
])
|
||||
);
|
||||
}
|
||||
@ -39,8 +39,7 @@ class InitDataCommand extends ContainerAwareCommand
|
||||
}
|
||||
|
||||
$loadRebrickableCommad = $this->getApplication()->find('app:load:rebrickable');
|
||||
$returnCode = $loadRebrickableCommad->run(new ArrayInput([
|
||||
'command' => 'app:load:rebrickable', ]), $output);
|
||||
$returnCode = $loadRebrickableCommad->run(new ArrayInput(['command' => 'app:load:rebrickable']), $output);
|
||||
|
||||
if ($returnCode) {
|
||||
return 1;
|
||||
@ -48,8 +47,7 @@ class InitDataCommand extends ContainerAwareCommand
|
||||
|
||||
$loadRelationsCommand = $this->getApplication()->find('app:load:relations');
|
||||
|
||||
$returnCode = $loadRelationsCommand->run(new ArrayInput([
|
||||
'command' => 'app:load:relations', ]), $output);
|
||||
$returnCode = $loadRelationsCommand->run(new ArrayInput(['command' => 'app:load:relations']), $output);
|
||||
|
||||
if ($returnCode) {
|
||||
return 1;
|
||||
|
@ -22,7 +22,7 @@ class LoadModelsCommand extends ContainerAwareCommand
|
||||
->setHelp('This command allows you to load LDraw library models into database while converting .dat files to .stl format.')
|
||||
->setDefinition(
|
||||
new InputDefinition([
|
||||
new InputArgument('ldraw', InputArgument::REQUIRED, 'Path to LDraw library directory'),
|
||||
new InputArgument('ldraw', InputArgument::OPTIONAL, 'Path to LDraw library 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('update', 'u', InputOption::VALUE_NONE, 'Overwrite already loaded models'),
|
||||
@ -42,7 +42,9 @@ class LoadModelsCommand extends ContainerAwareCommand
|
||||
$modelLoader->setOutput($output);
|
||||
$modelLoader->setRewite($input->getOption('update'));
|
||||
|
||||
$ldraw = $input->getArgument('ldraw');
|
||||
if (!($ldraw = $input->getArgument('ldraw'))) {
|
||||
$ldraw = $modelLoader->downloadLibrary();
|
||||
}
|
||||
|
||||
if (!$input->getOption('file') && !$input->getOption('all')) {
|
||||
$output->writeln('Either the --all or --file option is required');
|
||||
|
@ -79,6 +79,35 @@ class ModelLoader extends BaseLoader
|
||||
}
|
||||
}
|
||||
|
||||
public function downloadLibrary()
|
||||
{
|
||||
$this->writeOutput([
|
||||
'<fg=cyan>------------------------------------------------------------------------------</>',
|
||||
'<fg=cyan>Downloading LDraw library</>',
|
||||
'<fg=cyan>------------------------------------------------------------------------------</>',
|
||||
]);
|
||||
|
||||
$libraryZip = $this->downloadFile($this->LDLibraryUrl);
|
||||
|
||||
$temp_dir = tempnam(sys_get_temp_dir(), 'printabrick.');
|
||||
if (file_exists($temp_dir)) {
|
||||
unlink($temp_dir);
|
||||
}
|
||||
mkdir($temp_dir);
|
||||
|
||||
$zip = new \ZipArchive();
|
||||
if ($zip->open($libraryZip) != 'true') {
|
||||
echo 'Error :- Unable to open the Zip File';
|
||||
}
|
||||
$zip->extractTo($temp_dir);
|
||||
$zip->close();
|
||||
unlink($libraryZip);
|
||||
|
||||
$this->writeOutput(['<info>LDraw libary downloaded</info>']);
|
||||
|
||||
return $temp_dir;
|
||||
}
|
||||
|
||||
public function loadOne($file)
|
||||
{
|
||||
$connection = $this->em->getConnection();
|
||||
|
Loading…
x
Reference in New Issue
Block a user