Ejemplo n.º 1
0
 def wait(self, change_set_name, stack_name):
     try:
         Oprint.info('Start creating change set {} for stack {}'.format(change_set_name, stack_name), self._client_type)
         spinner.start()
         self._change_set_create.wait(StackName=stack_name, ChangeSetName=change_set_name)
         spinner.stop()
         Oprint.info('Change set {} creation completed'.format(change_set_name), self._client_type)
     except Exception as e:
         spinner.stop()
Ejemplo n.º 2
0
 def wait(self, stack_name):
     try:
         Oprint.info('Start deleting stack {}'.format(stack_name), self._client_type)
         spinner.start()
         self._stack_delete.wait(StackName=stack_name)
         spinner.stop()
         Oprint.info('Stack {} delete completed'.format(stack_name), self._client_type)
     except Exception as e:
         spinner.stop()
Ejemplo n.º 3
0
 def wait(self, bucket_name):
     try:
         Oprint.info('Bucket {} delete starts'.format(bucket_name),
                     self._client_type)
         spinner.start()
         self._bucket_not_exist.wait(Bucket=bucket_name)
         spinner.stop()
         Oprint.info('Bucket {} delete completed'.format(bucket_name),
                     self._client_type)
     except Exception as e:
         spinner.stop()
Ejemplo n.º 4
0
 def wait(self, bucket_name, key, **kwargs):
     try:
         Oprint.info(
             'Object {} delete in bucket {} starts'.format(
                 key, bucket_name), self._client_type)
         spinner.start()
         self._object_not_exist.wait(Bucket=bucket_name, key=key, **kwargs)
         spinner.stop()
         Oprint.info(
             'Object {} delete in bucket {} completed'.format(
                 key, bucket_name), self._client_type)
     except Exception as e:
         spinner.stop()
Ejemplo n.º 5
0
    def pip_wsgi_install(self, tmp_path):
        """Install requirement for wsgi"""
        try:
            Oprint.info('Installing python package dependancies for wsgi',
                        'pip')

            spinner.start()
            os.system(
                'pip install werkzeug base58 wsgi-request-logger -t {} &>/dev/null'
                .format(tmp_path))
            spinner.stop()

            #Oprint.info('Wsgi python package installation complete', 'pip')
        except Exception as e:
            spinner.stop()
            raise e
Ejemplo n.º 6
0
    def fetch(self):
        """Fetch template repo to local"""
        try:
            Oprint.info(
                'Start downloading repo to your project from {}'.format(
                    self._args.get('<url>')), 'lmdo')
            spinner.start()

            tmp = tempfile.mkdtemp()
            self.git_clone(self._args.get('<url>'), tmp)
            copytree(tmp, './', ignore=shutil.ignore_patterns('*.git*'))
            shutil.rmtree(tmp)

            spinner.stop()
            Oprint.info(
                'Complete downloading repo to your project from {}'.format(
                    self._args.get('<url>')), 'lmdo')
        except Exception as e:
            spinner.stop()
            raise e
