-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexsql.py
More file actions
101 lines (72 loc) · 2.05 KB
/
Copy pathexsql.py
File metadata and controls
101 lines (72 loc) · 2.05 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import typer
from typer import Typer
import subprocess
import os
from src.configmanager import ConfigManager
from src.usepassword import use_password
from src.psql import Psql
from common.schemas import *
from rich import print
if not os.path.exists('config.ini'):
with open('config.ini.template', 'r') as template:
with open('config.ini', 'w') as real:
real.write(template.read())
config = ConfigManager('config.ini')
app = Typer()
@app.command()
def login(u: str, p: str, s: str = 'localhost', port: int = 5432):
'''
Saves your login into config.init to use in others commands
Args:
u: Server User.
p: User password.
s: Server (default localhost),
port: Connection Port (default 5432)
Returns:
None
Raises:
I don't know
'''
configs: list[tuple[str, str]] = [
('user', u),
('password', p),
('server', s),
('port', str(port))
]
for values in configs:
config.set('login', *values)
config.save()
@app.command()
@use_password(config)
def init(database_name: str):
'''
Create a new database with the base configuration needed for exsql
Args:
database_name: Name of the new database.
Returns:
None
Raises:
I don't know
'''
psql = Psql(config_file=config)
create_result = psql.execute(f"CREATE DATABASE {database_name};", shell=True)
psql.move(database_name)
schema_result = add_default_schema(psql)
print(create_result, schema_result)
@app.command()
@use_password(config)
def transfer(database_name: str):
'''
Adds base configuration to an already created database
Args:
database_name: Name of the database.
Returns:
None
Raises:
I don't know
'''
psql = Psql(config_file=config, database=database_name)
schema_result = add_default_schema(psql)
print(schema_result)
if __name__ == '__main__':
app()