Exemple #1
0
def _get_chrome_path(ini_path: str = None) -> Union[str, None]:
    """从ini文件或系统变量中获取chrome.exe的路径    \n
    :param ini_path: ini文件路径
    :return: chrome.exe路径
    """
    # -----------从ini文件中获取--------------
    try:
        path = OptionsManager(ini_path).chrome_options['binary_location']
    except KeyError:
        return None

    if path and Path(path).is_file():
        print('ini文件中', end='')
        return str(path)

    # -----------从系统路径中获取--------------
    paths = popen('set path').read().lower()
    r = RE_SEARCH(r'[^;]*chrome[^;]*', paths)

    if r:
        path = Path(r.group(0)) if 'chrome.exe' in r.group(0) else Path(
            r.group(0)) / 'chrome.exe'

        if path.exists():
            print('系统中', end='')
            return str(path)

    paths = paths.split(';')

    for path in paths:
        path = Path(path) / 'chrome.exe'

        if path.exists():
            print('系统中', end='')
            return str(path)
 def readPhysicstext(self,name,attrs):
     '''
         Reads physical data from text fields
     '''    
     txt=self.__current["data"]
     regexp = \
       r'([a-zA-Z]*)(?:\s|=)*([-+]?\d*\.?\d+(?:[eE][-+]?\d+)?)\s*([a-zA-Z]*)'
     number=RegSearch(regexp,txt)
     if number:
         self.model[number.group(1).lower()] = \
                                    (float(number.group(2)), number.group(3))
     print "... Read Physics data " + number.group(1).lower()
 def readPhysicstext(self, name, attrs):
     '''
         Reads physical data from text fields
     '''
     txt = self.__current["data"]
     regexp = \
       r'([a-zA-Z]*)(?:\s|=)*([-+]?\d*\.?\d+(?:[eE][-+]?\d+)?)\s*([a-zA-Z]*)'
     number = RegSearch(regexp, txt)
     if number:
         self.model[number.group(1).lower()] = \
                                    (float(number.group(2)), number.group(3))
     print "... Read Physics data " + number.group(1).lower()
 else:
     file_js = file_js[1]
 with open(file_js) as ff:
     data_json = json.load(ff)
 data_json = data_json["RESULTS"]["model"][model]
 ff.close()
 del ff, file_js
 files_nc = sorted(list(
     GLOBiglob(
         OSpath__join(
             path_nc, "cmip?_" + experiment + "_" + metric_col +
             "_v2019????_" + model + "_*.nc"))),
                   key=lambda v: v.upper())
 for file1 in files_nc:
     # find metric name
     metric = REsearch("_v2019(.+?)_" + model + "_(.+?).nc", file1)
     metric = metric.group(2)
     if 'SstDiv' in metric or 'SstDur' in metric:
         pass
     else:
         # find metric observations and variable(s)
         met_obs = dict_MC[metric]["obs_name"]
         met_var = dict_MC[metric]["variables"]
         print str().ljust(10) + metric
         # open file
         ff = open_dataset(file1, decode_times=False)
         # variables to read
         var_in = sorted([
             var
             for var in ff.keys() if var not in no_var and ff[var].ndim == 1
         ],
Exemple #5
0
def _get_chrome_path(
    ini_path: str = None,
    show_msg: bool = True,
    from_ini: bool = True,
    from_regedit: bool = True,
    from_system_path: bool = True,
) -> Union[str, None]:
    """从ini文件或系统变量中获取chrome.exe的路径    \n
    :param ini_path: ini文件路径
    :return: chrome.exe路径
    """
    # -----------从ini文件中获取--------------
    if ini_path and from_ini:
        try:
            path = OptionsManager(ini_path).chrome_options['binary_location']
        except KeyError:
            path = None
    else:
        path = None

    if path and Path(path).is_file():
        print('ini文件中', end='')
        return str(path)

    # -----------从注册表中获取--------------
    if from_regedit:
        import winreg
        try:
            key = winreg.OpenKey(
                winreg.HKEY_LOCAL_MACHINE,
                r'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe',
                reserved=0,
                access=winreg.KEY_READ)
            k = winreg.EnumValue(key, 0)
            winreg.CloseKey(key)

            if show_msg:
                print('注册表中', end='')

            return k[1]

        except FileNotFoundError:
            pass

    # -----------从系统变量中获取--------------
    if from_system_path:
        paths = popen('set path').read().lower()
        r = RE_SEARCH(r'[^;]*chrome[^;]*', paths)

        if r:
            path = Path(r.group(0)) if 'chrome.exe' in r.group(0) else Path(
                r.group(0)) / 'chrome.exe'

            if path.exists():
                if show_msg:
                    print('系统变量中', end='')
                return str(path)

        paths = paths.split(';')

        for path in paths:
            path = Path(path) / 'chrome.exe'

            try:
                if path.exists():
                    if show_msg:
                        print('系统变量中', end='')
                    return str(path)
            except OSError:
                pass