Skip to content

Commit

Permalink
archiveコマンドを修正
Browse files Browse the repository at this point in the history
  • Loading branch information
rsky committed Mar 31, 2013
1 parent 69b8759 commit 8b74ac2
Showing 1 changed file with 56 additions and 11 deletions.
67 changes: 56 additions & 11 deletions lib/expack/Console/Command/Archive.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ class Archive extends Command
const BUILD_DIR = 'build'; const BUILD_DIR = 'build';
const ARCHIVE_NAME_PREFIX = 'rep2ex-'; const ARCHIVE_NAME_PREFIX = 'rep2ex-';


const ERR_PREPARE = 1;
const ERR_EXPORT = 2;
const ERR_CLEANUP = 3;
const ERR_ARCHIVE = 4;

/** /**
* (non-PHPdoc) * (non-PHPdoc)
* @see Symfony\Component\Console\Command\Command::configure() * @see Symfony\Component\Console\Command\Command::configure()
Expand All @@ -22,7 +27,6 @@ protected function configure()
->setDescription('Makes an archive') ->setDescription('Makes an archive')
->setDefinition(array( ->setDefinition(array(
new InputOption('branch', null, InputOption::VALUE_REQUIRED, 'Specify branch, tag or commit'), new InputOption('branch', null, InputOption::VALUE_REQUIRED, 'Specify branch, tag or commit'),
new InputOption('clear', null, InputOption::VALUE_NONE, 'Remove targets befor export'),
)); ));
} }


Expand All @@ -34,29 +38,35 @@ protected function execute(InputInterface $input, OutputInterface $output)
{ {
$verbose = (bool)$input->getOption('verbose'); $verbose = (bool)$input->getOption('verbose');


if ((bool)$input->getOption('clear')) {
if (!$this->clear($output, $verbose)) {
return 1;
}
}

$branch = $input->getOption('branch'); $branch = $input->getOption('branch');
if ($branch) { if ($branch) {
if (!$this->checkout($branch, $output, $verbose)) { if (!$this->checkout($branch, $output, $verbose)) {
return 1; return self::ERR_PREPARE;
} }
} }


if (!$this->clear($output, $verbose)) {
return self::ERR_PREPARE;
}

if (!$this->exportRep2($output, $verbose)) { if (!$this->exportRep2($output, $verbose)) {
return 1; return self::ERR_EXPORT;
} }


if (!$this->copyDirectory('vendor', $output, $verbose)) { if (!$this->copyDirectory('vendor', $output, $verbose)) {
return 1; return self::ERR_EXPORT;
}

if (!$this->clearExtendedAttributes($output, $verbose)) {
return self::ERR_CLEANUP;
}

if (!$this->deleteVcsDirectories($output, $verbose)) {
return self::ERR_CLEANUP;
} }


if (!$this->archive($output, $verbose)) { if (!$this->archive($output, $verbose)) {
return 1; return self::ERR_ARCHIVE;
} }


$output->writeln('<comment>Success</comment>'); $output->writeln('<comment>Success</comment>');
Expand Down Expand Up @@ -136,7 +146,21 @@ private function copyDirectory($directory, OutputInterface $output, $verbose = f
return false; return false;
} }


return true;
}

/**
* Removes all extended attributes
*
* @param OutputInterface $output
* @param bool $verbose
*
* @return bool
*/
private function clearExtendedAttributes(OutputInterface $output, $verbose = false)
{
if (is_executable('/usr/bin/xattr')) { if (is_executable('/usr/bin/xattr')) {
$target = $this->getExportPrefix();
$command = '/usr/bin/xattr -cr ' . escapeshellarg($target); $command = '/usr/bin/xattr -cr ' . escapeshellarg($target);


return $this->execCommand($command, $output) === 0; return $this->execCommand($command, $output) === 0;
Expand All @@ -145,6 +169,27 @@ private function copyDirectory($directory, OutputInterface $output, $verbose = f
return true; return true;
} }


/**
* Removes all vcs directories
*
* @param OutputInterface $output
* @param bool $verbose
*
* @return bool
*/
private function deleteVcsDirectories(OutputInterface $output, $verbose = false)
{
$target = $this->getExportPrefix();
$command = 'find ' . escapeshellarg($target) . ' -type d \('
. ' -name .CVS -or -name .git -or -name .hg -or -name .svn'
. ' \) -print0 | xargs -0 rm -rf';
if ($verbose) {
$command .= 'v';
}

return $this->execCommand($command, $output) === 0;
}

/** /**
* Makes the archives * Makes the archives
* *
Expand Down

0 comments on commit 8b74ac2

Please sign in to comment.