MCPcopy Index your code
hub / github.com/pgadmin-org/pgadmin4 / set_prefs

Method set_prefs

web/setup.py:683–787  ·  view source on GitHub ↗

Set User preferences.

(username,
                  pref_options: Annotated[Optional[List[str]],
                                          typer.Argument()] = None,
                  auth_source: AuthType = AuthType.internal,
                  console: Optional[bool] = True,
                  json: Optional[bool] = False,
                  input_file: Optional[str] = None,
                  sqlite_path: Optional[str] = None,
                  )

Source from the content-addressed store, hash-verified

681 @app.command()
682 @update_sqlite_path
683 def set_prefs(username,
684 pref_options: Annotated[Optional[List[str]],
685 typer.Argument()] = None,
686 auth_source: AuthType = AuthType.internal,
687 console: Optional[bool] = True,
688 json: Optional[bool] = False,
689 input_file: Optional[str] = None,
690 sqlite_path: Optional[str] = None,
691 ):
692 """Set User preferences."""
693 if not pref_options:
694 pref_options = []
695
696 if input_file:
697 from urllib.parse import unquote
698 # generate full path of file
699 try:
700 file_path = unquote(input_file)
701 except Exception as e:
702 print(str(e))
703 return _handle_error(str(e), True)
704 import json as json_utility
705 try:
706 with open(file_path) as f:
707 data = json_utility.load(f)
708 except json_utility.decoder.JSONDecodeError as e:
709 return _handle_error(gettext("Error parsing input file %s: %s"
710 % (file_path, e)), True)
711 except Exception as e:
712 return _handle_error(
713 gettext("Error reading input file %s: [%d] %s" %
714 (file_path, e.errno, e.strerror)), True)
715
716 pref_data = data['preferences']
717
718 for k, v in pref_data.items():
719 pref_options.append(k + "=" + str(v))
720
721 user_id = ManagePreferences.get_user(username, auth_source)
722 table = Table(title="Updated Pref Details", box=box.ASCII)
723 table.add_column("Preference", style="green")
724 if not user_id:
725 print(USER_NOT_FOUND_STR)
726 return
727
728 prefs = ManagePreferences.fetch_prefs(True)
729 app = create_app(config.APP_NAME + '-cli')
730 invalid_prefs = []
731 invalid_value_prefs = []
732 valid_prefs = []
733 # Module preference objects are registered lazily via
734 # register_before_app_start() callbacks; pgAdmin4.py runs them at
735 # web-app startup, but the CLI never does. save_cli() now validates
736 # against the registered preference type, so we have to trigger
737 # registration ourselves. PGADMIN_RUNTIME must be set first because
738 # some register_preferences() methods (e.g. browser) check it; we
739 # use False so the full server-mode preference set (including
740 # keyboard shortcuts) is exposed to the CLI. run_before_app_start()

Callers

nothing calls this directly

Calls 11

_handle_errorFunction · 0.90
create_appFunction · 0.90
save_prefFunction · 0.90
gettextFunction · 0.85
appendMethod · 0.80
fetch_prefsMethod · 0.80
run_before_app_startMethod · 0.80
joinMethod · 0.80
TableFunction · 0.50
loadMethod · 0.45
get_userMethod · 0.45

Tested by

no test coverage detected