Beispiel #1
0
    def move_package(self):
        """Moves packages from temp dir to a repo dir specified in the config"""

        # Only move if the no_move isn't set
        if not self.global_config['no_move']:
            (exists, source, destination) = \
                self.check_package_file(self.package_config)

            if not os.path.exists(destination):
                try:
                    os.makedirs(destination)
                except OSError, error:
                    raise SuitcasePackagingError(error)
                    
            if exists:
                display_warning(
                    "Suitcase Warning: Package %s already exists in"\
                    " destination; skipping file move..." \
                    % self.package_config['package_filename']
                )
            else:
                copy_files(source, destination)
Beispiel #2
0
def generate_depends(global_config, package_config):
    """Generates the config dependencies automagically"""

    # now export the root as whatever is in export_base_path_as
    if global_config.get("export_base_path_as"):
        
        relative_import(
            global_config["base_path"],
            global_config["export_base_path_as"]
        )
    
        # now load the config.settings file 
        config_path = package_config["path"]

        if config_path.endswith("/"):
            config_path = config_path[:-1]

        # make the config module name
        config_module = "configs.%s.settings" % config_path.split("/")[-1]

        if global_config.get("prefix"):
            config_module = "%s.%s" % (global_config["prefix"], config_module)

        package_config["depends"] = merge_and_de_dupe(
            package_config["depends"]
        )

        try:
            config_settings = dynamic_import(config_module)
            for app in config_settings.INSTALLED_APPS:
                if "django.contrib.admin" in app:
                    
                    migration_package = Debian.make_package_name(
                        global_config["base_path"],
                        os.path.join(global_config["base_path"],"migrations"), 
                        global_config.get("prefix"),
                        global_config.get("package_name_filters")
                    )
                    
                    # work out migration package
                    migration_config = {
                        "path":os.path.join(global_config["base_path"],"migrations")
                    }
                    
                    migration_version = Debian(global_config).get_package_version(
                        migration_config
                    )
                    
                    package_config["depends"] = merge_and_de_dupe(
                        package_config["depends"],
                        "%s (>=%s)" % (
                            migration_package,
                            migration_version
                        )
                    )

                elif not app.startswith("django"):
                    app_package = Debian.normalise_package_name(
                        app,
                        global_config.get("package_name_filters")
                    )
                    
                    package_config["depends"] = merge_and_de_dupe(
                        package_config["depends"],app_package
                    )
        except:
            display_warning('Suitcase Warning: No settings file found for config package %s' % package_config["package"])

    if package_config.get("target_hosts"):
        
        for host in package_config["target_hosts"]:
            asset_path = os.path.join(
                global_config["base_path"],
                "assets",
                "domains",
                host
            )
            
            if os.path.exists(asset_path):
                
                package_config["depends"] = merge_and_de_dupe(
                    package_config["depends"],
                    Debian.make_package_name(
                        global_config["base_path"],
                        asset_path, 
                        global_config.get("prefix"),
                        global_config.get("package_name_filters")
                    )
                )

            template_path = os.path.join(
                global_config["base_path"], 
                "templates", 
                "root",
                "domains",
                host
            )
            
            if os.path.exists(template_path):
                package_config["depends"] = merge_and_de_dupe(
                    package_config["depends"],
                    Debian.make_package_name(
                        global_config["base_path"],
                        template_path, 
                        global_config.get("prefix"),
                        global_config.get("package_name_filters")
                    )
                )

    return package_config
