def run_safe_validations(handler): """This function runs all the validations that can safely be done without running user code. It returns the common parent directory of the archive. """ logger.info(">> Running safe validations") # check archive format namelist = handler.get_namelist() common_dir = validate_archive_files(namelist) logger.debug("Common directory is %s" % common_dir) # check for and then read configuration file config_file = common_dir + os.sep + DJANGO_CFG_FILENAME if not handler.is_file_in_archive(config_file): raise FileMissingError("Archive missing configuration file %s" % config_file) fileobj = handler.open_member(config_file) data = fileobj.read() django_config = django_config_from_json(data, COMPATIBLE_PACKAGER_VERSION) # check for additional_components file and parse if present components_file = common_dir + os.sep + COMPONENTS_FILENAME if handler.is_file_in_archive(components_file): fileobj = handler.open_member(components_file) read_components_file(fileobj, components_file, django_config.components) else: if len(django_config.components)>0: raise ValidationError("No additional component file at %s, but application with packaged with an additional component file" % filepath) # check for other required files settings_module_file = django_config.get_settings_module_file() if not handler.is_file_in_archive(settings_module_file): raise FileMissingError("Archive missing django settings file %s" % settings_module_file) logger.debug("Has required files") return (common_dir, django_config)
def run(self): if self.django_settings_module: ds_mod = self.django_settings_module django_config = None else: config_file = os.path.join(self.app_dir_path, DJANGO_CFG_FILENAME) if not os.path.exists(config_file): raise FileMissingError("Missing configuration file %s" % config_file) with open(config_file, "rb") as fileobj: django_config = django_config_from_json(fileobj.read(), COMPATIBLE_PACKAGER_VERSION) ds_mod = django_config.django_settings_module results = validate_settings(self.app_dir_path, ds_mod, django_config) write_json(results.to_json(), self.results_file) results.print_final_status_message(logger) return results.get_return_code()