This repository was archived by the owner on Nov 14, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 113
Improved the Download abstract command #121
Closed
javiereguiluz
wants to merge
3
commits into
symfony:master
from
javiereguiluz:improve_download_command
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,9 @@ | |
use GuzzleHttp\Subscriber\Progress\Progress; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Helper\ProgressBar; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
|
||
/** | ||
* Abstract command used by commands which download and extract compressed Symfony files. | ||
|
@@ -31,6 +34,24 @@ | |
*/ | ||
abstract class DownloadCommand extends Command | ||
{ | ||
/** | ||
* Returns the type of the downloaded application in a human readable format. | ||
* It's mainly used to display readable error messages. | ||
* @return string | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like you need one space in front of each *. |
||
abstract protected function getDownloadedApplicationType(); | ||
|
||
/** | ||
* Returns the absolute URL of the remote file downloaded by the command. | ||
*/ | ||
abstract protected function getRemoteFileUrl(); | ||
|
||
protected function initialize(InputInterface $input, OutputInterface $output) | ||
{ | ||
$this->output = $output; | ||
$this->fs = new Filesystem(); | ||
} | ||
|
||
/** | ||
* Chooses the best compressed file format to download (ZIP or TGZ) depending upon the | ||
* available operating system uncompressing commands and the enabled PHP extensions | ||
|
@@ -42,14 +63,14 @@ abstract class DownloadCommand extends Command | |
*/ | ||
protected function download() | ||
{ | ||
$this->output->writeln(sprintf("\n Downloading %s...\n", $this->getDownloadedFileName())); | ||
$this->output->writeln(sprintf("\n Downloading %s...\n", $this->getDownloadedApplicationType())); | ||
|
||
// decide which is the best compressed version to download | ||
$distill = new Distill(); | ||
$symfonyArchiveFile = $distill | ||
->getChooser() | ||
->setStrategy(new MinimumSize()) | ||
->addFilesWithDifferentExtensions($this->remoteFileUrl, ['tgz', 'zip']) | ||
->addFilesWithDifferentExtensions($this->getRemoteFileUrl(), ['tgz', 'zip']) | ||
->getPreferredFile() | ||
; | ||
|
||
|
@@ -107,7 +128,7 @@ protected function download() | |
} else { | ||
throw new \RuntimeException(sprintf( | ||
"There was an error downloading %s from symfony.com server:\n%s", | ||
$this->getDownloadedFileName(), | ||
$this->getDownloadedApplicationType(), | ||
$e->getMessage() | ||
)); | ||
} | ||
|
@@ -142,21 +163,21 @@ protected function extract() | |
throw new \RuntimeException(sprintf( | ||
"%s can't be installed because the downloaded package is corrupted.\n". | ||
"To solve this issue, try executing this command again:\n%s", | ||
$this->getDownloadedFileName(), $this->getExecutedCommand() | ||
$this->getDownloadedApplicationType(), $this->getExecutedCommand() | ||
)); | ||
} catch (FileEmptyException $e) { | ||
throw new \RuntimeException(sprintf( | ||
"%s can't be installed because the downloaded package is empty.\n". | ||
"To solve this issue, try executing this command again:\n%s", | ||
$this->getDownloadedFileName(), $this->getExecutedCommand() | ||
$this->getDownloadedApplicationType(), $this->getExecutedCommand() | ||
)); | ||
} catch (TargetDirectoryNotWritableException $e) { | ||
throw new \RuntimeException(sprintf( | ||
"%s can't be installed because the installer doesn't have enough\n". | ||
"permissions to uncompress and rename the package contents.\n". | ||
"To solve this issue, check the permissions of the %s directory and\n". | ||
"try executing this command again:\n%s", | ||
$this->getDownloadedFileName(), getcwd(), $this->getExecutedCommand() | ||
$this->getDownloadedApplicationType(), getcwd(), $this->getExecutedCommand() | ||
)); | ||
} catch (\Exception $e) { | ||
throw new \RuntimeException(sprintf( | ||
|
@@ -165,15 +186,15 @@ protected function extract() | |
"rename the package contents.\n". | ||
"To solve this issue, check the permissions of the %s directory and\n". | ||
"try executing this command again:\n%s", | ||
$this->getDownloadedFileName(), getcwd(), $this->getExecutedCommand() | ||
$this->getDownloadedApplicationType(), getcwd(), $this->getExecutedCommand() | ||
)); | ||
} | ||
|
||
if (!$extractionSucceeded) { | ||
throw new \RuntimeException(sprintf( | ||
"%s can't be installed because the downloaded package is corrupted\n". | ||
"or because the uncompress commands of your operating system didn't work.", | ||
$this->getDownloadedFileName() | ||
$this->getDownloadedApplicationType() | ||
)); | ||
} | ||
|
||
|
@@ -323,23 +344,4 @@ protected function isEmptyDirectory($dir) | |
// scandir() returns '.' and '..' for an empty dir | ||
return 2 === count(scandir($dir.'/')); | ||
} | ||
|
||
/** | ||
* Returns the name of the downloaded file in a human readable format. | ||
* @return string | ||
*/ | ||
protected function getDownloadedFileName() | ||
{ | ||
$commandName = $this->getName(); | ||
|
||
if ('new' === $commandName) { | ||
return 'Symfony'; | ||
} | ||
|
||
if ('demo' === $commandName) { | ||
return 'Symfony Demo Application'; | ||
} | ||
|
||
return ''; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This property should be moved to the
DownloadCommand
class.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. I moved the initialization of the variables but not their declaration. Done. Thanks.