kleinkram 0.0.116__tar.gz → 0.0.117__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of kleinkram might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: kleinkram
3
- Version: 0.0.116
3
+ Version: 0.0.117
4
4
  Summary: A CLI for the ETH project kleinkram
5
5
  Project-URL: Homepage, https://github.com/leggedrobotics/kleinkram
6
6
  Project-URL: Issues, https://github.com/leggedrobotics/kleinkram/issues
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "kleinkram"
7
- version = "0.0.116"
7
+ version = "0.0.117"
8
8
  authors = [
9
9
  { name="Johann Schwabe", email="jschwab@ethz.ch" },
10
10
  ]
@@ -72,6 +72,7 @@ class OAuthCallbackHandler(BaseHTTPRequestHandler):
72
72
  self.end_headers()
73
73
  self.wfile.write(b"Authentication successful. You can close this window.")
74
74
  return
75
+ print("here")
75
76
 
76
77
  def log_message(self, format, *args):
77
78
  pass
@@ -90,8 +91,8 @@ class AuthenticatedClient(httpx.Client):
90
91
  try:
91
92
  self.tokenfile = TokenFile()
92
93
  self._load_cookies()
93
- except:
94
- print("Not authenticated. Please run 'GTD login'.")
94
+ except Exception as e:
95
+ print(f"{self.tokenfile.endpoint} is not authenticated. Please run 'klein login'.")
95
96
 
96
97
  def _load_cookies(self):
97
98
  if self.tokenfile.isCliToken():
@@ -107,7 +108,7 @@ class AuthenticatedClient(httpx.Client):
107
108
  if not refresh_token:
108
109
  print("No refresh token found. Please login again.")
109
110
  raise Exception("No refresh token found.")
110
- self.cookies.set(REFRESH_TOKEN, refresh_token,)
111
+ self.cookies.set(REFRESH_TOKEN, refresh_token, )
111
112
  response = self.post(
112
113
  "/auth/refresh-token",
113
114
  )
@@ -122,7 +123,7 @@ class AuthenticatedClient(httpx.Client):
122
123
  method, self.tokenfile.endpoint + url, *args, **kwargs
123
124
  )
124
125
  if (
125
- url == "/auth/refresh-token"
126
+ url == "/auth/refresh-token"
126
127
  ) and response.status_code == 401:
127
128
  print("Refresh token expired. Please login again.")
128
129
  response.status_code = 403
@@ -137,30 +138,65 @@ class AuthenticatedClient(httpx.Client):
137
138
  client = AuthenticatedClient()
138
139
 
139
140
 
140
- def login(key: Annotated[str, typer.Option()] = None):
141
+ def login(
142
+ key: Annotated[str, typer.Option()] = None,
143
+ open_browser: Annotated[bool, typer.Option()] = True,
144
+ ):
141
145
  tokenfile = TokenFile()
142
146
  if key:
143
147
  tokenfile.saveTokens(key)
144
148
  else:
145
- print("Opening browser for authentication...")
146
- webbrowser.open(tokenfile.endpoint + "/auth/google?state=cli")
149
+ url = tokenfile.endpoint + "/auth/google?state=cli"
147
150
 
148
- print("Waiting for authentication to complete...")
149
- auth_tokens = get_auth_tokens()
151
+ has_browser = True
152
+ try:
153
+ browser_available = webbrowser.get()
154
+ if not browser_available:
155
+ raise Exception("No web browser available.")
156
+ except Exception as e:
157
+ has_browser = False
150
158
 
151
- if not auth_tokens:
152
- print("Failed to get authentication tokens.")
153
- return
159
+ if has_browser and open_browser:
160
+ webbrowser.open(url)
161
+ auth_tokens = get_auth_tokens()
162
+
163
+ if not auth_tokens:
164
+ print("Failed to get authentication tokens.")
165
+ return
154
166
 
155
- tokenfile.saveTokens(auth_tokens)
167
+ tokenfile.saveTokens(auth_tokens)
168
+ print("Authentication complete. Tokens saved to ~/.kleinkram.json.")
169
+
170
+ return
156
171
 
157
- print("Authentication complete. Tokens saved to tokens.json.")
172
+ print(f"Please open the following URL manually in your browser to authenticate: {url + '-no-redirect'}")
173
+ print("Enter the authentication token provided after logging in:")
174
+ manual_auth_token = input("Authentication Token: ")
175
+ manual_refresh_token = input("Refresh Token: ")
176
+ if manual_auth_token:
177
+ tokenfile.saveTokens({AUTH_TOKEN: manual_auth_token, REFRESH_TOKEN: manual_refresh_token})
178
+ print("Authentication complete. Tokens saved to tokens.json.")
179
+ else:
180
+ print("No authentication token provided.")
181
+ return
158
182
 
159
183
 
160
- def endpoint(endpoint: Annotated[str, typer.Argument()]):
184
+ def setEndpoint(endpoint: Annotated[str, typer.Argument()]):
161
185
  tokenfile = TokenFile()
162
186
  tokenfile.endpoint = endpoint
163
187
  tokenfile.writeToFile()
188
+ print("Endpoint set to: " + endpoint)
189
+ if tokenfile.endpoint not in tokenfile.tokens:
190
+ print("No tokens found for this endpoint.")
191
+
192
+
193
+ def endpoint():
194
+ tokenfile = TokenFile()
195
+ print("Current: " + tokenfile.endpoint)
196
+ print("Saved Tokens found for:")
197
+ for _endpoint, _ in tokenfile.tokens.items():
198
+ print(_endpoint)
199
+
164
200
 
165
201
  def setCliKey(key: Annotated[str, typer.Argument()]):
166
202
  tokenfile = TokenFile()
@@ -0,0 +1 @@
1
+ API_URL='https://api.datasets.leggedrobotics.com'
@@ -1,3 +1,4 @@
1
+ import sys
1
2
  from datetime import datetime, timedelta
2
3
  import os
3
4
 
@@ -10,7 +11,7 @@ from rich.table import Table
10
11
 
11
12
  from .helper import uploadFiles, expand_and_match
12
13
 
13
- from .auth import login, client, endpoint, setCliKey
14
+ from .auth import login, client, endpoint, setCliKey, setEndpoint
14
15
 
15
16
  app = typer.Typer()
16
17
  projects = typer.Typer(name="projects")
@@ -33,6 +34,7 @@ app.add_typer(tagtypes)
33
34
  app.add_typer(tag)
34
35
  app.command()(login)
35
36
  app.command()(endpoint)
37
+ app.command()(setEndpoint)
36
38
  app.command()(setCliKey)
37
39
 
38
40
 
@@ -426,8 +428,9 @@ def addTag(
426
428
  print("Failed to tag mission")
427
429
  except httpx.HTTPError as e:
428
430
  print(e)
429
- print("Failed to tag mission"
430
- )
431
+ print("Failed to tag mission")
432
+ sys.exit(1)
433
+
431
434
 
432
435
  @tagtypes.command('list')
433
436
  def tagTypes(
@@ -1,2 +0,0 @@
1
- API_URL = "http://localhost:3000"
2
- # API_URL = "https://api.datasets.leggedrobotics.com"
File without changes
File without changes
File without changes
File without changes
File without changes