Tries to determine the name of the Linux OS distribution name. The function first looks for a distribution release file in /etc and then reverts to _dist_try_harder() in case no suitable files are found. supported_dists may be given to define the set of Linux
(
distname, version, id, supported_dists, full_distribution_name
)
| 574 | ) |
| 575 | |
| 576 | def _linux_distribution( |
| 577 | distname, version, id, supported_dists, full_distribution_name |
| 578 | ): |
| 579 | """Tries to determine the name of the Linux OS distribution name. |
| 580 | The function first looks for a distribution release file in |
| 581 | /etc and then reverts to _dist_try_harder() in case no |
| 582 | suitable files are found. |
| 583 | supported_dists may be given to define the set of Linux |
| 584 | distributions to look for. It defaults to a list of currently |
| 585 | supported Linux distributions identified by their release file |
| 586 | name. |
| 587 | If full_distribution_name is true (default), the full |
| 588 | distribution read from the OS is returned. Otherwise the short |
| 589 | name taken from supported_dists is used. |
| 590 | Returns a tuple (distname, version, id) which default to the |
| 591 | args given as parameters. |
| 592 | """ |
| 593 | # check for the Debian/Ubuntu /etc/lsb-release file first, needed so |
| 594 | # that the distribution doesn't get identified as Debian. |
| 595 | # https://bugs.python.org/issue9514 |
| 596 | try: |
| 597 | with open("/etc/lsb-release") as etclsbrel: |
| 598 | for line in etclsbrel: |
| 599 | m = _distributor_id_file_re.search(line) |
| 600 | if m: |
| 601 | _u_distname = m.group(1).strip() |
| 602 | m = _release_file_re.search(line) |
| 603 | if m: |
| 604 | _u_version = m.group(1).strip() |
| 605 | m = _codename_file_re.search(line) |
| 606 | if m: |
| 607 | _u_id = m.group(1).strip() |
| 608 | if _u_distname and _u_version: |
| 609 | return (_u_distname, _u_version, _u_id) |
| 610 | except (OSError, UnboundLocalError): |
| 611 | pass |
| 612 | |
| 613 | try: |
| 614 | etc = os.listdir(_UNIXCONFDIR) |
| 615 | except OSError: |
| 616 | # Probably not a Unix system |
| 617 | return distname, version, id |
| 618 | etc.sort() |
| 619 | for file in etc: |
| 620 | m = _release_filename.match(file) |
| 621 | if m is not None: |
| 622 | _distname, dummy = m.groups() |
| 623 | if _distname in supported_dists: |
| 624 | distname = _distname |
| 625 | break |
| 626 | else: |
| 627 | return _dist_try_harder(distname, version, id) |
| 628 | |
| 629 | # Read the first line |
| 630 | with open( |
| 631 | os.path.join(_UNIXCONFDIR, file), |
| 632 | encoding='utf-8', |
| 633 | errors='surrogateescape', |
no test coverage detected