Ejemplo n.º 1
0
    def create_website(self):
        '''
        To create a website, the new_website cookie is used.
        After creating the directory structure, the run_script function
        from cookiecutter finds the hooks folder which contains a
        post-cookiecutter-template-generation bash script.  The bash script
        sets up the proper dependencies and environment variables for the website,
        and runs the website on the specified host and port

        :return: Runs the website.
        '''
        # TODO-ROB Add heavy logging here
        e_c = {
            "website_name": self.website,
            "website_path": os.path.join(str(self.website_path), ''),
            "website_host": self.web_host,
            "website_port": self.web_port
        }
        cookiecutter(str(self.website_cookie),
                     no_input=True,
                     extra_context=e_c,
                     output_dir=self.flask)
        # Get the absolute path to the script that starts the flask server
        script_path = self.website_path / Path('hooks') / Path(
            'post_gen_project.sh')
        #scripts_file_path = find_hook('post_gen_project.sh', hooks_dir=str(script_path))
        # TODO-ROB add screening to the bash script for flask run -h -p
        run_script(script_path=str(script_path), cwd=str(self.website_path))
Ejemplo n.º 2
0
    def bake_the_website(self, host, port, website_path, cookie_jar=None):
        """Create a website using the new_website cookie.

        After creating the directory structure, the run_script function
        from cookiecutter finds the hooks folder which contains a
        post-cookiecutter-template-generation bash script.  The bash script
        sets up the proper dependencies and environment variables for the
        website, and runs the website on the specified host and port.

        :param host:
        :param port:
        :param website_path:
        :param cookie_jar:  (Default value = None)
        """

        self.cookielog.warn('Creating directories from the Website Cookie template.')
        if cookie_jar:
            self.cookie_jar = cookie_jar
        # TODO-ROB:  Add heavy logging here
        e_c = {"website_name": self.website,
               "website_path": os.path.join(str(website_path), ''),
               "website_host": host,
               "website_port": port}
        cookiecutter(str(self.Recipes.website_cookie), no_input=True,
                     extra_context=e_c, output_dir=str(self.cookie_jar))
        os.chmod(str(self.cookie_jar / Path(self.website)), mode=0o777)
        # Get the absolute path to the script that starts the flask server
        script_path = website_path / \
                      Path('hooks') / Path('post_gen_project.sh')
        #scripts_file_path = find_hook('post_gen_project.sh', hooks_dir=str(script_path))
        # TODO-ROB add screening to the bash script for flask run -h -p
        run_script(script_path=str(script_path), cwd=str(website_path))
        self.cookielog.info('Directories have been created for the Flask Web Server, %s. ✔' % self.website)
        self.cookielog.warn('The %s Flask Server should now be running on http://%s:%s' % (self.website, host, port))
Ejemplo n.º 3
0
 def test_run_script_cwd(self):
     """Change directory before running hook"""
     hooks.run_script(
         os.path.join(self.hooks_path, self.post_hook),
         'tests'
     )
     assert os.path.isfile('tests/shell_post.txt')
     assert 'tests' not in os.getcwd()
Ejemplo n.º 4
0
 def test_run_script_cwd(self):
     """Change directory before running hook"""
     hooks.run_script(
         os.path.join(self.hooks_path, self.post_hook),
         'tests'
     )
     assert os.path.isfile('tests/shell_post.txt')
     assert 'tests' not in os.getcwd()
Ejemplo n.º 5
0
    def test_run_failing_script(self, mocker):
        """Test correct exception raise if run_script fails."""
        err = OSError()

        prompt = mocker.patch('subprocess.Popen')
        prompt.side_effect = err

        with pytest.raises(exceptions.FailedHookException) as excinfo:
            hooks.run_script(os.path.join(self.hooks_path, self.post_hook))
        assert 'Hook script failed (error: {})'.format(err) in str(excinfo.value)
Ejemplo n.º 6
0
    def test_run_failing_script_enoexec(self, mocker):
        """Test correct exception raise if run_script fails."""
        err = OSError()
        err.errno = errno.ENOEXEC

        prompt = mocker.patch('subprocess.Popen')
        prompt.side_effect = err

        with pytest.raises(exceptions.FailedHookException) as excinfo:
            hooks.run_script(os.path.join(self.hooks_path, self.post_hook))
        assert 'Hook script failed, might be an empty file or missing a shebang' in str(
            excinfo.value)
Ejemplo n.º 7
0
 def create_website(self):
     # TODO-ROB Add heavy logging here
     e_c = {
         "website_name": self.website,
         "website_path": os.path.join(str(self.website_path), ''),
         "website_host": self.web_host,
         "website_port": self.web_port
     }
     cookiecutter(str(self.website_cookie),
                  no_input=True,
                  extra_context=e_c,
                  output_dir=self.flask)
     # Get the absolute path to the script that starts the flask server
     script_path = self.website_path / Path('hooks') / Path(
         'post_gen_project.sh')
     #scripts_file_path = find_hook('post_gen_project.sh', hooks_dir=str(script_path))
     run_script(script_path=str(script_path), cwd=str(self.website_path))
Ejemplo n.º 8
0
 def test_run_script(self):
     """Execute a hook script, independently of project generation"""
     hooks.run_script(os.path.join(self.hooks_path, self.post_hook))
     assert os.path.isfile('shell_post.txt')
Ejemplo n.º 9
0
 def test_run_script(self):
     """Execute a hook script, independently of project generation"""
     hooks.run_script(os.path.join(self.hooks_path, self.post_hook))
     assert os.path.isfile("shell_post.txt")