mckabue commited on
Commit
b68b7b6
·
1 Parent(s): bdcc0da

Refactor terminal WHOIS availability check for improved error handling and logging

Browse files
Files changed (1) hide show
  1. app.py +17 -15
app.py CHANGED
@@ -155,22 +155,24 @@ def terminal_whois_is_available(domain, is_available_callback: Callable[[str], b
155
  try:
156
  # Check if OS is Linux
157
  if platform.system().lower() == 'linux':
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  logs_append(f"{terminal_whois_is_available.__name__}:Exception:System WHOIS check only available on Linux")
159
- if which('whois') is not None:
160
- logs_append(f"{terminal_whois_is_available.__name__}:Exception:WHOIS not installed. Install with: sudo apt-get install whois")
161
- # Run whois command with timeout
162
- process = subprocess.Popen(
163
- ['whois', domain],
164
- stdout=subprocess.PIPE,
165
- stderr=subprocess.PIPE)
166
- try:
167
- stdout, stderr = process.communicate(timeout=60)
168
- output = stdout.decode('utf-8', errors='ignore').lower()
169
- logs_append(f"{terminal_whois_is_available.__name__}:stderr:{str(stderr.decode(encoding='utf-8'))}")
170
- return is_available_callback(output), "system whois"
171
- except subprocess.TimeoutExpired as timeout_e:
172
- logs_append(f"{terminal_whois_is_available.__name__}:TimeoutExpired:{str(timeout_e)}")
173
- process.kill()
174
  except Exception as e:
175
  logs_append(f"{terminal_whois_is_available.__name__}:Exception:{str(e)}")
176
  return False, None
 
155
  try:
156
  # Check if OS is Linux
157
  if platform.system().lower() == 'linux':
158
+ if which('whois') is not None:
159
+ # Run whois command with timeout
160
+ process = subprocess.Popen(
161
+ ['whois', domain],
162
+ stdout=subprocess.PIPE,
163
+ stderr=subprocess.PIPE)
164
+ try:
165
+ stdout, stderr = process.communicate(timeout=60)
166
+ output = stdout.decode('utf-8', errors='ignore').lower()
167
+ logs_append(f"{terminal_whois_is_available.__name__}:stderr:{str(stderr.decode(encoding='utf-8'))}")
168
+ return is_available_callback(output), "system whois"
169
+ except subprocess.TimeoutExpired as timeout_e:
170
+ logs_append(f"{terminal_whois_is_available.__name__}:TimeoutExpired:{str(timeout_e)}")
171
+ process.kill()
172
+ else:
173
+ logs_append(f"{terminal_whois_is_available.__name__}:Exception:WHOIS not installed. Install with: sudo apt-get install whois")
174
+ else:
175
  logs_append(f"{terminal_whois_is_available.__name__}:Exception:System WHOIS check only available on Linux")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
  except Exception as e:
177
  logs_append(f"{terminal_whois_is_available.__name__}:Exception:{str(e)}")
178
  return False, None