def generate_redirect_pages():
    redirects_folder = path.join(root_folder, 'redirects')
    for (root, dirs, files) in os.walk(redirects_folder):
        for file in files:
            if (not file.endswith('.yml')):
                continue
            redirects_file_path = path.join(redirects_folder, file)
            with open(redirects_file_path, encoding='UTF-8') as stream:
                try:
                    redirects = yaml.load(stream, Loader=FullLoader)
                    for entry in redirects:
                        url_to = entry['to']
                        url_from = entry['from']
                        url_list = (url_from if isinstance(url_from, list) else [url_from])
                        for url in url_list:
                            app.add_url_rule(url, view_func=RedirectTemplateView.as_view(url, url=url_to))
                except yaml.YAMLError as exc:
                    sys.stderr.write((('Cant parse data file ' + file) + ': '))
                    sys.stderr.write(str(exc))
                    sys.exit((- 1))
                except IOError as exc:
                    sys.stderr.write((('Cant read data file ' + file) + ': '))
                    sys.stderr.write(str(exc))
                    sys.exit((- 1))
def generate_redirect_pages():
    redirects_folder = path.join(root_folder, 'redirects')
    for (root, dirs, files) in os.walk(redirects_folder):
        for file in files:
            if (not file.endswith('.yml')):
                continue
            redirects_file_path = path.join(redirects_folder, file)
            with open(redirects_file_path, encoding='UTF-8') as stream:
                try:
                    redirects = yaml.load(stream, Loader=FullLoader)
                    for entry in redirects:
                        url_to = entry['to']
                        url_from = entry['from']
                        url_list = (url_from if isinstance(url_from, list) else [url_from])
                        for url in url_list:
                            app.add_url_rule(url, view_func=RedirectTemplateView.as_view(url, url=url_to))
                except yaml.YAMLError as exc:
                    sys.stderr.write((('Cant parse data file ' + file) + ': '))
                    sys.stderr.write(str(exc))
                    sys.exit((- 1))
                except IOError as exc:
                    sys.stderr.write((('Cant read data file ' + file) + ': '))
                    sys.stderr.write(str(exc))
                    sys.exit((- 1))