forked from systemd/pystemd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.py
More file actions
49 lines (37 loc) · 1.15 KB
/
Copy pathshell.py
File metadata and controls
49 lines (37 loc) · 1.15 KB
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
#!/usr/bin/env python3
#
# Copyright (c) 2017-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the LICENSE file in
# the root directory of this source tree.
#
"""
This file is here so we can annotate a few example of usage, and also it turns
into a nice ipython shell, to run commands interactively.
Needless to say that you need to have the ipython installed.
"""
import runpy
import sys
from pathlib import Path
# pyrefly: ignore [missing-import]
from IPython.terminal.embed import InteractiveShellEmbed
import pystemd
import pystemd.daemon
import pystemd.journal
import pystemd.run
display_banner = """
Welcome to pystemd {pystemd.__version__} interactive shell for python {sys.version}.
""".format(pystemd=pystemd, sys=sys)
def shell() -> None:
shell = InteractiveShellEmbed()
shell.show_banner(display_banner)
shell.mainloop()
def main(mod: Path) -> None:
# pyrefly: ignore [bad-argument-type]
runpy.run_path(mod, {}, "__main__")
if __name__ == "__main__":
if len(sys.argv) > 1:
main(Path(__file__).resolve().absolute().parent / sys.argv[1])
else:
shell()