Пример #1
0
    def package(self):
        package = os.path.join(self._temp_workspace, 'lambda_package')

        # Copy site packages into package base
        LOG.info('Copying site packages')
        site_packages = 'lib/python2.7/site-packages'
        if sys.platform == 'win32' or sys.platform == 'cygwin':
            site_packages = 'lib\\site-packages'

        shutil.copytree(os.path.join(self._pkg_venv, site_packages),
                        package)
        utils.copy_tree(self._path, package, ignore=[TEMP_WORKSPACE_NAME])
        self._create_zip(package)
Пример #2
0
    def package(self, ignore=None):
        """
        Create a zip file of the lambda script and its dependencies.

        :param list ignore: a list of regular expression strings to match paths
            of files in the source of the lambda script against and ignore
            those files when creating the zip file. The paths to be matched are
            local to the source root.
        """
        ignore = ignore or []
        package = os.path.join(self._temp_workspace, 'lambda_package')

        # Copy site packages into package base
        LOG.info('Copying site packages')

        if hasattr(self, '_pkg_venv') and self._pkg_venv:
            lib_dir = 'lib/python*/site-packages'
            lib64_dir = 'lib64/python*/site-packages'

            if sys.platform == 'win32' or sys.platform == 'cygwin':
                lib_dir = 'lib\\site-packages'
                lib64_dir = 'lib64\\site-packages'

            # Look for the site packages
            lib_site_list = glob.glob(os.path.join(
                self._pkg_venv, lib_dir))
            if lib_site_list:
                utils.copy_tree(lib_site_list[0], package)
            else:
                LOG.debug("no lib site packages found")

            lib64_site_list = glob.glob(os.path.join(
                self._pkg_venv, lib64_dir))
            if lib64_site_list:
                lib64_site_packages = lib64_site_list[0]
                if not os.path.islink(lib64_site_packages):
                    LOG.info('Copying lib64 site packages')
                    utils.copy_tree(lib64_site_packages, package)
                lib64_site_packages = lib64_site_list[0]
            else:
                LOG.debug("no lib64 site packages found")

        # Append the temp workspace to the ignore list:
        ignore.append(r"^%s/.*" % re.escape(TEMP_WORKSPACE_NAME))
        utils.copy_tree(self._path, package, ignore)

        # Add extra files
        for p in self._extra_files:
            LOG.info('Copying extra %s into package' % p)
            ignore.append(re.escape(p))
            if os.path.isdir(p):
                utils.copy_tree(p, package, ignore=ignore, include_parent=True)
            else:
                shutil.copy(p, package)

        self._create_zip(package)
Пример #3
0
def test_copy_tree_with_symlink():
    os.mkdir(TESTING_TEMP_DIR)
    filename = 'foo.py'
    symlink_filename = "sym-{}".format(filename)
    with open(path.join(TESTING_TEMP_DIR, filename), 'w') as tfile:
        tfile.write(filename)
    os.symlink(path.join(TESTING_TEMP_DIR,filename), path.join(TESTING_TEMP_DIR,symlink_filename))
    copy_dir = '.copy_of_test'

    utils.copy_tree(TESTING_TEMP_DIR, copy_dir)

    assert os.path.islink(path.join(copy_dir,symlink_filename))
    linkto = os.readlink(path.join(copy_dir,symlink_filename))
    assert linkto == path.join(copy_dir, filename)

    rmtree(TESTING_TEMP_DIR)
    rmtree(copy_dir)
Пример #4
0
def test_copy_tree():
    os.mkdir(TESTING_TEMP_DIR)
    for fil in TEST_TREE:
        dir = path.dirname(fil)
        test_pth = path.join(TESTING_TEMP_DIR, dir)
        if dir is not None and not path.isdir(test_pth):
            os.makedirs(test_pth)
        with open(path.join(TESTING_TEMP_DIR, fil), 'w') as tfile:
            tfile.write(fil)

    copy_dir = '.copy_of_test'
    utils.copy_tree(TESTING_TEMP_DIR, copy_dir, TEST_IGNORE)
    for fil in TEST_TREE:
        pth = path.join(copy_dir, fil)
        assert path.isfile(pth) is (fil not in PATHS_TO_BE_IGNORED)

    rmtree(TESTING_TEMP_DIR)
    rmtree(copy_dir)
