File: setup.py

package info (click to toggle)
python-oracledb 1.2.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 5,224 kB
  • sloc: python: 17,637; sql: 1,819; makefile: 41
file content (68 lines) | stat: -rw-r--r-- 1,578 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#! /usr/bin/env python3.9
#
# NAME
#
#   setup.py
#
# PURPOSE
#
#   Creates the python-oracledb sample schema after waiting for the database to
#   open.
#
# USAGE
#
#   ./setup.py

import oracledb
import os
import time

oracledb.init_oracle_client()

pw = os.environ.get("ORACLE_PASSWORD")
os.environ["PYO_SAMPLES_ADMIN_PASSWORD"] = pw

c = None

for i in range(30):
    try:
        c = oracledb.connect(user="system",
                             password=pw,
                             dsn="localhost/xepdb1",
                             tcp_connect_timeout=5)
        break
    except (OSError, oracledb.Error) as e:
        print("Waiting for database to open")
        time.sleep(5)

if c:
    print("PDB is open")
else:
    print("PDB did not open in allocated time")
    print("Try again in a few minutes")
    exit()


print("Enabling per-PDB DRCP")

c = oracledb.connect(mode=oracledb.SYSDBA)
cursor = c.cursor()
cursor.execute("alter pluggable database all close")
cursor.execute("alter system set enable_per_pdb_drcp=true scope=spfile sid='*'")

c = oracledb.connect(mode=oracledb.SYSDBA | oracledb.PRELIM_AUTH)
c.startup(force=True)

c = oracledb.connect(mode=oracledb.SYSDBA)
cursor = c.cursor()
cursor.execute("alter database mount")
cursor.execute("alter database open")

c = oracledb.connect(user="sys",
                     password=pw,
                     dsn="localhost/xepdb1",
                     mode=oracledb.SYSDBA)
cursor = c.cursor()
cursor.callproc("dbms_connection_pool.start_pool")

# create_schema.py will be appended here by the Dockerfile