GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — PgnDownloaderGUI/main.py at main · codeguy-jv2080/PgnDownloaderGUI

Expand file tree

/

main.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
115 lines (92 loc) · 4.08 KB
/

main.py

Copy path

File metadata and controls

115 lines (92 loc) · 4.08 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
"""Windows desktop entry point and deliberately headless maintenance commands."""
from __future__ import annotations
import argparse
import multiprocessing
from pathlib import Path
import secrets
import sys
import traceback
from datetime import datetime, timezone
def _port(value: str) -> int:
port = int(value)
if not 1 <= port <= 65535:
raise argparse.ArgumentTypeError("port must be between 1 and 65535")
return port
def _parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(description="PGN Downloader for Windows")
mode = parser.add_mutually_exclusive_group()
mode.add_argument("--serve", action="store_true", help="run the local server without a desktop window")
mode.add_argument("--self-test", action="store_true", help="run offline checks without opening a window")
mode.add_argument("--headless-smoke", action="store_true", help="alias for --self-test")
parser.add_argument("--data-dir", type=Path, help="use this local data directory")
parser.add_argument("--report", type=Path, help="write the self-test JSON report here")
parser.add_argument("--port", type=_port, default=8765, help="loopback port for --serve (default: 8765)")
parser.add_argument("--token", help="use this session token instead of generating one")
return parser
def _record_startup_error(data_dir: Path | None) -> Path | None:
if data_dir is None:
return None
try:
data_dir.mkdir(parents=True, exist_ok=True)
log_path = data_dir / "startup-error.log"
with log_path.open("a", encoding="utf-8") as log:
log.write(f"\n{datetime.now(timezone.utc).isoformat()}\n")
traceback.print_exc(file=log)
return log_path
except OSError:
return None
def main(argv: list[str] | None = None) -> int:
parser = _parser()
args = parser.parse_args(argv)
is_self_test = args.self_test or args.headless_smoke
if args.report is not None and not is_self_test:
parser.error("--report is only available with --self-test or --headless-smoke")
if args.token == "":
parser.error("--token cannot be empty")
data_dir: Path | None = None
try:
from app.paths import default_data_dir
data_dir = (args.data_dir or default_data_dir()).expanduser().resolve()
data_dir.mkdir(parents=True, exist_ok=True)
if is_self_test:
from app.selftest import run
report_path = (args.report or data_dir / "selftest-report.json").expanduser().resolve()
return 0 if run(data_dir, report_path) else 1
token = args.token or secrets.token_urlsafe(32)
if args.serve:
from urllib.parse import quote
import uvicorn
from app.server import create_app
print(f"Local interface: http://127.0.0.1:{args.port}/#token={quote(token, safe='')}")
print("Press Ctrl+C to stop the server.")
uvicorn.run(
create_app(data_dir=data_dir, token=token),
host="127.0.0.1",
port=args.port,
access_log=False,
lifespan="on",
)
return 0
from app.desktop import run_desktop
run_desktop(data_dir=data_dir, token=token)
return 0
except KeyboardInterrupt:
return 130
except Exception as exc:
log_path = _record_startup_error(data_dir)
message = f"PGN Downloader could not start.\n\n{exc}"
if log_path is not None:
message += f"\n\nDetails were saved to:\n{log_path}"
if not getattr(sys, "frozen", False):
message += "\n\nIf dependencies are missing, run setup.bat first."
if args.serve or is_self_test:
if sys.stderr is not None:
print(message, file=sys.stderr)
else:
# Only an actual desktop launch may show a native error dialog.
import ctypes
ctypes.windll.user32.MessageBoxW(None, message, "PGN Downloader", 0x10)
return 1
if __name__ == "__main__":
multiprocessing.freeze_support()
raise SystemExit(main())
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.