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