PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/dev/build/extruder.php

https://bitbucket.org/sunil_nextbits/magento2
PHP | 109 lines | 71 code | 9 blank | 29 comment | 16 complexity | f232c79ab0c362459518baaecc19c7ee MD5 | raw file
  1. #!/usr/bin/php
  2. <?php
  3. /**
  4. * Magento
  5. *
  6. * NOTICE OF LICENSE
  7. *
  8. * This source file is subject to the Open Software License (OSL 3.0)
  9. * that is bundled with this package in the file LICENSE.txt.
  10. * It is also available through the world-wide-web at this URL:
  11. * http://opensource.org/licenses/osl-3.0.php
  12. * If you did not receive a copy of the license and are unable to
  13. * obtain it through the world-wide-web, please send an email
  14. * to license@magentocommerce.com so we can send you a copy immediately.
  15. *
  16. * DISCLAIMER
  17. *
  18. * Do not edit or add to this file if you wish to upgrade Magento to newer
  19. * versions in the future. If you wish to customize Magento for your
  20. * needs please refer to http://www.magentocommerce.com for more information.
  21. *
  22. * @category build
  23. * @package extruder
  24. * @copyright Copyright (c) 2012 X.commerce, Inc. (http://www.magentocommerce.com)
  25. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  26. */
  27. require_once __DIR__ . '/../../lib/Magento/Shell.php';
  28. require_once __DIR__ . '/../../lib/Magento/Exception.php'; // used by Magento_Shell (autoload is not present here)
  29. define('USAGE', <<<USAGE
  30. $>./extruder.php -w <working_dir> -l /path/to/list.txt [[-l /path/to/extra.txt] parameters]
  31. additional parameters:
  32. -w dir directory with working copy to edit with the extruder
  33. -l one or many files with lists that refer to files and directories to be deleted
  34. -v additional verbosity in output
  35. USAGE
  36. );
  37. $options = getopt('w:l:v');
  38. try {
  39. // working dir argument
  40. if (empty($options['w'])) {
  41. throw new Exception(USAGE);
  42. }
  43. $workingDir = realpath($options['w']);
  44. if (!$workingDir || !is_writable($workingDir) || !is_dir($workingDir)) {
  45. throw new Exception("'{$options['w']}' must be a writable directory.");
  46. }
  47. // lists argument
  48. if (empty($options['l'])) {
  49. throw new Exception(USAGE);
  50. }
  51. if (!is_array($options['l'])) {
  52. $options['l'] = array($options['l']);
  53. }
  54. $list = array();
  55. foreach ($options['l'] as $file) {
  56. if (!is_file($file) || !is_readable($file)) {
  57. throw new Exception("Specified file with patterns does not exist or cannot be read: '{$file}'");
  58. }
  59. $patterns = file($file, FILE_IGNORE_NEW_LINES);
  60. foreach ($patterns as $pattern) {
  61. if (empty($pattern) || 0 === strpos($pattern, '#')) { // comments start from #
  62. continue;
  63. }
  64. $pattern = $workingDir . DIRECTORY_SEPARATOR . $pattern;
  65. $items = glob($pattern, GLOB_BRACE);
  66. if (empty($items)) {
  67. throw new Exception("glob() pattern '{$pattern}' returned empty result.");
  68. }
  69. $list = array_merge($list, $items);
  70. }
  71. }
  72. if (empty($list)) {
  73. throw new Exception('List of files or directories to delete is empty.');
  74. }
  75. // verbosity argument
  76. $verbose = isset($options['v']);
  77. // perform "extrusion"
  78. $shell = new Magento_Shell($verbose);
  79. foreach ($list as $item) {
  80. if (!file_exists($item)) {
  81. throw new Exception("The file or directory '{$item} is marked for deletion, but it doesn't exist.");
  82. }
  83. $shell->execute(
  84. 'git --git-dir %s --work-tree %s rm -r -f -- %s',
  85. array("{$workingDir}/.git", $workingDir, $item)
  86. );
  87. if (file_exists($item)) {
  88. throw new Exception("The file or directory '{$item}' was supposed to be deleted, but it still exists.");
  89. }
  90. }
  91. exit(0);
  92. } catch (Exception $e) {
  93. if ($e->getPrevious()) {
  94. $message = (string)$e->getPrevious();
  95. } else {
  96. $message = $e->getMessage();
  97. }
  98. echo $message . PHP_EOL;
  99. exit(1);
  100. }