MINOR: Make new-project use github source for blackcandy theme, not svn

This commit is contained in:
Hamish Friedlander 2011-03-31 11:31:25 +13:00
parent c5ce75fae4
commit b39937f40e
3 changed files with 59 additions and 11 deletions

View File

@ -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 { class SvnRepo {
function __construct($data) { function __construct($data) {
$this->data = $data; $this->data = $data;

View File

@ -16,14 +16,16 @@ $template = array(
'project' => 'silverstripe-cms', 'project' => 'silverstripe-cms',
'branch' => SAPPHIRE_CURRENT_BRANCH 'branch' => SAPPHIRE_CURRENT_BRANCH
)), )),
'themes/blackcandy' => new SvnRepo(array( 'themes/blackcandy' => new GithubSparse(array(
'repo' => 'http://svn.silverstripe.com/open/themes/blackcandy', 'user' => 'silverstripe-themes',
'branch' => 'trunk', 'project' => 'silverstripe-blackcandy',
'branch' => SAPPHIRE_CURRENT_BRANCH,
'subdir' => 'blackcandy' 'subdir' => 'blackcandy'
)), )),
'themes/blackcandy_blog' => new SvnRepo(array( 'themes/blackcandy_blog' => new GithubSparse(array(
'repo' => 'http://svn.silverstripe.com/open/themes/blackcandy', 'user' => 'silverstripe-themes',
'branch' => 'trunk', 'project' => 'silverstripe-blackcandy',
'branch' => SAPPHIRE_CURRENT_BRANCH,
'subdir' => 'blackcandy_blog' 'subdir' => 'blackcandy_blog'
)) ))
); );

View File

@ -65,6 +65,10 @@ class GIT {
return is_dir('.git'); return is_dir('.git');
} }
static function add($dir) {
`git add $dir`;
}
static function ignore($dir) { static function ignore($dir) {
$hndl = fopen('.gitignore', 'a'); $hndl = fopen('.gitignore', 'a');
fwrite($hfnl, $dir."\n"); fwrite($hfnl, $dir."\n");
@ -94,7 +98,7 @@ class Zip {
return class_exists('ZipArchive'); return class_exists('ZipArchive');
} }
static function import($src, $dest, $skipdirs = 0) { static function import($src, $dest, $skipdirs = 0, $subdir = null) {
$zip = new ZipArchive; $zip = new ZipArchive;
$res = $zip->open($src); $res = $zip->open($src);
if ($res === TRUE) { if ($res === TRUE) {
@ -116,10 +120,20 @@ class Zip {
$name = dirname($name); $name = dirname($name);
} }
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 // We only need to move the very next level after the skipdirs level
if (count($parts) != $skipdirs+1) continue; if (count($parts) != $skipdirs+1) continue;
$dstname = $parts[$skipdirs]; $dstname = $parts[$skipdirs];
}
rename($tmpdir.'/'.$srcname, $dest.'/'.$dstname); rename($tmpdir.'/'.$srcname, $dest.'/'.$dstname);
} }
} }