Exemple #1
0
class MachineRegisteredEnvironment(RegisteredEnvironment):
    path = r'SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
    hklm = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
    try:
        key = winreg.OpenKey(hklm, path, 0, winreg.KEY_READ | winreg.KEY_WRITE)
    except WindowsError:
        key = winreg.OpenKey(hklm, path, 0, winreg.KEY_READ)
Exemple #2
0
def _visual_compiler(output, version):
    'version have to be 8.0, or 9.0 or... anything .0'
    from six.moves import winreg

    try:
        hKey = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
                              r"SOFTWARE\Microsoft\Windows\CurrentVersion")
        winreg.QueryValueEx(hKey, "ProgramFilesDir (x86)")
        is_64bits = True
    except EnvironmentError:
        is_64bits = False
    finally:
        winreg.CloseKey(hKey)

    if is_64bits:
        key_name = r'SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VC7'
    else:
        key_name = r'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\SxS\VC7'

    try:
        key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, key_name)
        winreg.QueryValueEx(key, version)
        installed_version = Version(version).major(fill=False)
        compiler = "Visual Studio"
        output.success("Found %s %s" % (compiler, installed_version))
        return compiler, installed_version
    except EnvironmentError:
        return None
Exemple #3
0
def get_latest_nastran_directory():
    def enum_keys(handle):
        for i in range(2**10):
            try:
                yield winreg.EnumKey(handle, i)
            except WindowsError as e:
                if e.winerror != 259:
                    raise
                return

    with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
                        "SOFTWARE\\MSC.Software Corporation", winreg.KEY_READ
                        | winreg.KEY_WOW64_32KEY) as software_msc:
        nastrans = sorted([
            name for name in enum_keys(software_msc) if "MSC Nastran" in name
            and "MSC Nastran Documentation" not in name
        ])
        if not nastrans:
            exitwitherror(
                "Nastran.py: Can't read NASTRAN path from registry. Do you have it installed?",
                -1)
        latest_nastran = nastrans[-1]
        with winreg.OpenKey(software_msc,
                            latest_nastran + "\\Latest") as latest_key:
            version = six.text_type(winreg.QueryValueEx(latest_key, None)[0])
        with winreg.OpenKey(software_msc,
                            "{}\\{}".format(latest_nastran,
                                            version)) as nastran_key:
            return six.text_type(winreg.QueryValueEx(nastran_key, "Path")[0])
Exemple #4
0
    def _get_vix_path():
        """Finds the expected install path for the so/dll.

        :returns: Expected path.
        :rtype: str

        :raises NotImplemented: If the OS/architecture are not recognized.
        """

        os_name = platform.system()

        if os_name == 'Linux':
            return '/usr/lib/libvixAllProducts.so'

        elif os_name == 'Darwin':
            return '/Applications/VMware Fusion.app/Contents/Public/libvixAllProducts.dylib'

        elif os_name == 'Windows':
            arch = platform.architecture()[0].lower()
            machine = platform.machine().lower()

            # Py: 32; Machine: 32: %ProgramFiles%\VMware\VMware VIX\VixAllProductsDyn.dll
            # Py: 32; Machine: 64: %ProgramFiles(x86)%\VMware\VMware VIX\VixAllProductsDyn.dll
            # Py: 64; Machine: 32: N/A
            # Py: 64; Machine: 64: %ProgramFiles(x86)%\VMware\VMware VIX\Vix64AllProductsDyn.dll

            from six.moves import winreg

            try:
                if machine == 'amd64':
                    base_path = winreg.QueryValueEx(
                        winreg.OpenKey(
                            winreg.HKEY_LOCAL_MACHINE,
                            r'SOFTWARE\WOW6432Node\VMware, Inc.\VMware VIX'),
                        'InstallPath')[0]
                else:
                    base_path = winreg.QueryValueEx(
                        winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
                                       r'SOFTWARE\VMware, Inc.\VMware VIX'),
                        'InstallPath')[0]
            except OSError:
                base_path = os.getenv(
                    'ProgramFiles(x86)') if machine == 'amd64' else os.getenv(
                        'ProgramFiles')
                base_path = os.path.join(base_path, 'VMware', 'VMware VIX')

            base_path = os.path.join(
                base_path, 'Vix64AllProductsDyn.dll'
                if arch == '64bit' else 'VixAllProductsDyn.dll')

            return base_path

        raise NotImplementedError(
            'Unrecognized OS or architecture ({0}, {1}, {2})'.format(
                platform.architecture(), platform.machine(),
                platform.system()))
