Skip to content

Commit

Permalink
Fix python 3.6 compatibility issue
Browse files Browse the repository at this point in the history
3.6's subprocess.run lacks capture_output arg and throws an exception.
  • Loading branch information
val-ms committed Apr 20, 2021
1 parent b760c33 commit 419f95d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions cvdupdate/cvdupdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,14 +789,16 @@ def check(name):
'''
self.logger.debug(f'Checking for a newer version of cvdupdate.')

latest_version = str(subprocess.run([sys.executable, '-m', 'pip', 'install', '{}==random'.format('cvdupdate')], capture_output=True, text=True))
result = subprocess.run([sys.executable, '-m', 'pip', 'install', '{}==random'.format('cvdupdate')], stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
latest_version = result.stderr.decode("utf-8")
latest_version = latest_version[latest_version.find('(from versions:')+15:]
latest_version = latest_version[:latest_version.find(')')]
latest_version = latest_version.replace(' ','').split(',')[-1]
latest_version = latest_version.replace(' ','').split(',')[-1].strip()

current_version = str(subprocess.run([sys.executable, '-m', 'pip', 'show', '{}'.format('cvdupdate')], capture_output=True, text=True))
result = subprocess.run([sys.executable, '-m', 'pip', 'show', '{}'.format('cvdupdate')], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
current_version = result.stdout.decode("utf-8")
current_version = current_version[current_version.find('Version:')+8:]
current_version = current_version[:current_version.find('\\n')].replace(' ','')
current_version = current_version[:current_version.find('\n')].replace(' ','').strip()

if 'ERROR' in latest_version:
self.logger.debug(f"Version check didn't work, didn't get back a list of package versions.")
Expand Down

0 comments on commit 419f95d

Please # to comment.