| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- from pathlib import Path
- import typer
- import config
- import database
- app = typer.Typer()
- cfg = config.Config()
- @app.command()
- def create(config_file: str):
- config_file = cfg.system_dir + f"\\SQL\\config\\{config_file}.json"
- database.create(config_file)
- @app.command()
- def compare(config_file: str):
- config_file = cfg.system_dir + f"\\SQL\\config\\{config_file}.json"
- database.compare(config_file)
- @app.command()
- def run(config_file: str, increment: str = "1", max: int = 5):
- """
- Executes a database operation using a specified configuration file.
- Args:
- config_file (str): The name of the configuration file (without extension) to use, located in the SQL config directory.
- increment (str, optional): Determines whether to increment; treated as True if "1", otherwise False. Defaults to "1".
- max (int, optional): The maximum number of operations to perform. Defaults to 5.
- Returns:
- None
- """
- config_file = cfg.system_dir + f"\\SQL\\config\\{config_file}.json"
- database.run(config_file, increment == "1", max)
- bcp_log()
- @app.command()
- def run_folder(folder: str):
- folder_list = [
- Path(folder),
- Path(cfg.system_dir + "\\SQL\\exec\\" + folder),
- Path(cfg.system_dir + "\\Export\\SQL\\" + folder),
- ]
- for f in folder_list:
- if f.exists() and f.is_dir():
- folder = str(f.resolve())
- break
- print(folder)
- for sql_file in Path(folder).glob("*.sql"):
- print(f"call sqlexec2.bat {sql_file}")
- @app.command()
- def schema():
- database.schema()
- @app.command()
- def bcp_log():
- logs_dir = cfg.system_dir + "\\SQL\\logs"
- if not Path(logs_dir).exists():
- logs_dir = cfg.system_dir + "\\SQL\\temp"
- output_file = cfg.log_dir + "\\bcp.csv.log"
- database.bcp_log(logs_dir, output_file)
- if __name__ == "__main__":
- app()
|