среда, 15 ноября 2017 г.

Automate check for a new Nvidia or Intel drivers

Sometimes you need to know when a new version of graphics driver is available and do not want to install constantly running in background tools from a manufacturer. Like Nvidia experience or Intel driver assist tool. Or you need notifications for the remote machine.

Luckily there is exists packages for Nvidia and Intel in the chocolatey project repository. And they updated pretty quickly. So using API it is possible to poll them for a new version.

https://github.com/kotofos/check-chocolatey-package-version

code example:

import xml.etree.ElementTree as ET
import zipfile
from io import BytesIO
from urllib.request import urlretrieve, urlopen

driver_url_map = {
    'nvidia': 'https://chocolatey.org/api/v2/package/nvidia-display-driver',
    'intel': 'https://chocolatey.org/api/v2/package/intel-graphics-driver',
}


def download(url):
    f = BytesIO()
    response = urlopen(url)
    f.write(response.read())
    return f


def get_current_version(name):
    url = driver_url_map[name]
    archive = download(url)
    zip = zipfile.ZipFile(archive)

    string = zip.read(url.rpartition('/')[-1] + '.nuspec').decode()
    string = "\n".join(string.split("\r\n"))
    root = ET.fromstring(string)

    tag_name = ('{http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd}' 
                'version')
    for elem in root.iter():
        if elem.tag == tag_name:
            return elem.text


if __name__ == '__main__':
    for name in ('nvidia', 'intel'):
        res = get_current_version(name)
        print('version for', name, res)

среда, 4 октября 2017 г.

Install software from chocolatey and cygwin with ansible

It is possible to use chocolatey to manage Windows computers from ansible.

choco install vlc -y works fine in Cygwin. And also over Cygwin's ssh server from ansible.

- name: Check command exist
  shell: command -v procdump

  register: procdump_res

- name: Install procdump
  command: choco install procdump -y

  when: procdump_res.rc == 1

вторник, 18 июля 2017 г.

isatty under pycharm

If you want to print something from python script only on real TTY (terminal), not in a file or redirected stream there is built in check for that: sys.stdout.isatty().
But it will return False for the pycharm console. To detect that script is executed under pycharm add or 'PYCHARM_HOSTED' in os.environ

is_direct_output = sys.stdout.isatty() or 'PYCHARM_HOSTED' in os.environ