import logging
@@ -76,23 +77,12 @@
def get_ua_status():
"""Return a dict of all UA status information or empty dict on error."""
# status.json will exist on any attached system or any unattached system
- # which has already run `ua status`. Calling ua status directly on
- # network disconnected machines will raise a TimeoutException trying to
- # access contracts.canonical.com/v1/resources.
- try:
- # Success writes UA_STATUS_JSON
- result = subprocess.run(['ua', 'status', '--format=json'], stdout=subprocess.PIPE)
- except Exception as e:
- print("Failed to call ubuntu advantage client:\n%s" % e)
+ # which has already run `sudo ua status`.
+ if not os.path.exists(UA_STATUS_JSON):
return {}
- if result.returncode != 0:
- print("Ubuntu advantage client returned code %d" % result.returncode)
- return {}
-
try: status_file = open(UA_STATUS_JSON, "r")
except Exception as e:
- print("No ua status file written:\n%s" % e)
return {}
Ultimately if we decide to go with #2 here's a patch that I think would limit both the time cost of a remote uRL query and the noisy logging:
--- /usr/lib/ python3/ dist-packages/ softwarepropert ies/gtk/ utils.py 2021-06-10 23:20:22.000000000 -0600 python3/ dist-packages/ softwarepropert ies/gtk/ utils.py. new 2021-07-14 15:32:54.559693094 -0600 version( "Gtk", "3.0")
+++ /usr/lib/
@@ -26,6 +26,7 @@
gi.require_
from gi.repository import Gio, Gtk
import json
+import os
import subprocess
import logging canonical. com/v1/ resources. run(['ua' , 'status', '--format=json'], stdout= subprocess. PIPE) exists( UA_STATUS_ JSON):
status_ file = open(UA_ STATUS_ JSON, "r")
@@ -76,23 +77,12 @@
def get_ua_status():
"""Return a dict of all UA status information or empty dict on error."""
# status.json will exist on any attached system or any unattached system
- # which has already run `ua status`. Calling ua status directly on
- # network disconnected machines will raise a TimeoutException trying to
- # access contracts.
- try:
- # Success writes UA_STATUS_JSON
- result = subprocess.
- except Exception as e:
- print("Failed to call ubuntu advantage client:\n%s" % e)
+ # which has already run `sudo ua status`.
+ if not os.path.
return {}
- if result.returncode != 0:
- print("Ubuntu advantage client returned code %d" % result.returncode)
- return {}
-
try:
except Exception as e:
- print("No ua status file written:\n%s" % e)
return {}
with status_file as stream: