2121
2222
2323class SetupGdriveScreen (ModalScreen ):
24- """ """
24+ """
25+ This dialog window handles the TUI equivalent of API's `setup_google_drive_connection`.
26+ If the config contains a "gdrive_client_id", the user is prompted to enter a client secret.
27+ Then, the user is asked if the their machine has access to a browser. If yes, a
28+ google drive authentication page on the user's default browser opens up. Else,
29+ the user is asked to run an rclone command on a machine with access to a browser and
30+ input the config token generated by rclone.
31+ """
2532
2633 def __init__ (self , interface : Interface ) -> None :
2734 super (SetupGdriveScreen , self ).__init__ ()
@@ -54,7 +61,28 @@ def compose(self) -> ComposeResult:
5461 )
5562
5663 def on_button_pressed (self , event : Button .Pressed ) -> None :
57- """ """
64+ """
65+ This dialog window operates using 6 buttons.
66+
67+ 1) "ok" button : Starts the connection setup process. It has an intermediate
68+ step that asks the user for client secret if "gdrive_client_id" is present
69+ in configs. And then proceeds to ask the user for browser availability.
70+ This is done via a `stage` variable. If asking the user for client secret,
71+ the stage is incremented by 0.5 on two steps. Else, `ask_user_for_browser`
72+ increments the stage directly by 1.
73+
74+ 2) "yes" button : A "yes" answer to the availability of browser question. On click,
75+ proceeds to a browser authentication.
76+
77+ 3) "no" button : A "no" answer to the availability of browser question. On click,
78+ prompts the user to enter a config token by running an rclone command.
79+
80+ 4) "enter" button : To enter the config token generated by rclone.
81+
82+ 5) "finish" button : To finish the setup.
83+
84+ 6) "cancel" button : To cancel the setup at any step before completion.
85+ """
5886 if (
5987 event .button .id == "setup_gdrive_cancel_button"
6088 or event .button .id == "setup_gdrive_finish_button"
@@ -88,6 +116,10 @@ def on_button_pressed(self, event: Button.Pressed) -> None:
88116 self .setup_gdrive_connection_using_config_token ()
89117
90118 def ask_user_for_gdrive_client_secret (self ) -> None :
119+ """
120+ Asks the user for google drive client secret. Only called if
121+ the datashuttle config has a gdrive_client_id.
122+ """
91123 message = (
92124 "Please provide the client secret for Google Drive. "
93125 "You can find it in your Google Cloud Console."
@@ -102,6 +134,9 @@ def ask_user_for_gdrive_client_secret(self) -> None:
102134 self .stage += 0.5
103135
104136 def ask_user_for_browser (self ) -> None :
137+ """
138+ Asks the user if their machine has access to a browser.
139+ """
105140 message = (
106141 "Are you running Datashuttle on a machine "
107142 "that can open a web browser?"
@@ -126,6 +161,13 @@ def ask_user_for_browser(self) -> None:
126161 self .stage += 0.5 if self .stage == 0.5 else 1
127162
128163 def open_browser_and_setup_gdrive_connection (self ) -> None :
164+ """
165+ This removes the "yes" and "no" buttons that were asked during the
166+ browser question and starts an asyncio task that sets up google drive
167+ connection and updates the UI with success/failure. The connection setup
168+ is asynchronous so that the user is able to cancel the setup if anything
169+ goes wrong without quitting datashuttle altogether.
170+ """
129171 message = "Please authenticate through browser."
130172 self .update_message_box_message (message )
131173
@@ -163,6 +205,10 @@ def prompt_user_for_config_token(self) -> None:
163205 self .mount_input_box_before_buttons ()
164206
165207 def setup_gdrive_connection_using_config_token (self ) -> None :
208+ """
209+ Disables the enter button and starts an asyncio task to setup
210+ google drive connection and update the UI with success/failure.
211+ """
166212
167213 self .input_box .disabled = True
168214
@@ -178,6 +224,11 @@ def setup_gdrive_connection_using_config_token(self) -> None:
178224 async def setup_gdrive_connection_and_update_ui (
179225 self , config_token : Optional [str ] = None
180226 ) -> None :
227+ """
228+ This starts the google drive connection setup in a separate thread (required
229+ to have asynchronous processing) and awaits for its completion. After completion,
230+ it displays a success / failure screen.
231+ """
181232 worker = self .setup_gdrive_connection (config_token )
182233 self .setup_worker = worker
183234 if worker .is_running :
@@ -197,6 +248,12 @@ async def setup_gdrive_connection_and_update_ui(
197248 def setup_gdrive_connection (
198249 self , config_token : Optional [str ] = None
199250 ) -> Worker [InterfaceOutput ]:
251+ """
252+ This function runs in a worker thread to setup google drive connection.
253+ If the user had access to a browser, the underlying rclone commands called
254+ by this function are responsible for opening google's auth page to authenticate
255+ with google drive.
256+ """
200257 success , output = self .interface .setup_google_drive_connection (
201258 self .gdrive_client_secret , config_token
202259 )
0 commit comments