# Python 3 Migration Notes for DatabaseInitialisation Scripts This directory contains Python scripts ported from Python 2 to Python 3 for the Qt6 migration. ## Changes Applied ### 1. Import Statements - `ConfigParser` → `configparser` - Added `#!/usr/bin/env python3` shebang to all scripts ### 2. Exception Handling - `except getopt.GetoptError, err:` → `except getopt.GetoptError as err:` - `except Exception, e:` → `except Exception as e:` ### 3. Print Statements - `print "message"` → `print("message")` - `print >>sys.stderr, "error"` → `print("error", file=sys.stderr)` ### 4. String Methods - `string.replace(s, old, new)` → `s.replace(old, new)` (method call on string object) ### 5. Bytes vs Strings - `bRet == '1'` → `bRet == b'1'` (comparing bytes to bytes) - `f.write('\n'.join(sql_stmts))` → `f.write('\n'.join(sql_stmts).encode('utf-8'))` ### 6. ConfigParser API - `ConfigParser.ConfigParser()` → `configparser.ConfigParser()` - `config.get()` now raises `configparser.Error` instead of generic exceptions ## Usage All scripts can be executed with Python 3: ```bash python3 create_excon_db.py -p guez -c /etc/lts-cc.conf ``` Or make them executable and run directly: ```bash chmod +x create_excon_db.py ./create_excon_db.py -p guez ``` ## Database Initialization via db-manage.sh The recommended way to initialize databases is via the `db-manage.sh` script: ```bash ./db-manage.sh init-db guez ./db-manage.sh init-db ahtc ./db-manage.sh init-db test-db ``` This script handles container management and script execution automatically. ## Tested With - Python 3.8+ - PostgreSQL 18 - Ubuntu 22.04 / 24.04