Example #1
0
 def test_add_trailing_slash2(self):
     """testing adding a slash to a string that already has a slash"""
     test = add_trailing_slash("win/")
     expected = "win/"
     self.assert_equal(test, expected)
Example #2
0
    def copy_files_to_package_dir(self, extra_excludes=None):
        """Copys files from the branch into the destination file layout

        ready for packaging

        """
        if extra_excludes is None:
            extra_excludes = []

        package_config = self.package_config
        to_dir = package_config["working_dir"]
        from_dir = package_config["path"]

        build_exclusions = self.global_config["default_build_exclusions"] + self.global_config.get(
            "build_exclusions", []
        )

        # config based excludes
        if package_config.get("build_exclusions"):
            build_exclusions += package_config["build_exclusions"]

        mapped_files = []

        file_mapping = package_config.get("destination_mapping", {})

        # find which global_destination_map applies
        if self.global_config.get("destination_mapping"):

            global_mapping = self.global_config["destination_mapping"]
            global_mapping["root"] = global_mapping.get("root", "")

            # Create reverse destination mapping
            self.global_config["reverse_destination_mapping"] = {}

            for key, value in global_mapping.items():
                self.global_config["reverse_destination_mapping"][os.path.join(global_mapping["root"], value)] = key

            package_path = os.path.abspath(self.package_config["path"]).replace(self.global_config["base_path"], "")

            package_path = remove_leading_slash(package_path)

            # this is so we can walk up the path from the package root dir:
            # apps/blah wants to match the destination mapping for apps as well
            test_path = package_path
            global_mapping_root = global_mapping.get("root", "")
            found_mapping = False

            while len(test_path) > 0:
                # if we find something
                if global_mapping.get(test_path):
                    path_remainder = package_path.replace(test_path, "")
                    path_remainder = remove_leading_slash(path_remainder)

                    # append the relative path (from the matched key)
                    # so in the above example:
                    # in global:
                    # destination_mapping:
                    # apps: /foo/bar/apps

                    # so apps/blah wants to go to /foo/bar/apps/blah
                    global_mapping_root = os.path.join(global_mapping_root, global_mapping[test_path], path_remainder)
                    found_mapping = True

                    break
                # walk up
                test_path = "/".join(test_path.split("/")[:-1])

            # check that something was actually added else the path_remainder
            # is value.
            if not found_mapping:
                global_mapping_root = os.path.join(global_mapping_root, package_path)

            # overwrite the root mapping (if it starts with / ignore)
            root = file_mapping.get("root", "")
            file_mapping["root"] = os.path.join(global_mapping_root, root)

        # Check if file mapping exists

        if file_mapping != {}:

            if DEBUG:
                print "USING MAPPING"
            for key, value in file_mapping.items():

                if key == "root":
                    continue

                if not value.startswith("/"):
                    try:
                        value = os.path.join(file_mapping["root"], value)
                    except KeyError:
                        raise SuitcasePackagingError(
                            "You are using relative mapping settings in your " "debian file without setting a root"
                        )

                value = remove_leading_slash(value)

                # Joining paths to make absolute
                source = os.path.join(from_dir, key)
                destination = os.path.join(to_dir, value)

                mapped_files.append("/%s" % key)

                # do the magic
                if os.path.exists(source):
                    copy_files(source, destination, build_exclusions)

            file_mapping["root"] = file_mapping.get("root", "/")
            file_mapping["root"] = remove_leading_slash(file_mapping["root"])

            # AWOOGA - be careful with slashes as this tells rsync
            # whether it's creating the last dir in the destination or not
            # Now copy root (which will normally be everything)
            if len(mapped_files) > 0:
                build_exclusions += mapped_files

            copy_files(add_trailing_slash(from_dir), os.path.join(to_dir, file_mapping["root"]), build_exclusions)

            self.package_config["destination_mapping"] = file_mapping
        else:
            from_dir = add_trailing_slash(from_dir)
            extra_build_exclusions = package_config.get("build_exclusions", [])

            if extra_excludes:
                build_exclusions += extra_build_exclusions

            copy_files(from_dir, to_dir, build_exclusions)
            self.package_config["destination_mapping"] = {"root": ""}
Example #3
0
 def test_add_trailing_slash(self):
     """testing adding a slash"""
     test = add_trailing_slash("win")
     expected = "win/"
     self.assert_equal(test, expected)