From 38946d137e672b1cf72bab19336f21b58a2b6a7b Mon Sep 17 00:00:00 2001 From: Vincent Loy Date: Fri, 18 Sep 2015 18:05:34 +0200 Subject: [PATCH 1/4] [CASTOR] add post freeze command line support --- src/castor/repo.py | 17 +++++++++++++++++ tests/assets/test1/Castorfile | 5 ++++- tests/repo.py | 9 +++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/castor/repo.py b/src/castor/repo.py index 80582c8..a5db1a0 100644 --- a/src/castor/repo.py +++ b/src/castor/repo.py @@ -5,6 +5,8 @@ # Rémy Sanchez import json +import shlex +import subprocess from tarfile import TarFile from tempfile import NamedTemporaryFile from shutil import copyfile, rmtree @@ -66,6 +68,12 @@ 'version': { 'type': 'string', }, + 'post_freeze': { + 'type': 'array', + 'items': { + 'type': 'string', + } + }, }, 'required': ['target', 'type', 'repo', 'version'], 'additionalProperties': False, @@ -343,6 +351,15 @@ def gather_dam(self): if target['type'] == 'file': self.apply_file(target['source'], self.target_dam_path(target)) + for target in self.git_targets: + if 'post_freeze' in target: + dam_target = self.target_dam_path(target) + print('Executing post freeze for target {}'.format(target['target'])) + + for cl in target['post_freeze']: + print(cl) + subprocess.Popen(shlex.split(cl), cwd=dam_target).wait() + def freeze(self): """ The goal is to update current versions to the current Git HEADs, and gather all the files diff --git a/tests/assets/test1/Castorfile b/tests/assets/test1/Castorfile index b5eded2..3d1cc12 100644 --- a/tests/assets/test1/Castorfile +++ b/tests/assets/test1/Castorfile @@ -15,7 +15,10 @@ "target": "/modules/test", "type": "git", "repo": "https://bitbucket.org/activkonnect/castor-test-2.git", - "version": "tag1" + "version": "tag1", + "post_freeze": [ + "touch foo" + ] } ] } diff --git a/tests/repo.py b/tests/repo.py index 3580938..1d227d7 100644 --- a/tests/repo.py +++ b/tests/repo.py @@ -229,6 +229,7 @@ def test_gather_dam(self): self.assertEqual(dam_files, { 'test.txt', 'modules/test/youpi.txt', + 'modules/test/foo', '.htaccess', }) @@ -258,6 +259,14 @@ def test_freeze(self): with open(path.join(self.test_root, 'dam', 'test.txt')) as f: self.assertEqual('Saluton', f.read()) + def test_post_freeze(self): + c = Castor(self.test_root) + c.apply() + + c.freeze() + + self.assertTrue(path.exists(path.join(self.test_root, 'dam', 'modules', 'test', 'foo'))) + def test_freeze_files(self): c = Castor(self.test_root) c.apply() From 13126b6ba934e2138ce32121fc1f6540d2c3817c Mon Sep 17 00:00:00 2001 From: Vincent Loy Date: Fri, 18 Sep 2015 18:15:48 +0200 Subject: [PATCH 2/4] update readme --- README.rst | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index cbde2e8..5186f9d 100644 --- a/README.rst +++ b/README.rst @@ -17,6 +17,12 @@ repository containing an empty ``Castorfile`` and a pre-initialized .gitignore. Then, you need to edit your ``Castorfile``. It might look like +Note +++++ + +``post_freeze`` array are an optional argument. It must be an array, each command will be executed +on the ``target`` directory after executing ``castor freeze``. + .. code-block:: { @@ -31,7 +37,10 @@ Then, you need to edit your ``Castorfile``. It might look like "target": "/themes/my-prestashop-theme", "version": "e0e7c15789e6ff674cd75cb24981155441c3df09", "repo": "git@bitbucket.org:activkonnect/my-prestashop-theme.git", - "type": "git" + "type": "git", + "post_freeze": [ + "composer update --no-dev" + ] }, { "target": "/.htaccess", @@ -61,3 +70,5 @@ You can use the ``lodge`` as your working directory during development. If you m code, you can commit in the git repos. If you simply want to update upstream code, check out the new tag/commit you want to use. Then you can use ``castor freeze`` again, and it will update the ``Castorfile`` automatically with the latest Git HEADs, as well as the ``dam`` directory. + + From 13a9fbe6510f9875c9db633c871176bad0f7ad73 Mon Sep 17 00:00:00 2001 From: Vincent Loy Date: Fri, 18 Sep 2015 18:17:14 +0200 Subject: [PATCH 3/4] update readme --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 5186f9d..9f48430 100644 --- a/README.rst +++ b/README.rst @@ -20,7 +20,7 @@ Then, you need to edit your ``Castorfile``. It might look like Note ++++ -``post_freeze`` array are an optional argument. It must be an array, each command will be executed +``post_freeze`` array is optional. It must be an array, each command will be executed on the ``target`` directory after executing ``castor freeze``. .. code-block:: From 3c32f89fe21e8501adc0b467c14e3f9352e5f686 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Sanchez?= Date: Mon, 21 Sep 2015 15:21:14 +0200 Subject: [PATCH 4/4] Version bump --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 11f4f61..fcf3d00 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ setup( name='castor', - version='0.2.0', + version='0.2.1', scripts=['bin/castor'], packages=['castor'], package_dir={'': 'src'},