Sophie

Sophie

distrib > Mageia > 3 > x86_64 > by-pkgid > ed855f7c18d8f7387426873c5d69401e > files > 1384

bzr-2.5.1-3.3.mga3.x86_64.rpm

#!/usr/bin/python

"""Get file version.
Written by Alexander Belchenko, 2006
"""

import os

import pywintypes   # from pywin32 (http://pywin32.sf.net)
import win32api     # from pywin32 (http://pywin32.sf.net)


__all__ = ['get_file_version', 'FileNotFound', 'VersionNotAvailable']
__docformat__ = "restructuredtext"


class FileNotFound(Exception):
    pass

class VersionNotAvailable(Exception):
    pass


def get_file_version(filename):
    """Get file version (windows properties)
    :param  filename:   path to file
    :return:            4-tuple with 4 version numbers
    """
    if not os.path.isfile(filename):
        raise FileNotFound

    try:
        version_info = win32api.GetFileVersionInfo(filename, '\\')
    except pywintypes.error:
        raise VersionNotAvailable

    return (divmod(version_info['FileVersionMS'], 65536) +
            divmod(version_info['FileVersionLS'], 65536))