Ejemplo n.º 7
0
    def venv_package_install(self, tmp_path):
        """Install virtualenv packages"""
        import pip
        venv = self.get_current_venv_path()

        cwd = os.getcwd()

        def splitpath(path):
            parts = []
            (path, tail) = os.path.split(path)
            while path and tail:
                parts.append(tail)
                (path, tail) = os.path.split(path)
            parts.append(os.path.join(path, tail))
            return map(os.path.normpath, parts)[::-1]

        split_venv = splitpath(venv)
        split_cwd = splitpath(cwd)

        # Ideally this should be avoided automatically,
        # but this serves as an okay stop-gap measure.
        if split_venv[-1] == split_cwd[-1]:  # pragma: no cover
            Oprint.warn(
                "Warning! Your project and virtualenv have the same name! You may want to re-create your venv with a new name, or explicitly define a 'project_name', as this may cause errors.",
                'lambda')

        # Then, do site site-packages..
        egg_links = []

        site_packages = os.path.join(venv, 'lib', 'python2.7', 'site-packages')
        egg_links.extend(glob.glob(os.path.join(site_packages, '*.egg-link')))
        Oprint.info('Copying lib packages over', 'pip')
        copytree(site_packages,
                 tmp_path,
                 symlinks=False,
                 ignore=shutil.ignore_patterns(*self.VIRTUALENV_ZIP_EXCLUDES))

        # We may have 64-bin specific packages too.
        site_packages_64 = os.path.join(venv, 'lib64', 'python2.7',
                                        'site-packages')
        if os.path.exists(site_packages_64):
            egg_links.extend(
                glob.glob(os.path.join(site_packages_64, '*.egg-link')))
            Oprint.info('Copying lib64 packages over', 'pip')
            copytree(
                site_packages_64,
                tmp_path,
                symlinks=False,
                ignore=shutil.ignore_patterns(*self.VIRTUALENV_ZIP_EXCLUDES))

        if egg_links:
            self.copy_editable_packages(egg_links, tmp_path)

        package_to_keep = []
        if os.path.isdir(site_packages):
            package_to_keep += os.listdir(site_packages)
        if os.path.isdir(site_packages_64):
            package_to_keep += os.listdir(site_packages_64)

        installed_packages_name_set = self.get_virtualenv_installed_package()
        # First, try lambda packages
        for name, details in lambda_packages.iteritems():
            if name.lower() in installed_packages_name_set:
                Oprint.info(
                    'Installing Lambda_package Amazon Linux AMI bianry package {} to {}'
                    .format(name, tmp_path), 'pip')
                tar = tarfile.open(details['path'], mode="r:gz")
                for member in tar.getmembers():
                    # If we can, trash the local version.
                    if member.isdir():
                        shutil.rmtree(os.path.join(tmp_path, member.name),
                                      ignore_errors=True)
                        continue

                    tar.extract(member, tmp_path)

                installed_packages_name_set.remove(name.lower())

        # Then try to use manylinux packages from PyPi..
        # Related: https://github.com/Miserlou/Zappa/issues/398
        try:
            Oprint.info(
                'Installing virtualenv python package dependancies to {}'.
                format(tmp_path), 'pip')
            spinner.start()
            for installed_package_name in installed_packages_name_set:
                wheel_url = self.get_manylinux_wheel(installed_package_name)
                if wheel_url:
                    resp = requests.get(wheel_url, timeout=2, stream=True)
                    resp.raw.decode_content = True
                    zipresp = resp.raw
                    with zipfile.ZipFile(BytesIO(zipresp.read())) as zfile:
                        zfile.extractall(tmp_path)
            spinner.stop()
        except Exception as e:
            spinner.stop()
            Oprint.warn(e, 'pip')
Ejemplo n.º 8
0
    def package_install(self, tmp_path):
        """Install requirement"""
        if os.path.isfile('{}/{}'.format(
                tmp_path,
                os.getenv('PIP_REQUIREMENTS_FILE', PIP_REQUIREMENTS_FILE))):
            with open('{}/{}'.format(
                    tmp_path,
                    os.getenv('PIP_REQUIREMENTS_FILE',
                              PIP_REQUIREMENTS_FILE))) as f:
                requirements = [
                    item.strip().lower() for item in f.read().splitlines()
                    if item.strip()
                ]
            try:
                lambda_pkg_to_install = {}

                # Filter function to find package should
                # be fetched from lambda package
                def find_lambda_pkg(item):
                    found = False
                    for name, detail in lambda_packages.items():
                        if item.startswith(name.lower()):
                            lambda_pkg_to_install[name.lower()] = detail
                            return False
                        else:
                            continue

                    return True

                requirements = filter(find_lambda_pkg, requirements)
                # always install setup tool
                requirements.append('setuptools')

                for name, detail in lambda_pkg_to_install.iteritems():
                    Oprint.info(
                        'Installing Amazon Linux AMI bianry package {} to {}'.
                        format(name, tmp_path), 'pip')

                    tar = tarfile.open(detail['path'], mode="r:gz")
                    for member in tar.getmembers():
                        if member.isdir():
                            shutil.rmtree(os.path.join(tmp_path, member.name),
                                          ignore_errors=True)
                            continue

                        #tar.extract(member, os.getenv('PIP_VENDOR_FOLDER', PIP_VENDOR_FOLDER))
                        tar.extract(member, tmp_path)

                tmp_requirements = tempfile.NamedTemporaryFile(delete=False)
                for line in requirements:
                    tmp_requirements.write(line + '\n')
                tmp_requirements.close()

                Oprint.info(
                    'Installing python package dependancies to {}'.format(
                        tmp_path), 'pip')
                spinner.start()
                os.system('pip install -t {} -r {} &>/dev/null'.format(
                    tmp_path, tmp_requirements.name))
                spinner.stop()
            except Exception as e:
                spinner.stop()
                Oprint.err(e, 'pip')
        else:
            Oprint.warn(
                '{} could not be found, no dependencies will be installed'.
                format(
                    os.getenv('PIP_REQUIREMENTS_FILE',
                              PIP_REQUIREMENTS_FILE)), 'pip')