-
Notifications
You must be signed in to change notification settings - Fork 2
Making config file path dynamic #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
eac94a0
dfef04c
c07b0e2
3ce4a0c
c7d0760
1393f9f
7c0d69c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,23 @@ | ||
| from src.cranecloud.commands.apps import apps_group | ||
| from src.cranecloud.commands.clusters import clusters_group | ||
| import click | ||
| from os.path import join, dirname | ||
| from dotenv import load_dotenv | ||
| from src.cranecloud.utils.config import create_config | ||
| from src.cranecloud.utils.config import create_config , write_config , get_base_dir | ||
| from src.cranecloud.commands.user_management import user_group | ||
| from src.cranecloud.commands.projects import projects_group | ||
| from src.cranecloud.commands.config_management import config_group | ||
|
|
||
|
|
||
| dotenv_path = join(dirname(__file__), '.env') | ||
| load_dotenv(dotenv_path) | ||
| from src.cranecloud.commands.apps import apps_group | ||
| from src.cranecloud.commands.clusters import clusters_group | ||
| from pathlib import Path | ||
| from dotenv import set_key | ||
|
|
||
|
|
||
| @click.group() | ||
| def cli(): | ||
| pass | ||
|
|
||
|
|
||
| cli = click.CommandCollection( | ||
| sources=[user_group, projects_group, apps_group, clusters_group, config_group]) | ||
|
|
||
|
|
||
| def create_initial_config(): | ||
| create_config() | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,61 @@ | ||
|
|
||
| import os | ||
| import configparser | ||
| from dotenv import set_key | ||
| from pathlib import Path | ||
| from os.path import join, dirname | ||
| from dotenv import load_dotenv | ||
|
|
||
|
|
||
|
|
||
| CONFIG_FILE = 'config' | ||
|
|
||
| dotenv_path = join(dirname(__file__), '.env') | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't be here, rather in the initial file |
||
| load_dotenv(dotenv_path) | ||
|
|
||
|
|
||
|
|
||
| def get_base_dir(): | ||
| home_dir = os.path.expanduser("~") | ||
| crane_dir = os.path.join(home_dir, '.crane') | ||
| crane_dir = os.getenv('CRANE_CONFIG_DIR') | ||
| if not crane_dir: | ||
| config_dir = os.path.expanduser("~") | ||
| crane_dir = os.path.join(config_dir, '.crane') | ||
| return crane_dir | ||
|
|
||
|
|
||
| def create_config(): | ||
| def create_config(dir= get_base_dir()): | ||
| env_file_path = Path(join(dirname(__file__), '.env')) | ||
| env_file_path.touch(mode=0o600, exist_ok=True) | ||
|
|
||
| default_base_url = os.getenv('API_BASE_URL', "https://api.cranecloud.io") | ||
| set_key(dotenv_path=env_file_path, key_to_set="CRANE_CONFIG_DIR", value_to_set=dir , export=True) | ||
| write_config('base_url', default_base_url , crane_dir = dir) | ||
| write_config("dotenv_path" , dotenv_path , crane_dir=env_file_path) | ||
|
|
||
|
|
||
| def create_initial_config(): | ||
| env_file_path = Path(join(dirname(__file__), '.env')) | ||
| env_file_path.touch(mode=0o600, exist_ok=True) | ||
|
|
||
| config_dir = os.path.expanduser("~") | ||
| crane_dir = os.path.join(config_dir, '.crane') | ||
|
|
||
| set_key(dotenv_path=env_file_path, key_to_set="CRANE_CONFIG_DIR", value_to_set=crane_dir , export=True) | ||
| write_config("dotenv_path" , dotenv_path , crane_dir=crane_dir) | ||
|
|
||
| default_base_url = os.getenv('API_BASE_URL', "https://api.cranecloud.io") | ||
| write_config('base_url', default_base_url) | ||
| write_config('base_url', default_base_url , crane_dir=crane_dir) | ||
|
|
||
|
|
||
| def read_config(): | ||
| def read_config(crane_config = get_base_dir()): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove |
||
| config = configparser.ConfigParser() | ||
| crane_dir = get_base_dir() | ||
| config_file = os.path.join(crane_dir, CONFIG_FILE) | ||
| config_file = os.path.join(crane_config, CONFIG_FILE) | ||
| config.read(config_file) | ||
| return config | ||
|
|
||
|
|
||
| def write_config(key, value, should_update=True): | ||
| def write_config(key, value, should_update=True , crane_dir = get_base_dir()): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please revert this, we talked about removing |
||
| config = configparser.ConfigParser() | ||
| crane_dir = get_base_dir() | ||
| config_file = os.path.join(crane_dir, CONFIG_FILE) | ||
| os.makedirs(crane_dir, exist_ok=True) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove this? @LanternNassi