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

View File

@ -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'
))
);

View File

@ -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);
}
}