def test_singleton_works(self): """Test singleton instance creation""" import_string = "suitcase.vcs.subversion" module = dynamic_import(import_string) # Create first instance instance = module.Subversion() # Create Second instance instance2 = module.Subversion() # Both instances should occupy the same memory space self.assert_equal(instance, instance2)
def run_hook(self, method_label): """dynamically call pre/post conf methods as defined in package_conf""" for method in self.get_hook(method_label): conf_module = dynamic_import(".".join(method.split(".")[:-1])) try: return_val = getattr( conf_module,method.split(".")[-1] )(self.global_config,self.package_config) if return_val: self.package_config = return_val except AttributeError, error: raise SuitcaseImportError( "%s hook %s not found:\n%s" % (method_label, method, error) )
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
def test_dynamic_import(self): """Test the dynamic import works""" import_string = "suitcase.vcs.subversion" module = dynamic_import(import_string) self.assert_equal(import_string, module.__name__)