|
|
|
@ -1,23 +1,3 @@ |
|
|
|
""" |
|
|
|
|
|
|
|
env_manager.py |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This script initializes a connection to an ArangoDB database and retrieves all documents from the 'enviroment' collection. |
|
|
|
|
|
|
|
It attempts to load environment variables from a .env file to get the ArangoDB password. If the .env file is not found, |
|
|
|
|
|
|
|
it prompts the user to input the password manually. It then connects to the ArangoDB instance using the provided credentials |
|
|
|
|
|
|
|
and returns the first document from the 'enviroment' collection. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Modules: |
|
|
|
|
|
|
|
os: Provides a way of using operating system dependent functionality. |
|
|
|
|
|
|
|
arango: Provides a client for interacting with ArangoDB. |
|
|
|
|
|
|
|
dotenv: Loads environment variables from a .env file. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Functions: |
|
|
|
|
|
|
|
get_env: Initializes a connection to an ArangoDB database and retrieves the first document from the 'enviroment' collection. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Usage: |
|
|
|
|
|
|
|
Run this script to connect to the ArangoDB database and print the first document from the 'enviroment' collection. |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import os |
|
|
|
import os |
|
|
|
try: |
|
|
|
try: |
|
|
|
from arango import ArangoClient |
|
|
|
from arango import ArangoClient |
|
|
|
@ -59,6 +39,15 @@ def get_env(): |
|
|
|
|
|
|
|
|
|
|
|
# Initialize the database for ArangoDB. |
|
|
|
# Initialize the database for ArangoDB. |
|
|
|
db = ArangoClient(hosts=host).db(db, username=username, password=pwd) |
|
|
|
db = ArangoClient(hosts=host).db(db, username=username, password=pwd) |
|
|
|
return db.collection('enviroment').all().next() |
|
|
|
env_doc = db.collection('enviroment').all().next() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Set the environment variables |
|
|
|
|
|
|
|
for key, value in env_doc.items(): |
|
|
|
|
|
|
|
if isinstance(value, dict): |
|
|
|
|
|
|
|
continue |
|
|
|
|
|
|
|
os.environ[key] = str(value) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return env_doc |
|
|
|
|
|
|
|
|
|
|
|
env = get_env() |
|
|
|
# Retrieve and set environment variables |
|
|
|
|
|
|
|
env = get_env() |
|
|
|
|