mirror of
https://github.com/keylase/nvidia-patch.git
synced 2024-12-26 06:23:34 +00:00
nv-driver-locator: timeouts
This commit is contained in:
parent
751deb08a7
commit
96deb64977
@ -251,6 +251,7 @@ Params:
|
||||
* `language` - language. Default: `1033` (English)
|
||||
* `beta` - request Beta driver. Default: `false`
|
||||
* `dch` - request DCH driver. Default: `false` (request Standard Driver)
|
||||
* `timeout` - allowed delay in seconds for each network operation. Default: `10.0`
|
||||
|
||||
#### NvidiaDownloadsChannel
|
||||
|
||||
@ -268,6 +269,7 @@ Params:
|
||||
* `driver_type` - driver type. Allowed values: `Standard`, `DCH`. At this moment DCH driver appears to exists only for some product families and only for Windows 10 x64. Default: `Standard`.
|
||||
* `lang` - driver language. Allowed values: `English`. Default: `English`.
|
||||
* `cuda_ver` - verson of CUDA Toolkit bundled with driver. Currently useless for covered product families. Default: `Nothing`.
|
||||
* `timeout` - allowed delay in seconds for each network operation. Default: `10.0`
|
||||
|
||||
### Notifiers
|
||||
|
||||
|
@ -9,7 +9,6 @@ from bs4 import BeautifulSoup
|
||||
|
||||
USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64; rv:65.0) '\
|
||||
'Gecko/20100101 Firefox/65.0'
|
||||
TIMEOUT = 10
|
||||
|
||||
|
||||
@enum.unique
|
||||
@ -95,6 +94,13 @@ class CUDAToolkitVersion(enum.Enum):
|
||||
def parse_args():
|
||||
import argparse
|
||||
|
||||
def check_positive_float(val):
|
||||
val = float(val)
|
||||
if val <= 0:
|
||||
raise ValueError("Value %s is not valid positive float" %
|
||||
(repr(val),))
|
||||
return val
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Retrieves info about latest NVIDIA drivers from "
|
||||
"downloads site",
|
||||
@ -119,14 +125,15 @@ def parse_args():
|
||||
default=DriverType.Standard,
|
||||
const=DriverType.DCH,
|
||||
action="store_const")
|
||||
parser.add_argument("-R", "--raw",
|
||||
help="Raw JSON output",
|
||||
action="store_true")
|
||||
parser.add_argument("-T", "--timeout",
|
||||
type=check_positive_float,
|
||||
default=10.,
|
||||
help="timeout for network operations")
|
||||
args = parser.parse_args()
|
||||
return args
|
||||
|
||||
|
||||
def issue_request(query_obj):
|
||||
def issue_request(query_obj, timeout=10):
|
||||
ENDPOINT = 'https://www.nvidia.com/Download/processFind.aspx'
|
||||
url = ENDPOINT + '?' + urllib.parse.urlencode(query_obj)
|
||||
http_req = urllib.request.Request(
|
||||
@ -136,7 +143,7 @@ def issue_request(query_obj):
|
||||
'User-Agent': USER_AGENT
|
||||
}
|
||||
)
|
||||
with urllib.request.urlopen(http_req, None, TIMEOUT) as resp:
|
||||
with urllib.request.urlopen(http_req, None, timeout) as resp:
|
||||
coding = resp.headers.get_content_charset()
|
||||
coding = coding if coding is not None else 'utf-8-sig'
|
||||
decoder = codecs.getreader(coding)(resp)
|
||||
@ -150,7 +157,8 @@ def get_drivers(*,
|
||||
certlevel=CertLevel.All,
|
||||
driver_type=DriverType.Standard,
|
||||
lang=DriverLanguage.English,
|
||||
cuda_ver=CUDAToolkitVersion.Nothing):
|
||||
cuda_ver=CUDAToolkitVersion.Nothing,
|
||||
timeout=10):
|
||||
psid, pfid = product.value
|
||||
query = {
|
||||
'psid': psid,
|
||||
@ -163,7 +171,7 @@ def get_drivers(*,
|
||||
}
|
||||
if os is OS.Windows10_64:
|
||||
query['dtcid'] = driver_type.value
|
||||
doc = issue_request(query)
|
||||
doc = issue_request(query, timeout)
|
||||
soup = BeautifulSoup(doc, 'html.parser')
|
||||
if soup.find(class_='contentBucketMainContent') is None:
|
||||
return []
|
||||
@ -194,7 +202,8 @@ def main():
|
||||
pprint.pprint(get_drivers(os=args.os,
|
||||
product=args.product,
|
||||
certlevel=args.certification_level,
|
||||
driver_type=args.dch))
|
||||
driver_type=args.dch,
|
||||
timeout=args.timeout))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -7,14 +7,13 @@ import posixpath
|
||||
import codecs
|
||||
|
||||
USER_AGENT = 'NvBackend/34.0.0.0'
|
||||
TIMEOUT = 10
|
||||
|
||||
|
||||
def serialize_req(obj):
|
||||
return json.dumps(obj, separators=(',', ':'))
|
||||
|
||||
|
||||
def getDispDrvrByDevid(query_obj):
|
||||
def getDispDrvrByDevid(query_obj, timeout=10):
|
||||
ENDPOINT = 'https://gfwsl.geforce.com/nvidia_web_services/' \
|
||||
'controller.gfeclientcontent.NG.php/' \
|
||||
'com.nvidia.services.GFEClientContent_NG.getDispDrvrByDevid'
|
||||
@ -26,7 +25,7 @@ def getDispDrvrByDevid(query_obj):
|
||||
'User-Agent': USER_AGENT
|
||||
}
|
||||
)
|
||||
with urllib.request.urlopen(http_req, None, TIMEOUT) as resp:
|
||||
with urllib.request.urlopen(http_req, None, timeout) as resp:
|
||||
coding = resp.headers.get_content_charset()
|
||||
coding = coding if coding is not None else 'utf-8-sig'
|
||||
decoder = codecs.getreader(coding)(resp)
|
||||
@ -41,7 +40,8 @@ def get_latest_geforce_driver(*,
|
||||
os_build="17763",
|
||||
language=1033,
|
||||
beta=False,
|
||||
dch=False):
|
||||
dch=False,
|
||||
timeout=10):
|
||||
# GeForce GTX 1080 and GP104 HD Audio
|
||||
dt_id = ["1B80_10DE_119E_10DE"]
|
||||
# GeForce GTX 1080 Mobile
|
||||
@ -62,7 +62,7 @@ def get_latest_geforce_driver(*,
|
||||
"dch": "1" if dch else "0" # 0 - Standard Driver, 1 - DCH Driver
|
||||
}
|
||||
try:
|
||||
res = getDispDrvrByDevid(query_obj)
|
||||
res = getDispDrvrByDevid(query_obj, timeout)
|
||||
except urllib.error.HTTPError as e:
|
||||
if e.code == 404:
|
||||
res = None
|
||||
@ -80,6 +80,13 @@ def parse_args():
|
||||
raise ValueError("Bad language ID")
|
||||
return lang
|
||||
|
||||
def check_positive_float(val):
|
||||
val = float(val)
|
||||
if val <= 0:
|
||||
raise ValueError("Value %s is not valid positive float" %
|
||||
(repr(val),))
|
||||
return val
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Retrieves info about latest NVIDIA drivers from GeForce "
|
||||
"Experience",
|
||||
@ -107,6 +114,10 @@ def parse_args():
|
||||
parser.add_argument("-D", "--dch",
|
||||
help="Query DCH driver instead of Standard driver",
|
||||
action="store_true")
|
||||
parser.add_argument("-T", "--timeout",
|
||||
type=check_positive_float,
|
||||
default=10.,
|
||||
help="timeout for network operations")
|
||||
parser.add_argument("-R", "--raw",
|
||||
help="Raw JSON output",
|
||||
action="store_true")
|
||||
@ -123,7 +134,8 @@ def main():
|
||||
notebook=args.notebook,
|
||||
x86_64=(not args._32bit),
|
||||
beta=args.beta,
|
||||
dch=args.dch)
|
||||
dch=args.dch,
|
||||
timeout=args.timeout)
|
||||
if drv is None:
|
||||
print("NOT FOUND")
|
||||
sys.exit(3)
|
||||
|
@ -164,7 +164,8 @@ class NvidiaDownloadsChannel(BaseChannel):
|
||||
certlevel="All",
|
||||
driver_type="Standard",
|
||||
lang="English",
|
||||
cuda_ver="Nothing"):
|
||||
cuda_ver="Nothing",
|
||||
timeout=10):
|
||||
self.name = name
|
||||
gnd = importlib.import_module('get_nvidia_downloads')
|
||||
self._gnd = gnd
|
||||
@ -174,6 +175,7 @@ class NvidiaDownloadsChannel(BaseChannel):
|
||||
self._driver_type = gnd.DriverType[driver_type]
|
||||
self._lang = gnd.DriverLanguage[lang]
|
||||
self._cuda_ver = gnd.CUDAToolkitVersion[cuda_ver]
|
||||
self._timeout = timeout
|
||||
|
||||
def get_latest_driver(self):
|
||||
drivers = self._gnd.get_drivers(os=self._os,
|
||||
@ -181,7 +183,8 @@ class NvidiaDownloadsChannel(BaseChannel):
|
||||
certlevel=self._certlevel,
|
||||
driver_type=self._driver_type,
|
||||
lang=self._lang,
|
||||
cuda_ver=self._cuda_ver)
|
||||
cuda_ver=self._cuda_ver,
|
||||
timeout=self._timeout)
|
||||
if not drivers:
|
||||
return None
|
||||
latest = max(drivers, key=lambda d: tuple(d['version'].split('.')))
|
||||
|
Loading…
Reference in New Issue
Block a user