Skip to content

Commit

Permalink
fix(utils/fn_reset_config): fixed missing default values for paths in…
Browse files Browse the repository at this point in the history
… reset config function
  • Loading branch information
MRColorR committed Dec 10, 2024
1 parent 702ecaa commit ed138f0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config/m4b-config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"project": {
"project_version": "4.4.0",
"project_version": "4.4.1",
"compose_project_name": "money4band",
"ds_project_server_url": "https://discord.com/invite/Fq8eeazBAD"
},
Expand Down
3 changes: 3 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from utils.fn_reset_config import main as reset_main
from utils.updater import check_update_available


def mainmenu(m4b_config_path: str, apps_config_path: str, user_config_path: str, utils_dir_path: str) -> None:
"""
Main menu of the script.
Expand Down Expand Up @@ -108,6 +109,7 @@ def mainmenu(m4b_config_path: str, apps_config_path: str, user_config_path: str,
logging.error(f"An error occurred while processing the menu: {str(e)}")
raise


def main():
# Get the script absolute path and name
script_dir = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -170,5 +172,6 @@ def main():
logging.error(f"An error occurred: {str(e)}")
raise


if __name__ == '__main__':
main()
5 changes: 4 additions & 1 deletion utils/fn_reset_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import json
from typing import Dict, Any, Optional


def reset_config(src_path: str, dest_path: str) -> None:
"""
Resets a configuration file by copying from the source path to the destination path.
Expand Down Expand Up @@ -40,7 +41,8 @@ def reset_config(src_path: str, dest_path: str) -> None:
logger.error(f"An unexpected error occurred: {str(e)}")
raise

def main(app_config_path: str, m4b_config_path: str, user_config_path: str, src_path: str, dest_path: str) -> None:

def main(app_config_path: str, m4b_config_path: str, user_config_path: str, src_path: str = './template/user-config.json', dest_path: str = './config/user-config.json') -> None:
"""
Main function to call the reset_config function.
Expand All @@ -53,6 +55,7 @@ def main(app_config_path: str, m4b_config_path: str, user_config_path: str, src_
"""
reset_config(src_path=src_path, dest_path=dest_path)


if __name__ == '__main__':
# Get the script absolute path and name
script_dir = os.path.dirname(os.path.abspath(__file__))
Expand Down
16 changes: 15 additions & 1 deletion utils/fn_setupApps.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,30 @@
from utils.fn_stopStack import stop_stack, stop_all_stacks
from utils.networker import find_next_available_port


def configure_email(app: Dict, flag_config: Dict, config: Dict):
email = ask_email(f'Enter your {app["name"].lower().title()} email:', default=config.get("email"))
config['email'] = email


def configure_password(app: Dict, flag_config: Dict, config: Dict):
print(f'Note: If you are using login with Google, remember to set also a password for your {app["name"].lower().title()} account!')
password = ask_string(f'Enter your {app["name"].lower().title()} password:', default=config.get("password"))
config['password'] = password


def configure_apikey(app: Dict, flag_config: Dict, config: Dict):
print(f'Find/Generate your APIKey inside your {app["name"].lower().title()} dashboard/profile.')
apikey = ask_string(f'Enter your {app["name"].lower().title()} APIKey:', default=config.get("apikey"))
config['apikey'] = apikey


def configure_userid(app: Dict, flag_config: Dict, config: Dict):
print(f'Find your UserID inside your {app["name"].lower().title()} dashboard/profile.')
userid = ask_string(f'Enter your {app["name"].lower().title()} UserID:', default=config.get("userid"))
config['userid'] = userid


def configure_uuid(app: Dict, flag_config: Dict, config: Dict):
print(f'Starting UUID generation/import for {app["name"].lower().title()}')
if 'length' not in flag_config:
Expand Down Expand Up @@ -83,22 +88,26 @@ def configure_uuid(app: Dict, flag_config: Dict, config: Dict):
uuid = f'{prefix}{uuid}'
config['uuid'] = uuid