Exemple #5
0
    def __init__(self):
        with winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) as handle:
            with winreg.OpenKey(handle, TZLOCALKEYNAME) as tzlocalkey:
                keydict = valuestodict(tzlocalkey)

            self._std_abbr = keydict["StandardName"]
            self._dst_abbr = keydict["DaylightName"]

            try:
                tzkeyname = text_type("{kn}\\{sn}").format(kn=TZKEYNAME,
                                                           sn=self._std_abbr)
                with winreg.OpenKey(handle, tzkeyname) as tzkey:
                    _keydict = valuestodict(tzkey)
                    self._display = _keydict["Display"]
            except OSError:
                self._display = None

        stdoffset = -keydict["Bias"] - keydict["StandardBias"]
        dstoffset = stdoffset - keydict["DaylightBias"]

        self._std_offset = datetime.timedelta(minutes=stdoffset)
        self._dst_offset = datetime.timedelta(minutes=dstoffset)

        # For reasons unclear, in this particular key, the day of week has been
        # moved to the END of the SYSTEMTIME structure.
        tup = struct.unpack("=8h", keydict["StandardStart"])

        (
            self._stdmonth,
            self._stdweeknumber,  # Last = 5
            self._stdhour,
            self._stdminute,
        ) = tup[1:5]

        self._stddayofweek = tup[7]

        tup = struct.unpack("=8h", keydict["DaylightStart"])

        (
            self._dstmonth,
            self._dstweeknumber,  # Last = 5
            self._dsthour,
            self._dstminute,
        ) = tup[1:5]

        self._dstdayofweek = tup[7]

        self._dst_base_offset_ = self._dst_offset - self._std_offset
        self.hasdst = self._get_hasdst()
Exemple #6
0
    def __init__( self, vmx, user='', password='', vmrun='', debug=False ):

        self.VM_FILE    =   vmx         # TODO strict censor?
        self.VM_ADMIN   =   user
        self.VM_PASS    =   password
        self.DEBUG      =   debug

        if vmrun != '':
            self.VMRUN_PATH = vmrun
        else:
            if os.sys.platform == 'darwin':
                self.provider = 'fusion'
                self.VMRUN_PATH = '/Applications/VMware\ Fusion.app/Contents/Library/vmrun'
            elif os.sys.platform == "win32":
                # get vmrun.exe's full path via registry
                from six.moves import winreg as _winreg
                reg = _winreg.ConnectRegistry( None, _winreg.HKEY_LOCAL_MACHINE )
                try:
                    # Known registry key location in Windows 10
                    rh = _winreg.OpenKey( reg, r'SOFTWARE\WOW6432Node\VMware, Inc.\VMware Workstation' )
                    try:
                        vw_dir = _winreg.QueryValueEx( rh, 'InstallPath' )[0]
                    finally:
                        _winreg.CloseKey( rh )
                except WindowsError:
                    # Previously used registry key location
                    rh = _winreg.OpenKey( reg, r'SOFTWARE\VMware, Inc.\VMware Workstation' )
                    try:
                        vw_dir = _winreg.QueryValueEx( rh, 'InstallPath' )[0]
                    finally:
                        _winreg.CloseKey( rh )
                finally:
                    reg.Close()

                self.provider = 'ws'
                if vw_dir != '':
                    self.VMRUN_PATH = vw_dir + 'vmrun.exe'
            else:
                self.provider = 'ws'
                if os.environ.has_key("PATH"):
                    for path in os.environ["PATH"].split(os.pathsep):
                        tmp_file = path + os.sep + "vmrun"
                        if os.path.exists(tmp_file):
                            self.VMRUN_PATH = tmp_file
                            break
        
        vmrun_path = getattr(self, 'VMRUN_PATH', None)
        if vmrun_path is None:
            raise RuntimeError('Could not locate vmrun executable!')
