View | Details | Raw Unified | Return to bug 34421
Collapse All | Expand All

(-)Python/Lib/platform.py (-27 / +46 lines)
Lines 314-348 Link Here
314
        args given as parameters.
314
        args given as parameters.
315
315
316
    """
316
    """
317
    try:
317
    _os_release = '/etc/os-release'
318
        etc = os.listdir('/etc')
318
    if os.path.exists(_os_release) == True:
319
    except os.error:
319
320
        # Probably not a Unix system
320
        try:
321
        return distname,version,id
321
            _os_release_file = open(_os_release)
322
    etc.sort()
322
            _os_release_content = _os_release_file.read()
323
    for file in etc:
323
        except IOError:
324
        m = _release_filename.match(file)
324
            pass
325
        if m is not None:
325
326
            _distname,dummy = m.groups()
326
        get_name = re.findall(r'NAME=.*', _os_release_content)[0]
327
            if _distname in supported_dists:
327
        distname = get_name.split('"')[1]
328
                distname = _distname
328
        get_version = re.findall(r'VERSION=.*', _os_release_content)[0]
329
                break
329
        version = get_version.split('"')[1]
330
        get_id = re.findall(r'ID=.*', _os_release_content)[0]
331
        id = get_id.split('=')[1]
332
        return distname, version, id
333
330
    else:
334
    else:
331
        return _dist_try_harder(distname,version,id)
332
335
333
    # Read the first line
336
        try:
334
    f = open('/etc/'+file, 'r')
337
            etc = os.listdir('/etc')
335
    firstline = f.readline()
338
        except os.error:
336
    f.close()
339
            # Probably not a Unix system
337
    _distname, _version, _id = _parse_release_file(firstline)
340
            return distname,version,id
338
341
        etc.sort()
339
    if _distname and full_distribution_name:
342
        for file in etc:
340
        distname = _distname
343
            m = _release_filename.match(file)
341
    if _version:
344
            if m is not None:
342
        version = _version
345
                _distname,dummy = m.groups()
343
    if _id:
346
                if _distname in supported_dists:
344
        id = _id
347
                    distname = _distname
345
    return distname, version, id
348
                    break
349
        else:
350
            return _dist_try_harder(distname,version,id)
351
352
        # Read the first line
353
        f = open('/etc/'+file, 'r')
354
        firstline = f.readline()
355
        f.close()
356
        _distname, _version, _id = _parse_release_file(firstline)
357
358
        if _distname and full_distribution_name:
359
            distname = _distname
360
        if _version:
361
            version = _version
362
        if _id:
363
            id = _id
364
        return distname, version, id
346
365
347
# To maintain backwards compatibility:
366
# To maintain backwards compatibility:
348
367

Return to bug 34421