File: __main__.py

package info (click to toggle)
pygame 2.1.2%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 32,416 kB
  • sloc: ansic: 66,042; python: 46,176; javascript: 9,214; objc: 273; sh: 78; makefile: 56; cpp: 25
file content (38 lines) | stat: -rw-r--r-- 1,020 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# python -m pygame.docs

import os
import webbrowser
from urllib.parse import quote, urlunparse


def _iterpath(path):
    path, last = os.path.split(path)
    if last:
        for p in _iterpath(path):
            yield p
        yield last


# for test suite to confirm pygame built with local docs
def has_local_docs():
    pkg_dir = os.path.dirname(os.path.abspath(__file__))
    main_page = os.path.join(pkg_dir, "generated", "index.html")
    return os.path.exists(main_page)


def open_docs():
    pkg_dir = os.path.dirname(os.path.abspath(__file__))
    main_page = os.path.join(pkg_dir, "generated", "index.html")
    if os.path.exists(main_page):
        url_path = quote("/".join(_iterpath(main_page)))
        drive, rest = os.path.splitdrive(__file__)
        if drive:
            url_path = "%s/%s" % (drive, url_path)
        url = urlunparse(("file", "", url_path, "", "", ""))
    else:
        url = "https://www.pygame.org/docs/"
    webbrowser.open(url)


if __name__ == "__main__":
    open_docs()