Exemple #7
0
def find_windows_10_sdk():
    """finds valid Windows 10 SDK version which can be passed to vcvarsall.bat (vcvars_command)"""
    # uses the same method as VCVarsQueryRegistry.bat
    from six.moves import winreg  # @UnresolvedImport
    hives = [
        (winreg.HKEY_LOCAL_MACHINE, r'SOFTWARE\Wow6432Node'),
        (winreg.HKEY_CURRENT_USER, r'SOFTWARE\Wow6432Node'),
        (winreg.HKEY_LOCAL_MACHINE, r'SOFTWARE'),
        (winreg.HKEY_CURRENT_USER, r'SOFTWARE')
    ]
    for key, subkey in hives:
        try:
            hkey = winreg.OpenKey(key, r'%s\Microsoft\Microsoft SDKs\Windows\v10.0' % subkey)
            installation_folder, _ = winreg.QueryValueEx(hkey, 'InstallationFolder')
            if os.path.isdir(installation_folder):
                include_dir = os.path.join(installation_folder, 'include')
                for sdk_version in os.listdir(include_dir):
                    if os.path.isdir(os.path.join(include_dir, sdk_version)) and sdk_version.startswith('10.'):
                        windows_h = os.path.join(include_dir, sdk_version, 'um', 'Windows.h')
                        if os.path.isfile(windows_h):
                            return sdk_version
        except EnvironmentError:
            pass
        finally:
            winreg.CloseKey(hkey)
    return None
Exemple #8
0
    def _check_reg(self, sub_key):
        # see comments in check_httpd(), above, for why this routine exists and what it's doing.
        try:
            # Note that we HKCR is a union of HKLM and HKCR (with the latter
            # overriding the former), so reading from HKCR ensures that we get
            # the value if it is set in either place. See als comments below.
            hkey = _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, sub_key)
            args = _winreg.QueryValue(hkey, '').split()
            _winreg.CloseKey(hkey)

            # In order to keep multiple checkouts from stepping on each other, we simply check that an
            # existing entry points to a valid path and has the right command line.
            if (len(args) == 2 and self._filesystem.exists(args[0])
                    and args[0].endswith('perl.exe') and args[1] == '-wT'):
                return True
        except WindowsError as error:  # WindowsError is not defined on non-Windows platforms - pylint: disable=undefined-variable
            if error.errno != errno.ENOENT:
                raise
            # The key simply probably doesn't exist.

        # Note that we write to HKCU so that we don't need privileged access
        # to the registry, and that will get reflected in HKCR when it is read, above.
        cmdline = self._path_from_chromium_base('third_party', 'perl', 'perl',
                                                'bin', 'perl.exe') + ' -wT'
        hkey = _winreg.CreateKeyEx(_winreg.HKEY_CURRENT_USER,
                                   'Software\\Classes\\' + sub_key, 0,
                                   _winreg.KEY_WRITE)
        _winreg.SetValue(hkey, '', _winreg.REG_SZ, cmdline)
        _winreg.CloseKey(hkey)
        return True
