<commit_before>#!/usr/bin/env python

# Pyvidia
# Gets the required driver series for the detected NVIDIA device.
# Also able to get the latest version of the required driver series.
# Parses the list of supported devices for each driver version from the NVIDIA site.

import argparse
import collections
import re
import subprocess
import sys
import urllib2
from bs4 import BeautifulSoup
from bs4 import NavigableString

legacy_device_url = "http://www.nvidia.com/object/IO_32667.html"
unix_driver_url = "http://www.nvidia.com/object/unix.html"
long_lived_url = ""
short_lived_url = ""
long_lived_version = ""
short_lived_version = ""
legacy_versions = []

series_lookup = None

device = collections.namedtuple("Device", ["name", "pci_id"])

def __is_driver_section_header(tag):
    """
    Returns true if the given tag is a driver version section header.

    Keyword Args:
    tag -- The HTML tag to inspect
    """
    for child in tag.children:
        if ".xx driver" in child:
            return True
    return False

def __get_driver_section_headers():
    """
    Returns all driver version section header tags on the legacy driver page.
    """
    legacy_device_page = urllib2.urlopen(legacy_device_url)
    soup = BeautifulSoup(legacy_device_page)
    return soup.find_all(__is_driver_section_header)

def __get_driver_series_tag_text(tag):
    """
    Returns the driver series number from the given HTML tag

    Keyword Args:
    tag -- Device driver section header tag
    """
    driver_regex = re.compile('[0-9]+\.?[0-9]*\.?[0-9]*')
    match = driver_regex.search(tag.text)
    if match:
        match_text = tag.text[match.start():match.end()]
        if match_text[-1:] == ".":
            match_text = match_text[:-1]
        return match_text
    return None

def __get_driver_series_supported_devices(tag):
    """
    Returns the list of supported devices for the given driver section

    Keyword Args:
    tag -- Device driver section header tag
    """
    device = collections.namedtuple("Device", ["name", "pci_id"])
    devices = []

    table = tag.parent.next_sibling.next_sibling
    rows = table.find_all('tr')
    for row in rows:
        cols = row.find_all('td')
        if len(cols) >= 2:
            if not "GPU product" in cols[0].text:
                device_name = cols[0].text
                pci_id = cols[1].text
                device_info = device(name=device_name, pci_id=pci_id)
                devices.append(device_info)

    return devices

def __get_current_driver_supported_devices(url):
    """
    Returns the list of supported devices for the current driver at the given URL.
<commit_msg>Remove redundant definition<commit_after>#!/usr/bin/env python

# Pyvidia
# Gets the required driver series for the detected NVIDIA device.
# Also able to get the latest version of the required driver series.
# Parses the list of supported devices for each driver version from the NVIDIA site.

import argparse
import collections
import re
import subprocess
import sys
import urllib2
from bs4 import BeautifulSoup
from bs4 import NavigableString

legacy_device_url = "http://www.nvidia.com/object/IO_32667.html"
unix_driver_url = "http://www.nvidia.com/object/unix.html"
long_lived_url = ""
short_lived_url = ""
long_lived_version = ""
short_lived_version = ""
legacy_versions = []

series_lookup = None

device = collections.namedtuple("Device", ["name", "pci_id"])

def __is_driver_section_header(tag):
    """
    Returns true if the given tag is a driver version section header.

    Keyword Args:
    tag -- The HTML tag to inspect
    """
    for child in tag.children:
        if ".xx driver" in child:
            return True
    return False

def __get_driver_section_headers():
    """
    Returns all driver version section header tags on the legacy driver page.
    """
    legacy_device_page = urllib2.urlopen(legacy_device_url)
    soup = BeautifulSoup(legacy_device_page)
    return soup.find_all(__is_driver_section_header)

def __get_driver_series_tag_text(tag):
    """
    Returns the driver series number from the given HTML tag

    Keyword Args:
    tag -- Device driver section header tag
    """
    driver_regex = re.compile('[0-9]+\.?[0-9]*\.?[0-9]*')
    match = driver_regex.search(tag.text)
    if match:
        match_text = tag.text[match.start():match.end()]
        if match_text[-1:] == ".":
            match_text = match_text[:-1]
        return match_text
    return None

def __get_driver_series_supported_devices(tag):
    """
    Returns the list of supported devices for the given driver section

    Keyword Args:
    tag -- Device driver section header tag
    """
    devices = []

    table = tag.parent.next_sibling.next_sibling
    rows = table.find_all('tr')
    for row in rows:
        cols = row.find_all('td')
        if len(cols) >= 2:
            if not "GPU product" in cols[0].text:
                device_name = cols[0].text
                pci_id = cols[1].text
                device_info = device(name=device_name, pci_id=pci_id)
                devices.append(device_info)

    return devices

def __get_current_driver_supported_devices(url):
    """
    Returns the list of supported devices for the current driver at the given URL.

{'fraction_non_alphanumeric': 0.09462037390309043, 'fraction_numerical': 0.008012209080503624, 'mean_word_length': 3.073815073815074, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2162021', 'n_tokens_mistral': 1624, 'n_tokens_neox': 1583, 'n_words': 470}