Exemplo n.º 1
0
def generate_depends(global_config, package_config):
    """Generates the app dependencies automagically"""
    
    apps_path = package_config["path"].replace("apps","assets/apps")
    
    package_config["depends"] = merge_and_de_dupe(package_config["depends"])

    if os.path.isdir(apps_path):
        package_config["depends"] = merge_and_de_dupe(
            package_config["depends"],
            Debian.make_package_name(
                global_config["base_path"], 
                apps_path, 
                global_config.get("prefix"),
                global_config.get("package_name_filters")
            ) 
        )

    app_template_path = package_config["path"].replace(
        "apps", "templates/root/apps"
    )
    
    if os.path.isdir(app_template_path):
        
        package_config["depends"] = merge_and_de_dupe( 
            package_config["depends"],
            Debian.make_package_name(
                global_config["base_path"], 
                app_template_path, 
                global_config.get("prefix"),
                global_config.get("package_name_filters")
            ) 
        )
    
    return package_config
Exemplo n.º 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
Exemplo n.º 3
0
class DebianTestCase(unittest.TestCase):

    """Test suite of tests for the debian packaging class"""

    def assert_equal(self, result, expected):
        """Wraps assertEqual for convenience"""
        return self.assertEqual(
            result,
            expected,
            "%s should be %s" % (result, expected,),
        )

    def setUp(self):
        """Sets up and instantiates the package class"""
        self.deb = Debian()

    def tearDown(self):
        """Tears down the package class"""
        self.deb = None

    def test_invalid_package_name(self):
        """Testing package name validation when package name is invalid"""
        package_name = 'fhjdskfh-900u78*'
        self.assertFalse(self.deb.is_valid_package_name(package_name))

    def test_valid_package_name(self):
        """Testing package name validation when package name is valid"""
        package_name = 'my-awesome-package'
        self.assertTrue(self.deb.is_valid_package_name(package_name))

    def test_package_name_normalisation(self):
        """Test that the package name normalisation works"""
        unnormalised_name = "test_this_test-name"
        expected = "test-this-test-name"
        self.assert_equal(
            self.deb.normalise_package_name(unnormalised_name),
            expected
        )

    def test_package_name_length(self):
        """Test that the package name length is valid"""
        test_string = "A short description"
        self.assertTrue(self.deb.is_valid_description_length(test_string))

    def test_package_name_length2(self):
        """Test that the package name length is invalid when over 60 chars"""

        test_string = "Lorem ipsum dolor sit amet, consectetur adipisicing "\
            "elit, sed do eiusmod tempor incididunt ut labore et dolore magna"\
            " aliqua. Ut enim ad minim veniam, quis nostrud exercitation "\
            "ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis "\
            "aute irure dolor in reprehenderit in voluptate velit esse cillum"\
            " dolore eu fugiat nulla pariatur. Excepteur sint occaecat "\
            "cupidatat non proident, sunt in culpa qui officia deserunt "\
            "mollit anim id est laborum."

        self.assertFalse(self.deb.is_valid_description_length(test_string))

    def test_make_package_name(self):
        """Test package name generation from paths"""
        this_dir = "/".join(os.path.abspath(__file__).split("/")[:-1])
        base_path = os.path.abspath(os.path.realpath(
            os.path.join(this_dir, "../../tests/package_test")
        ))
        path = os.path.join(base_path, "apps/suitcase_test")
        package_name = self.deb.make_package_name(base_path, path)
        expected = "apps-suitcase-test"
        self.assert_equal(package_name, expected)

    def test_make_package_name_wprefix(self):
        """Test package name generation from paths with prefix"""
        this_dir = "/".join(os.path.abspath(__file__).split("/")[:-1])
        base_path = os.path.abspath(os.path.realpath(
            os.path.join(this_dir, "../../tests/package_test")
        ))
        path = os.path.join(base_path, "apps/suitcase_test")
        package_name = self.deb.make_package_name(base_path, path, 'gcap')
        expected = "gcap-apps-suitcase-test"
        self.assert_equal(package_name, expected)

    def test_make_package_name_wfilter(self):
        """Test package name generation from paths with filter"""
        this_dir = "/".join(os.path.abspath(__file__).split("/")[:-1])
        base_path = os.path.abspath(
            os.path.realpath(os.path.join(this_dir, "../../tests/package_test")
        ))
        path = os.path.join(base_path, "apps/suitcase_test")
        package_name = self.deb.make_package_name(
            base_path, path, "gcap", { "suitcase": "awesome" }
        )
        expected = "gcap-apps-awesome-test"
        self.assert_equal(package_name, expected)
Exemplo n.º 4
0
 def setUp(self):
     """Sets up and instantiates the package class"""
     self.deb = Debian()