Exemple #9
0
    def __init__(self, name):
        self._name = name

        handle = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
        tzkey = winreg.OpenKey(handle, "%s\%s" % (TZKEYNAME, name))
        keydict = valuestodict(tzkey)
        tzkey.Close()
        handle.Close()

        self._stdname = keydict["Std"].encode("iso-8859-1")
        self._dstname = keydict["Dlt"].encode("iso-8859-1")

        self._display = keydict["Display"]

        # See http://ww_winreg.jsiinc.com/SUBA/tip0300/rh0398.htm
        tup = struct.unpack("=3l16h", keydict["TZI"])
        self._stdoffset = -tup[0] - tup[1]  # Bias + StandardBias * -1
        self._dstoffset = self._stdoffset - tup[2]  # + DaylightBias * -1

        (
            self._stdmonth,
            self._stddayofweek,  # Sunday = 0
            self._stdweeknumber,  # Last = 5
            self._stdhour,
            self._stdminute) = tup[4:9]

        (
            self._dstmonth,
            self._dstdayofweek,  # Sunday = 0
            self._dstweeknumber,  # Last = 5
            self._dsthour,
            self._dstminute) = tup[12:17]
Exemple #10
0
 def find_available_vc_vers(self):
     """
     Find all available Microsoft Visual C++ versions.
     """
     vckeys = (self.ri.vc, self.ri.vc_for_python)
     vc_vers = []
     for hkey in self.ri.HKEYS:
         for key in vckeys:
             try:
                 bkey = winreg.OpenKey(hkey, key, 0, winreg.KEY_READ)
             except (OSError, IOError):
                 continue
             subkeys, values, _ = winreg.QueryInfoKey(bkey)
             for i in range(values):
                 try:
                     ver = float(winreg.EnumValue(bkey, i)[0])
                     if ver not in vc_vers:
                         vc_vers.append(ver)
                 except ValueError:
                     pass
             for i in range(subkeys):
                 try:
                     ver = float(winreg.EnumKey(bkey, i))
                     if ver not in vc_vers:
                         vc_vers.append(ver)
                 except ValueError:
                     pass
     return sorted(vc_vers)
Exemple #11
0
 def list():
     """Return a list of all time zones known to the system."""
     with winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) as handle:
         with winreg.OpenKey(handle, TZKEYNAME) as tzkey:
             result = [winreg.EnumKey(tzkey, i)
                       for i in range(winreg.QueryInfoKey(tzkey)[0])]
     return result
Exemple #12
0
    def __init__(self, name):
        self._name = name

        # multiple contexts only possible in 2.7 and 3.1, we still support 2.6
        with winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) as handle:
            with winreg.OpenKey(handle, "%s\%s" % (TZKEYNAME, name)) as tzkey:
                keydict = valuestodict(tzkey)

        self._stdname = keydict["Std"]
        self._dstname = keydict["Dlt"]

        self._display = keydict["Display"]

        # See http://ww_winreg.jsiinc.com/SUBA/tip0300/rh0398.htm
        tup = struct.unpack("=3l16h", keydict["TZI"])
        self._stdoffset = -tup[0] - tup[1]  # Bias + StandardBias * -1
        self._dstoffset = self._stdoffset - tup[2]  # + DaylightBias * -1

        # for the meaning see the win32 TIME_ZONE_INFORMATION structure docs
        # http://msdn.microsoft.com/en-us/library/windows/desktop/ms725481(v=vs.85).aspx
        (
            self._stdmonth,
            self._stddayofweek,  # Sunday = 0
            self._stdweeknumber,  # Last = 5
            self._stdhour,
            self._stdminute) = tup[4:9]

        (
            self._dstmonth,
            self._dstdayofweek,  # Sunday = 0
            self._dstweeknumber,  # Last = 5
            self._dsthour,
            self._dstminute) = tup[12:17]
