From b39937f40e4d90b805656564ae6c4dab721fcc5c Mon Sep 17 00:00:00 2001 From: Hamish Friedlander Date: Thu, 31 Mar 2011 11:31:25 +1300 Subject: [PATCH] MINOR: Make new-project use github source for blackcandy theme, not svn --- tools/lib/sources.php | 32 ++++++++++++++++++++++++++++++++ tools/lib/template.php | 14 ++++++++------ tools/lib/tools.php | 24 +++++++++++++++++++----- 3 files changed, 59 insertions(+), 11 deletions(-) diff --git a/tools/lib/sources.php b/tools/lib/sources.php index 6ffde9d..0f234c5 100644 --- a/tools/lib/sources.php +++ b/tools/lib/sources.php @@ -75,6 +75,38 @@ class Github extends GitRepo { } } +class GithubSparse extends Github { + function piston($out) { + $this->export($out); + if (Git::isGITRepo()) Git::add($out); + } + + function canPiston() { + $data = $this->data; + echo "WARNING: Sparse import of directory {$data['subdir']} from {$this->repoURL()} will be flat, not pistoned\n"; + return $this->canExport(); + } + + function checkout($out) { + $this->export($out); + } + + function canCheckout() { + $data = $this->data; + echo "WARNING: Sparse import of directory {$data['subdir']} from {$this->repoURL()} will be flat, not checked out\n"; + return $this->canExport(); + } + + function export($out) { + $data = $this->data; + + $tmp = tempnam(sys_get_temp_dir(), 'phpinstaller-') . '.zip'; + + HTTP::get("https://github.com/{$data['user']}/{$data['project']}/zipball/{$data['branch']}", $tmp); + Zip::import($tmp, $out, 1, $data['subdir']); + } +} + class SvnRepo { function __construct($data) { $this->data = $data; diff --git a/tools/lib/template.php b/tools/lib/template.php index 9627483..5ecfe1a 100644 --- a/tools/lib/template.php +++ b/tools/lib/template.php @@ -16,14 +16,16 @@ $template = array( 'project' => 'silverstripe-cms', 'branch' => SAPPHIRE_CURRENT_BRANCH )), - 'themes/blackcandy' => new SvnRepo(array( - 'repo' => 'http://svn.silverstripe.com/open/themes/blackcandy', - 'branch' => 'trunk', + 'themes/blackcandy' => new GithubSparse(array( + 'user' => 'silverstripe-themes', + 'project' => 'silverstripe-blackcandy', + 'branch' => SAPPHIRE_CURRENT_BRANCH, 'subdir' => 'blackcandy' )), - 'themes/blackcandy_blog' => new SvnRepo(array( - 'repo' => 'http://svn.silverstripe.com/open/themes/blackcandy', - 'branch' => 'trunk', + 'themes/blackcandy_blog' => new GithubSparse(array( + 'user' => 'silverstripe-themes', + 'project' => 'silverstripe-blackcandy', + 'branch' => SAPPHIRE_CURRENT_BRANCH, 'subdir' => 'blackcandy_blog' )) ); diff --git a/tools/lib/tools.php b/tools/lib/tools.php index 14e3c3f..eeab7bd 100644 --- a/tools/lib/tools.php +++ b/tools/lib/tools.php @@ -65,6 +65,10 @@ class GIT { return is_dir('.git'); } + static function add($dir) { + `git add $dir`; + } + static function ignore($dir) { $hndl = fopen('.gitignore', 'a'); fwrite($hfnl, $dir."\n"); @@ -94,7 +98,7 @@ class Zip { return class_exists('ZipArchive'); } - static function import($src, $dest, $skipdirs = 0) { + static function import($src, $dest, $skipdirs = 0, $subdir = null) { $zip = new ZipArchive; $res = $zip->open($src); if ($res === TRUE) { @@ -115,11 +119,21 @@ class Zip { array_unshift($parts, basename($name)); $name = dirname($name); } - - // We only need to move the very next level after the skipdirs level - if (count($parts) != $skipdirs+1) continue; - $dstname = $parts[$skipdirs]; + if ($subdir) { + // We only need to move the level after the level after the skipdirs level, presuming that level after the skipdirs level == $subdir + if (count($parts) != $skipdirs+2) continue; + if ($parts[$skipdirs] != $subdir) continue; + + $dstname = $parts[$skipdirs+1]; + } + else { + // We only need to move the very next level after the skipdirs level + if (count($parts) != $skipdirs+1) continue; + + $dstname = $parts[$skipdirs]; + } + rename($tmpdir.'/'.$srcname, $dest.'/'.$dstname); } }