Пример #5
0
def test_copy_tree():
    os.mkdir(TESTING_TEMP_DIR)
    for fil in TEST_TREE:
        dir = path.dirname(fil)
        test_pth = path.join(TESTING_TEMP_DIR, dir)
        if dir is not None and not path.isdir(test_pth):
            os.makedirs(test_pth)
        with open(path.join(TESTING_TEMP_DIR, fil), 'w') as tfile:
            tfile.write(fil)

    copy_dir = '.copy_of_test'
    utils.copy_tree(TESTING_TEMP_DIR, copy_dir, TEST_IGNORE)
    for fil in TEST_TREE:
        pth = path.join(copy_dir, fil)
        assert path.isfile(pth) is (fil not in PATHS_TO_BE_IGNORED)

    rmtree(TESTING_TEMP_DIR)
    rmtree(copy_dir)
Пример #6
0
def test_copy_tree_with_symlink():
    os.mkdir(TESTING_TEMP_DIR)
    filename = 'foo.py'
    symlink_filename = "sym-{}".format(filename)
    with open(path.join(TESTING_TEMP_DIR, filename), 'w') as tfile:
        tfile.write(filename)
    os.symlink(path.join(TESTING_TEMP_DIR, filename),
               path.join(TESTING_TEMP_DIR, symlink_filename))
    copy_dir = '.copy_of_test'

    utils.copy_tree(TESTING_TEMP_DIR, copy_dir)

    assert os.path.islink(path.join(copy_dir, symlink_filename))
    linkto = os.readlink(path.join(copy_dir, symlink_filename))
    assert linkto == path.join(copy_dir, filename)

    rmtree(TESTING_TEMP_DIR)
    rmtree(copy_dir)
Пример #7
0
    def package(self, ignore=[]):
        """
        Create a zip file of the lambda script and its dependencies.

        :param list ignore: a list of regular expression strings to match paths
            of files in the source of the lambda script against and ignore
            those files when creating the zip file. The paths to be matched are
            local to the source root.
        """
        package = os.path.join(self._temp_workspace, 'lambda_package')

        # Copy site packages into package base
        LOG.info('Copying site packages')

        if hasattr(self, '_pkg_venv') and self._pkg_venv:
            site_packages = 'lib/python2.7/site-packages'
            lib64_site_packages = 'lib64/python2.7/site-packages'
            if sys.platform == 'win32' or sys.platform == 'cygwin':
                lib64_site_packages = 'lib64\\site-packages'
                site_packages = 'lib\\site-packages'

            utils.copy_tree(os.path.join(self._pkg_venv, site_packages),
                            package)
            lib64_path = os.path.join(self._pkg_venv, lib64_site_packages)
            if not os.path.islink(lib64_path):
                LOG.info('Copying lib64 site packages')
                utils.copy_tree(lib64_path, package)

        # Append the temp workspace to the ignore list:
        ignore += ["^%s/*" % TEMP_WORKSPACE_NAME]
        utils.copy_tree(self._path, package, ignore)
        self._create_zip(package)
Пример #8
0
    def package(self, ignore=None):
        """
        Create a zip file of the lambda script and its dependencies.

        :param list ignore: a list of regular expression strings to match paths
            of files in the source of the lambda script against and ignore
            those files when creating the zip file. The paths to be matched are
            local to the source root.
        """
        ignore = ignore or []
        package = os.path.join(self._temp_workspace, 'lambda_package')

        # Copy site packages into package base
        LOG.info('Copying site packages')

        if hasattr(self, '_pkg_venv') and self._pkg_venv:
            site_packages = 'lib/python2.7/site-packages'
            lib64_site_packages = 'lib64/python2.7/site-packages'
            if sys.platform == 'win32' or sys.platform == 'cygwin':
                lib64_site_packages = 'lib64\\site-packages'
                site_packages = 'lib\\site-packages'

            utils.copy_tree(os.path.join(self._pkg_venv, site_packages),
                            package)
            lib64_path = os.path.join(self._pkg_venv, lib64_site_packages)
            if not os.path.islink(lib64_path):
                LOG.info('Copying lib64 site packages')
                utils.copy_tree(lib64_path, package)

        # Append the temp workspace to the ignore list:
        ignore.append(r"^%s/.*" % re.escape(TEMP_WORKSPACE_NAME))
        utils.copy_tree(self._path, package, ignore)

        # Add extra files
        for p in self._extra_files:
            LOG.info('Copying extra %s into package' % p)
            ignore.append(re.escape(p))
            if os.path.isdir(p):
                utils.copy_tree(p, package, ignore=ignore, include_parent=True)
            else:
                shutil.copy(p, package)

        self._create_zip(package)