Exemple #13
0
def win32FontDirectory():
    """
    Return the user-specified font directory for Win32.  This is
    looked up from the registry key::

      \\\\HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\Fonts

    If the key is not found, $WINDIR/Fonts will be returned.
    """
    try:
        from six.moves import winreg
    except ImportError:
        pass  # Fall through to default
    else:
        try:
            user = winreg.OpenKey(winreg.HKEY_CURRENT_USER, MSFolders)
            try:
                try:
                    return winreg.QueryValueEx(user, 'Fonts')[0]
                except OSError:
                    pass  # Fall through to default
            finally:
                winreg.CloseKey(user)
        except OSError:
            pass  # Fall through to default
    return os.path.join(os.environ['WINDIR'], 'Fonts')
    def check_fips_mode_os():
        """ Function to check for the OS fips mode

        :param key: string to encrypt with
        :type key: str.

        :returns: returns True if FIPS mode is active, False otherwise
        """
        fips = False
        if os.name == 'nt':
            reg = winreg.ConnectRegistry(None, HKEY_LOCAL_MACHINE)
            try:
                reg = winreg.OpenKey(reg, 'System\\CurrentControlSet\\Control\\'\
                                            'Lsa\\FipsAlgorithmPolicy')
                winreg.QueryInfoKey(reg)
                value, _ = winreg.QueryValueEx(reg, 'Enabled')
                if value:
                    fips = True
            except:
                fips = False
        else:
            try:
                fipsfile = open("/proc/sys/crypto/fips_enabled")
                result = fipsfile.readline()
                if int(result) > 0:
                    fipsfile = True
                fipsfile.close()
            except:
                fips = False
        return fips
Exemple #15
0
 def SetEnv(name, value):
     key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, 'Environment', 0,
                          winreg.KEY_ALL_ACCESS)
     winreg.SetValueEx(key, name, 0, winreg.REG_EXPAND_SZ, value)
     winreg.CloseKey(key)
     win32gui.SendMessage(win32con.HWND_BROADCAST,
                          win32con.WM_SETTINGCHANGE, 0, 'Environment')
     return value
Exemple #16
0
 def get_browser_path():
     '''获取chorme.exe的路径
     '''
     from six.moves import winreg
     sub_key = r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Google Chrome"
     try:
         hkey = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, sub_key)
         install_dir, _ = winreg.QueryValueEx(hkey, "InstallLocation")
         winreg.CloseKey(hkey)
     except WindowsError:
         try:
             hkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, sub_key)
             install_dir, _ = winreg.QueryValueEx(hkey, "InstallLocation")
         except WindowsError:
             sub_key = r"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe"
             hkey = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, sub_key)
             install_dir, _ = winreg.QueryValueEx(hkey, "Path")
     return install_dir + "\\chrome.exe"
Exemple #17
0
 def get_user_home(self, username):
     user_sid = self.get_user_sid(username)
     if user_sid:
         with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, 'SOFTWARE\\'
                             'Microsoft\\Windows NT\\CurrentVersion\\'
                             'ProfileList\\%s' % user_sid) as key:
             return winreg.QueryValueEx(key, 'ProfileImagePath')[0]
     LOG.debug('Home directory not found for user %r', username)
     return None
Exemple #18
0
 def list():
     """Return a list of all time zones known to the system."""
     handle = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
     tzkey = winreg.OpenKey(handle, TZKEYNAME)
     result = [winreg.EnumKey(tzkey, i)
               for i in range(winreg.QueryInfoKey(tzkey)[0])]
     tzkey.Close()
     handle.Close()
     return result
Exemple #19
0
    def get_config_value(self, name, section=None):
        key_name = self._get_config_key_name(section)

        try:
            with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, key_name) as key:
                (value, regtype) = winreg.QueryValueEx(key, name)
                return value
        except WindowsError:
            return None
Exemple #20
0
def _settzkeyname():
    handle = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
    try:
        winreg.OpenKey(handle, TZKEYNAMENT).Close()
        TZKEYNAME = TZKEYNAMENT
    except WindowsError:
        TZKEYNAME = TZKEYNAME9X
    handle.Close()
    return TZKEYNAME
