Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

config.py 753 B

You have to be logged in to leave a comment. Sign In
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
  1. """
  2. Output configuration information.
  3. Usage:
  4. config.py --database (--url | --env)
  5. """
  6. from docopt import docopt
  7. from bookdata import db
  8. from bookdata import script_log
  9. _log = script_log(__file__)
  10. def _print_env(src, attr, var):
  11. val = getattr(src, attr, None)
  12. if val is not None:
  13. print(f"export {var}='{val}'")
  14. def db_config(opts):
  15. cfg = db.DBConfig.load()
  16. if opts['--url']:
  17. print(cfg.url())
  18. elif opts['--env']:
  19. _print_env(cfg, 'host', 'PGHOST')
  20. _print_env(cfg, 'port', 'PGPORT')
  21. _print_env(cfg, 'database', 'PGDATABASE')
  22. _print_env(cfg, 'user', 'PGUSER')
  23. _print_env(cfg, 'password', 'PGPASSWORD')
  24. opts = docopt(__doc__)
  25. if opts['--database']:
  26. db_config(opts)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...