def configure_cid(app: Dict, flag_config: Dict, config: Dict):
print(f'Find your CID inside your {app["name"].lower().title()} dashboard/profile.')
print("Example: For packetstream you can fetch it from your dashboard https://packetstream.io/dashboard/download?linux# then click on -> Looking for linux app -> now search for CID= in the code shown in the page, you need to enter the code after -e CID= (e.g. if in the code CID=6aTk, just enter 6aTk)")
cid = ask_string(f'Enter your {app["name"].lower().title()} CID:', default=config.get("cid"))
config['cid'] = cid


def configure_code(app: Dict, flag_config: Dict, config: Dict):
print(f'Find your code inside your {app["name"].lower().title()} dashboard/profile.')
code = ask_string(f'Enter your {app["name"].lower().title()} code:', default=config.get("code"))
config['code'] = code


def configure_token(app: Dict, flag_config: Dict, config: Dict):
print(f'Find your token inside your {app["name"].lower().title()} dashboard/profile.')
token = ask_string(f'Enter your {app["name"].lower().title()} token:', default=config.get("token"))
config['token'] = token


def configure_manual(app: Dict, flag_config: Dict, config: Dict):
if 'instructions' not in flag_config:
print(f'{Fore.RED}Error: Instructions not provided for manual configuration{Style.RESET_ALL}')
Expand All @@ -108,6 +117,7 @@ def configure_manual(app: Dict, flag_config: Dict, config: Dict):
print(f'{Fore.YELLOW}Please after completing this automated setup check also the app\'s website for further instructions if there are any.{Style.RESET_ALL}')
input('Press enter to continue...')


flag_function_mapper = {
'email': configure_email,
'password': configure_password,
Expand All @@ -120,6 +130,7 @@ def configure_manual(app: Dict, flag_config: Dict, config: Dict):
'manual': configure_manual
}


def collect_user_info(user_config: Dict[str, Any], m4b_config: Dict[str, Any]) -> None:
"""
Collect user information and update the user configuration.
Expand Down Expand Up @@ -209,6 +220,7 @@ def _configure_apps(user_config: Dict[str, Any], apps: Dict, m4b_config: Dict):
user_config['apps'][app_name] = config
time.sleep(m4b_config['system']['sleep_time'])


def configure_apps(user_config: Dict[str, Any], app_config: Dict, m4b_config: Dict) -> None:
"""
Configure apps by collecting user inputs.
Expand All @@ -220,6 +232,7 @@ def configure_apps(user_config: Dict[str, Any], app_config: Dict, m4b_config: Di
"""
_configure_apps(user_config, app_config['apps'], m4b_config)


def configure_extra_apps(user_config: Dict[str, Any], app_config: Dict, m4b_config: Dict) -> None:
"""
Configure extra apps by collecting user inputs.
Expand All @@ -231,6 +244,7 @@ def configure_extra_apps(user_config: Dict[str, Any], app_config: Dict, m4b_conf
"""
_configure_apps(user_config, app_config['extra-apps'], m4b_config)


# Supported services and their URL patterns
SUPPORTED_NOTIFICATION_SERVICES = {
'bark': r'^bark://[\w\-]+@.+$',
Expand Down Expand Up @@ -271,6 +285,7 @@ def validate_notification_url(url: str) -> bool:
logging.error(f"Given URL {url} does not match any supported notification service")
return False


def setup_notifications(user_config: Dict[str, Any]) -> None:
"""
Set up notifications for app updates using a supported service.
Expand Down Expand Up @@ -512,4 +527,3 @@ def main(app_config_path: str, m4b_config_path: str, user_config_path: str) -> N
except Exception as e:
logging.error(f"An unexpected error occurred: {str(e)}")
raise

0 comments on commit ed138f0

Please sign in to comment.