Exemple #21
0
    def __init__(self):

        handle = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)

        tzlocalkey = winreg.OpenKey(handle, TZLOCALKEYNAME)
        keydict = valuestodict(tzlocalkey)
        tzlocalkey.Close()

        self._stdname = keydict["StandardName"].encode("iso-8859-1")
        self._dstname = keydict["DaylightName"].encode("iso-8859-1")

        try:
            tzkey = winreg.OpenKey(handle,
                                   "%s\%s" % (TZKEYNAME, self._stdname))
            _keydict = valuestodict(tzkey)
            self._display = _keydict["Display"]
            tzkey.Close()
        except OSError:
            self._display = None

        handle.Close()

        self._stdoffset = -keydict["Bias"] - keydict["StandardBias"]
        self._dstoffset = self._stdoffset - keydict["DaylightBias"]

        # See http://ww_winreg.jsiinc.com/SUBA/tip0300/rh0398.htm
        tup = struct.unpack("=8h", keydict["StandardStart"])

        (
            self._stdmonth,
            self._stddayofweek,  # Sunday = 0
            self._stdweeknumber,  # Last = 5
            self._stdhour,
            self._stdminute) = tup[1:6]

        tup = struct.unpack("=8h", keydict["DaylightStart"])

        (
            self._dstmonth,
            self._dstdayofweek,  # Sunday = 0
            self._dstweeknumber,  # Last = 5
            self._dsthour,
            self._dstminute) = tup[1:6]
Exemple #22
0
def get_acroversion():
    " Return version of Adobe Acrobat executable or None"
    from six.moves import winreg
    adobesoft = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r'Software\Adobe')
    for index in range(winreg.QueryInfoKey(adobesoft)[0]):
        key = winreg.EnumKey(adobesoft, index)
        if "acrobat" in key.lower():
            acrokey = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
                                     'Software\\Adobe\\%s' % key)
            for index in range(winreg.QueryInfoKey(acrokey)[0]):
                numver = winreg.EnumKey(acrokey, index)
                try:
                    res = winreg.QueryValue(
                        winreg.HKEY_LOCAL_MACHINE,
                        'Software\\Adobe\\%s\\%s\\InstallPath' % (key, numver))
                    return res
                except Exception:
                    pass
    return None
Exemple #23
0
def set_rdp_keepalive(enable, interval=1):
    with winreg.OpenKey(
            winreg.HKEY_LOCAL_MACHINE, 'SOFTWARE\\Policies\\Microsoft\\'
            'Windows NT\\Terminal Services', 0, winreg.KEY_ALL_ACCESS) as key:
        LOG.debug("Setting RDP KeepAliveEnabled: %s", enable)
        winreg.SetValueEx(key, 'KeepAliveEnable', 0, winreg.REG_DWORD,
                          1 if enable else 0)
        LOG.debug("Setting RDP keepAliveInterval (minutes): %s", interval)
        winreg.SetValueEx(key, 'keepAliveInterval', 0, winreg.REG_DWORD,
                          interval)
Exemple #24
0
 def GetEnv(name):
     root = winreg.HKEY_CURRENT_USER
     subkey = 'Environment'
     key = winreg.OpenKey(root, subkey, 0, winreg.KEY_READ)
     try:
         value, _ = winreg.QueryValueEx(key, name)
     # pylint:disable=undefined-variable, This variable is defined in windows.
     except WindowsError:
         return ''
     return value
Exemple #25
0
 def get_san_policy(self):
     with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
                         'SYSTEM\\CurrentControlSet\\Services\\partmgr\\'
                         'Parameters') as key:
         try:
             san_policy = winreg.QueryValueEx(key, 'SanPolicy')[0]
         except WindowsError as ex:
             if ex.winerror != 2:
                 raise
             san_policy = base.SAN_POLICY_OFFLINE_SHARED
         return san_policy
