Skip to content

Commit 57f0d51

Browse files
committed
Failed attempt to create a .desktop file
After running the python script, the following command refreshes the database so that it appears in the menu: xdg-desktop-menu install ~/.local/share/applications/maxkapur-fetch_python_docs.py.desktop But running this desktop file even in a terminal shows that it doesn't do anything, even log the usual print output: gio launch ~/.local/share/applications/maxkapur-fetch_python_docs.py.desktop Not sure what's wrong here.
1 parent 9a856d0 commit 57f0d51

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

fetch_python_docs.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,21 @@
1010

1111
HERE = Path(__file__).parent
1212

13+
DOT_DESKTOP = f"""\
14+
[Desktop Entry]
15+
Version=1.0
16+
Name=Python Docs
17+
Comment=View Python docs from a local mirror
18+
Exec={__file__}
19+
# Icon=/todo.png
20+
Path={str(HERE)}
21+
Terminal=false
22+
Type=Application
23+
Categories=Utility;Application;
24+
"""
25+
26+
DOT_DESKTOP_PATH = Path.home() / ".local" / "share" / "applications" / f"maxkapur-{Path(__file__).name}.desktop"
27+
1328
if __name__ == "__main__":
1429
parser = argparse.ArgumentParser(
1530
description="Idempotently download/serve Python docs from a local copy"
@@ -42,6 +57,16 @@
4257
subprocess.run(["tar", "vxf", outfile], cwd=HERE).check_returncode()
4358
assert (outdir / "index.html").is_file()
4459

60+
if sys.platform == "linux":
61+
print(f"Creating .desktop file")
62+
DOT_DESKTOP_PATH.parent.mkdir(exist_ok=True, parents=True)
63+
if DOT_DESKTOP_PATH.is_file():
64+
print(f"{DOT_DESKTOP_PATH} already exists")
65+
else:
66+
with open(DOT_DESKTOP_PATH, "w") as f:
67+
f.write(DOT_DESKTOP)
68+
print(f"Desktop file: {DOT_DESKTOP_PATH}")
69+
4570
if parsed.serve:
4671
# Use a different port from 8000 to avoid conflicting with other
4772
# instances of http.server

0 commit comments

Comments
 (0)