Skip to content

Instantly share code, notes, and snippets.

@sam2332
Last active September 19, 2023 15:16
Show Gist options
  • Save sam2332/e9c2e6ba8f1dc04385680b7acd7341f1 to your computer and use it in GitHub Desktop.
Save sam2332/e9c2e6ba8f1dc04385680b7acd7341f1 to your computer and use it in GitHub Desktop.
Convert rdl to a old version so i can load it into a ancient version of ms business studio
import click
import logging
# Initialize logging
logging.basicConfig(level=logging.INFO)
def modify_rdl_for_sql2014(original_rdl):
lines = original_rdl.split('\n')
new_lines = []
in_report_parameters_layout = False
for line in lines:
line_stripped = line.strip().lower()
if line_stripped.startswith('<report'):
if '<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">' not in new_lines:
new_lines.append('<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">')
elif 'reportsections' in line_stripped:
continue
elif 'reportparameterslayout' in line_stripped:
in_report_parameters_layout = not in_report_parameters_layout
continue
elif in_report_parameters_layout:
continue
else:
new_lines.append(line.strip())
return '\n'.join(new_lines)
@click.command()
@click.argument('input_rdl_path', type=click.Path(exists=True))
@click.option('--output_rdl_path', type=click.Path(), default=None, help='Optional output path, defaults to overwriting input file if not given.')
def modify_rdl_for_sql2014_cli(input_rdl_path, output_rdl_path):
if output_rdl_path is None:
output_rdl_path = input_rdl_path
logging.info(click.style('Starting RDL modification...', fg='green'))
with open(input_rdl_path, 'r', encoding='utf-8') as infile:
original_rdl = infile.read()
modified_rdl = modify_rdl_for_sql2014(original_rdl)
with open(output_rdl_path, 'w', encoding='utf-8') as outfile:
outfile.write(modified_rdl)
logging.info(click.style('RDL modification completed.', fg='green'))
# Uncomment this line to run the script
if __name__ == '__main__':
modify_rdl_for_sql2014_cli()
# Importing required modules for CLI and logging
import click
import logging
# Initialize logging
logging.basicConfig(level=logging.INFO)
# Function to modify RDL for SQL 2014 using raw text processing based on the user's instructions
@click.command()
@click.argument('input_rdl_path', type=click.Path(exists=True))
@click.option('--output_rdl_path', type=click.Path(), default=None, help='Optional output path, defaults to overwriting input file if not given.')
def modify_rdl_for_sql2014_cli(input_rdl_path, output_rdl_path):
"""Modify an RDL file to make it compatible with SQL 2014."""
if output_rdl_path is None:
output_rdl_path = input_rdl_path
"""Modify an RDL file to make it compatible with SQL 2014."""
logging.info(click.style('Starting RDL modification...', fg='green'))
with open(input_rdl_path, 'r') as infile:
lines = infile.readlines()
new_lines = []
in_report_parameters_layout = False
for line in lines:
line_stripped = line.strip().lower()
if line_stripped.startswith('<report'):
new_lines.append('<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">')
logging.info(click.style('Updated xmlns attribute.', fg='yellow'))
elif 'reportsections' in line_stripped:
continue
elif 'reportparameterslayout' in line_stripped:
in_report_parameters_layout = not in_report_parameters_layout
continue
elif in_report_parameters_layout:
continue
else:
new_lines.append(line.strip())
with open(output_rdl_path, 'w') as outfile:
outfile.write('\n'.join(new_lines))
logging.info(click.style('RDL modification completed.', fg='green'))
# Uncomment this line before running the script as a standalone CLI tool
if __name__ == '__main__':
modify_rdl_for_sql2014_cli()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment