From ac70915ce208a413e63585826f06876b85861953 Mon Sep 17 00:00:00 2001 From: Michele Orselli Date: Sat, 23 Mar 2013 12:30:11 +0100 Subject: [PATCH] added rsync extension --- composer.lock | 33 ++++++++------ src/Idephix/Extension/Project/Project.php | 43 +++++++++++++++++++ .../Idephix/Extension/Project/ProjectTest.php | 38 ++++++++++++++++ 3 files changed, 100 insertions(+), 14 deletions(-) create mode 100644 src/Idephix/Extension/Project/Project.php create mode 100644 tests/Idephix/Extension/Project/ProjectTest.php diff --git a/composer.lock b/composer.lock index f27435b..da4f80a 100644 --- a/composer.lock +++ b/composer.lock @@ -3,17 +3,17 @@ "packages": [ { "name": "symfony/console", - "version": "2.0.x-dev", + "version": "v2.0.23", "target-dir": "Symfony/Component/Console", "source": { "type": "git", - "url": "https://github.com/symfony/Console", - "reference": "v2.0.13" + "url": "https://github.com/symfony/Console.git", + "reference": "v2.0.23" }, "dist": { "type": "zip", - "url": "https://github.com/symfony/Console/zipball/v2.0.13", - "reference": "v2.0.13", + "url": "https://api.github.com/repos/symfony/Console/zipball/v2.0.23", + "reference": "v2.0.23", "shasum": "" }, "require": { @@ -25,26 +25,23 @@ "Symfony\\Component\\Console": "" } }, + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { "name": "Fabien Potencier", - "email": "fabien@symfony.com", - "homepage": null, - "role": null + "email": "fabien@symfony.com" }, { "name": "Symfony Community", - "email": null, - "homepage": "http://symfony.com/contributors", - "role": null + "homepage": "http://symfony.com/contributors" } ], "description": "Symfony Console Component", "homepage": "http://symfony.com", - "time": "2012-04-29 19:28:50" + "time": "2013-02-27 09:08:35" }, { "name": "symfony/process", @@ -70,7 +67,7 @@ "Symfony\\Component\\Process": "" } }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -89,12 +86,20 @@ "time": "2013-02-18 21:27:57" } ], - "packages-dev": null, + "packages-dev": [ + + ], "aliases": [ ], "minimum-stability": "stable", "stability-flags": [ + ], + "platform": [ + + ], + "platform-dev": [ + ] } diff --git a/src/Idephix/Extension/Project/Project.php b/src/Idephix/Extension/Project/Project.php new file mode 100644 index 0000000..ea9d37e --- /dev/null +++ b/src/Idephix/Extension/Project/Project.php @@ -0,0 +1,43 @@ +idx = $idx; + } + + public function rsyncProject($remote_dir, $local_dir = null, $exclude = null, $extra_opts = null, $ssh_opts = null) + { + if (substr($remote_dir, -1) != '/') + { + $remote_dir .= '/'; + } + + $target = $this->idx->getCurrentTarget(); + $user = $target['ssh_params']['user']; + $host = $this->idx->getCurrentTargetHost(); + + if (file_exists($exclude)) + { + $extra_opts .= ' --exclude-from='.$exclude; + } + + $cmd = "rsync -rlDcz --force --delete --progress $extra_opts -e 'ssh' ./ $user@$host:$remote_dir"; + + return $this->idx->local($cmd); + } +} diff --git a/tests/Idephix/Extension/Project/ProjectTest.php b/tests/Idephix/Extension/Project/ProjectTest.php new file mode 100644 index 0000000..e435ae8 --- /dev/null +++ b/tests/Idephix/Extension/Project/ProjectTest.php @@ -0,0 +1,38 @@ +idx = $this->getMockBuilder('Idephix\Idephix') + ->disableOriginalConstructor() + ->getMock(); + + $this->idx->expects($this->exactly(1)) + ->method('local') + ->will($this->returnArgument(0)); + + $this->idx->expects($this->exactly(1)) + ->method('getCurrentTarget') + ->will($this->returnValue(array('ssh_params' => array('user' => 'kea')))); + + $this->idx->expects($this->exactly(1)) + ->method('getCurrentTargetHost') + ->will($this->returnValue('banana.com')); + + $this->project = new Project(); + $this->project->setIdephix($this->idx); + + } + + public function testRsyncProject() + { + $result = $this->project->rsyncProject('/a/remote'); + + $this->assertEquals("rsync -rlDcz --force --delete --progress -e 'ssh' ./ kea@banana.com:/a/remote/", $result); + } + +}