Beispiel #3
0
def assets(global_config, package_config):

    """Generates a dictionary of asset versions"""

    vcs = global_config.get('version_control')
    if vcs:
        # dynamically import the vcs code
        vcs_module = 'suitcase.vcs.%s' % vcs
        vcs_instance = get_dynamic_class_instance(vcs_module, vcs.capitalize())

    asset_dir = os.path.abspath(
        os.path.join(package_config["working_dir"],
        package_config["destination_mapping"]["root"])
    )
    
    target_dir = os.path.abspath(os.path.join(asset_dir,"../"))
    if os.path.exists(target_dir):
        asset_versions = {}
        for path, dirs, files in os.walk(target_dir):
            if 'tiny_mce' in dirs:
                dirs.remove('tiny_mce')

            for file_path in files:
                original_path = os.path.join(path, file_path)
                original_path = original_path.replace(target_dir, "")
                
                file_path = os.path.join(path, file_path)\
                    .replace(package_config["working_dir"], "")

                branch_path = file_path
                while len(branch_path) > 0:
                    if global_config["reverse_destination_mapping"]\
                        .get(branch_path):
                        
                        remainder = file_path.replace(branch_path, "")
                        remainder = remove_leading_slash(remainder)

                        file_path = os.path.join(
                            global_config["base_path"],
                            global_config["reverse_destination_mapping"]\
                                [branch_path],
                            remainder
                        )
                        
                        break
                    branch_path = "/".join(branch_path.split("/")[:-1])    

                non_minified_file = file_path.replace('-minified.js', '.js')
                if file_path.endswith("-minified.js") and \
                    os.path.exists(non_minified_file):

                    file_path = non_minified_file

                try:
                    version = vcs_instance.get_directory_revision(file_path)
                    
                except SuitcaseVcsError:
                    display_warning(
                        "Suitcase Warning: Can't find version "\
                        "for %s setting to package version: %s" % \
                        (original_path,package_config["version"])
                    )
                    version = package_config["version"]

                asset_versions[original_path] = version

        asset_versions[asset_dir.replace(target_dir, "")] = \
            package_config["version"]
        
        asset_version_file = os.path.join(
            package_config["working_dir"], 
            "etc/suitcase/asset_versions/",
            "%s.py"%package_config["package"]
        )
        
        asset_version_dir = os.path.split(asset_version_file)[0]
        
        if not os.path.exists(asset_version_dir):
            try:
                os.makedirs(asset_version_dir)
            except OSError, error:
                raise SuitcasePackagingError(error)
            
        open(asset_version_file,"w").write(
            "asset_versions=%s" % pprint.pformat(asset_versions)
        )
         
        package_config["configs"] = package_config.get("configs", [])
        package_config["configs"].append(asset_version_file)
        package_config["asset_versions"] = asset_versions
        return package_config
Beispiel #4
0
    def find_build_dirs(self, start_path, **kwargs):
        """Does a walk down from path and builds a dictionary of packages

        build_dict is a dictionary keyed from the path of the package
        and will be used  as the master configuration for the package
        building process.

        """
        # Get the package conf filename from the config or defaults to the 
        # name of the packaging system
        package_conf_name = kwargs.get(
            'package_conf_name',
            "%s.yml" % self.global_config['package_format']
        )

        if DEBUG:
            import pprint
            print "GLOBAL_CONFIG:" ,
            pprint.pprint(self.global_config)

        build_dict = {}
        for root, dirs, files in os.walk(start_path):

            exclusions = self.global_config.get('path_exclusions', []) \
                + self.global_config.get("default_path_exclusions", [])

            # Remove exclusions from the walking path
            for exclusion in exclusions:
                if exclusion in dirs:
                    dirs.remove(exclusion)

            # update this key with the collection data
            collection = self.find_collection_conf(root)

            # if foo.yml exists or there's a collection above us...
            if package_conf_name in files or collection:
                package_config = {}

                # get the package_conf file and load the conf
                file_path = os.path.join(root, package_conf_name)
                if os.path.exists(file_path):
                    package_config = yaml.load(open(file_path).read())
                    if package_config is None:
                        raise SuitcaseConfigurationError(
                            "Config file %s is invalid" % file_path
                        )

                # get package name
                package_config['path'] = root

                package_name = self.get_package_name(package_config)
                if DEBUG:
                    print "PACKAGE_NAME: %s" % package_name

                # Check for package dupes
                if build_dict.get(package_name):
                    raise SuitcasePackagingError(
                        "A duplicate package name exists."\
                        " Please check %s" % file_path
                    )
            
                else:

                    build_dict[root] = {}

                    if collection:
                        build_dict[root]=deepcopy(collection)

                    package_config["architecture"] = package_config.get(
                        "architecture", 
                        build_dict[root].get(
                            'architecture',
                            "all"
                        )
                    )
                    
                    package_config['version'] = self.get_package_version(
                        package_config
                    )
                    
                    package_config['package'] = package_name

                    package_config['package_filename'] = \
                        self.make_package_filename(package_config)

                    package_preexists = \
                        self.check_package_file(package_config)[0]

                    if not self.global_config['force_build'] and \
                        package_preexists:
                        if not self.global_config['quiet']:
                            display_warning(
                                "Suitcase Warning: Package %s already "\
                                "exists; skipping build..." \
                                % package_config['package_filename']
                            )
                        del build_dict[root]
                        # update this key with the rest of the data from 
                        # package_config
                    elif package_config['version'] < ("0.%s" % \
                        self.global_config['limit_from']):
                        if not self.global_config['quiet']:
                            display_warning("Suitcase Warning: Package "\
                                "version %s below limit; skipping build..." \
                                % package_config['version']
                            )
                        del build_dict[root]
                    else:
                        build_dict[root].update(deepcopy(package_config))


        if build_dict != {}:
            return build_dict
        else:
            raise SuitcasePackagingError(
                "No packages to build from walking %s" % start_path
            )