Пример #9
0
    def package(self, ignore=[]):
        """
        Create a zip file of the lambda script and its dependencies.

        :param list ignore: a list of regular expression strings to match paths
            of files in the source of the lambda script against and ignore
            those files when creating the zip file. The paths to be matched are
            local to the source root.
        """
        package = os.path.join(self._temp_workspace, 'lambda_package')

        # Copy site packages into package base
        LOG.info('Copying site packages')

        if hasattr(self, '_pkg_venv') and self._pkg_venv:
            site_packages = 'lib/python2.7/site-packages'
            lib64_site_packages = 'lib64/python2.7/site-packages'
            if sys.platform == 'win32' or sys.platform == 'cygwin':
                lib64_site_packages = 'lib64\\site-packages'
                site_packages = 'lib\\site-packages'

            utils.copy_tree(os.path.join(self._pkg_venv, site_packages),
                            package)
            lib64_path = os.path.join(self._pkg_venv, lib64_site_packages)
            if not os.path.islink(lib64_path):
                LOG.info('Copying lib64 site packages')
                utils.copy_tree(lib64_path, package)

        # Append the temp workspace to the ignore list:
        ignore += ["^%s/*" % TEMP_WORKSPACE_NAME]
        utils.copy_tree(self._path, package, ignore)

        # Add extra files
        for p in self._extra_files:
            LOG.info('Copying extra %s into package' % p)
            ignore += ["%s" % p]
            if os.path.isdir(p):
                utils.copy_tree(p, package, ignore=ignore, include_parent=True)
            else:
                shutil.copy(p, package)

        self._create_zip(package)
Пример #10
0
    def package(self, ignore=[]):
        package = os.path.join(self._temp_workspace, 'lambda_package')

        # Copy site packages into package base
        LOG.info('Copying site packages')

        if hasattr(self, '_pkg_venv') and self._pkg_venv:
            site_packages = 'lib/python2.7/site-packages'
            lib64_site_packages = 'lib64/python2.7/site-packages'
            if sys.platform == 'win32' or sys.platform == 'cygwin':
                lib64_site_packages = 'lib64\\site-packages'
                site_packages = 'lib\\site-packages'

            utils.copy_tree(os.path.join(self._pkg_venv, site_packages),
                            package)
            lib64_path = os.path.join(self._pkg_venv, lib64_site_packages)
            if not os.path.islink(lib64_path):
                LOG.info('Copying lib64 site packages')
                utils.copy_tree(lib64_path, package)

        # Append the temp workspace to the ignore list
        ignore.append("^%s/*" % self._temp_workspace)
        utils.copy_tree(self._path, package, ignore)
        self._create_zip(package)
Пример #11
0
    def package(self, ignore=[]):
        package = os.path.join(self._temp_workspace, 'lambda_package')

        # Copy site packages into package base
        LOG.info('Copying site packages')

        if hasattr(self, '_pkg_venv') and self._pkg_venv:
            site_packages = 'lib/python2.7/site-packages'
            lib64_site_packages = 'lib64/python2.7/site-packages'
            if sys.platform == 'win32' or sys.platform == 'cygwin':
                lib64_site_packages = 'lib64\\site-packages'
                site_packages = 'lib\\site-packages'

            utils.copy_tree(os.path.join(self._pkg_venv, site_packages),
                            package)
            lib64_path = os.path.join(self._pkg_venv, lib64_site_packages)
            if not os.path.islink(lib64_path):
                LOG.info('Copying lib64 site packages')
                utils.copy_tree(lib64_path, package)

        # Append the temp workspace to the ignore list
        ignore.append("^%s/*" % self._temp_workspace)
        utils.copy_tree(self._path, package, ignore)
        self._create_zip(package)