Exemple #26
0
 def _get_timezone_info(self):
     keyname = os.path.join(REG_TIME_ZONES, self._name)
     try:
         with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, keyname) as key:
             return self._unpack_timezone_info(key)
     except WindowsError as exc:
         if exc.errno == NOT_FOUND:
             raise exception.CloudbaseInitException(
                 "Timezone %r not found" % self._name)
         else:
             raise
Exemple #27
0
def _visual_compiler(output, version):
    'version have to be 8.0, or 9.0 or... anything .0'
    if platform.system().startswith("CYGWIN"):
        return _visual_compiler_cygwin(output, version)

    if version == "15":
        vs_path = os.getenv('vs150comntools')
        path = vs_path or vs_installation_path("15")
        if path:
            compiler = "Visual Studio"
            output.success("Found %s %s" % (compiler, "15"))
            return compiler, "15"
        return None

    version = "%s.0" % version
    from six.moves import winreg  # @UnresolvedImport
    try:
        hKey = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
                              r"SOFTWARE\Microsoft\Windows\CurrentVersion")
        winreg.QueryValueEx(hKey, "ProgramFilesDir (x86)")
        is_64bits = True
    except EnvironmentError:
        is_64bits = False
    finally:
        winreg.CloseKey(hKey)

    if is_64bits:
        key_name = r'SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VC7'
    else:
        key_name = r'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\SxS\VC7'

    try:
        key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, key_name)
        winreg.QueryValueEx(key, version)

        installed_version = Version(version).major(fill=False)
        compiler = "Visual Studio"
        output.success("Found %s %s" % (compiler, installed_version))
        return compiler, installed_version
    except EnvironmentError:
        return None
Exemple #28
0
 def get_browser_path():
     '''获取chorme.exe的路径
     '''
     from six.moves import winreg
     sub_key = r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Google Chrome"
     install_dir = ''
     try:
         hkey = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, sub_key)
         install_dir, _ = winreg.QueryValueEx(hkey, "InstallLocation")
         winreg.CloseKey(hkey)
     except WindowsError:
         try:
             hkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, sub_key)
             install_dir, _ = winreg.QueryValueEx(hkey, "InstallLocation")
         except WindowsError:
             try:
                 sub_key = r"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe"
                 hkey = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, sub_key)
                 install_dir, _ = winreg.QueryValueEx(hkey, "Path")
             except WindowsError:
                 for env_dir in os.getenv('PATH').split(';'):
                     if os.path.exists(os.path.join(env_dir, 'chrome.exe')):
                         install_dir = env_dir
                         break
                 if not install_dir:
                     app_dirs = [
                         os.getenv('LOCALAPPDATA'),
                         os.getenv('ProgramFiles(x86)'),
                         os.getenv('ProgramW6432')
                     ]
                     for app_dir in app_dirs:
                         if (os.path.exists(
                                 os.path.join(app_dir,
                                              r'Google\Chrome\Application',
                                              'chrome.exe'))):
                             install_dir = os.path.join(
                                 app_dir, r'Google\Chrome\Application')
                             break
     if not install_dir:
         raise WindowsError('未找到Chrome可执行文件路径')
     return os.path.join(install_dir, "chrome.exe")
Exemple #29
0
 def get_uac_remote_restrictions(self):
     try:
         with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
                             self._SYSTEM_POLICIES_KEY) as key:
             (value, regtype) = winreg.QueryValueEx(key,
                                                    self._LATFP_VALUE_NAME)
             return not bool(value)
     except WindowsError as e:
         if e.errno == 0x2:
             return True
         else:
             raise
Exemple #30
0
 def _check_server_level(self, server_level):
     try:
         with winreg.OpenKey(
                 winreg.HKEY_LOCAL_MACHINE,
                 "Software\\Microsoft\\Windows NT\\CurrentVersion\\Server\\"
                 "ServerLevels") as key:
             return winreg.QueryValueEx(key, server_level)[0] == 1
     except WindowsError as ex:
         if ex.winerror == 2:
             return False
         else:
             raise