Skip to content

Commit 187b04d

Browse files
committed
Complete demo_frontend.py
1 parent 0237a89 commit 187b04d

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

docs/assets/demo_frontend.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
################################################
2+
import os, signal
3+
if ("nt" == os.name):
4+
raise RuntimeError("CANNOT RUN ON WINDOWS "
5+
"https://pexpect.readthedocs.io/en/stable/"
6+
"overview.html#pexpect-on-windows")
7+
_S_ = 300
8+
__GOTOWORKDIR = os.path.dirname(os.path.dirname(
9+
os.path.dirname(os.path.abspath(__file__))))
10+
__OPENTHISLOG = os.path.join(__GOTOWORKDIR,
11+
"docs/assets/demo_frontend.logger")
12+
__OPENTHISOUT = os.path.join(__GOTOWORKDIR,
13+
"docs/assets/demo_frontend.stdout")
14+
__LOADTHISENV = dict(os.environ, **{
15+
"PYTHONBUGZILLA_LOG_FILE" : __OPENTHISLOG,
16+
"PYTHONBUGZILLA_REQUESTS_TIMEOUT" : str(_S_)})
17+
try:
18+
import pexpect
19+
except ImportError as e:
20+
raise RuntimeError("missing pexpect "
21+
"https://github.com/pexpect/pexpect") from e
22+
################################################
23+
FHEAD = lambda E,W : E.expect_exact("\n|v>{}<v|".format(W))
24+
FTAIL = lambda E,W : E.expect_exact("\n|^>{}<^|".format(W))
25+
FDATA = lambda E,W : [FHEAD(E,W), FTAIL(E,W), bytes.decode(E.before, encoding="utf-8").strip()][2]
26+
MIPET = pexpect.spawn("/usr/bin/env python3 ./bugzilla-mi", cwd=__GOTOWORKDIR, env=__LOADTHISENV, maxread=1, timeout=_S_)
27+
MIOUT = open(__OPENTHISOUT, mode="w", encoding="utf-8")
28+
################################################
29+
30+
''' bugzilla.mozilla.org '''
31+
D = "Catch being wait mozilla ----->{}<-----".format(
32+
FDATA(MIPET, "ARGINF"))
33+
print(D); MIOUT.write(D)
34+
35+
MIPET.sendline("very wrong arguments")
36+
D = "Catch argparse error ----->{}<-----".format(
37+
FDATA(MIPET, "ARGINF"))
38+
print(D); MIOUT.write(D)
39+
40+
MIPET.sendline("--bugzilla https://bugzilla.mozilla.org/rest --verbose info --products")
41+
D = "Catch output products ----->{}<-----".format(
42+
FDATA(MIPET, "STRING"))
43+
print(D); MIOUT.write(D)
44+
45+
D = "Catch being wait again ----->{}<-----".format(
46+
FDATA(MIPET, "ARGINF"))
47+
print(D); MIOUT.write(D)
48+
49+
MIPET.sendline("--bugzilla https://bugzilla.mozilla.org/rest --debug query --json --bug_id 255606")
50+
D = "Catch json output query 255606 ----->{}<-----".format(
51+
FDATA(MIPET, "STRING"))
52+
print(D); MIOUT.write(D)
53+
54+
''' bugs.documentfoundation.org '''
55+
D = "Catch being wait libreoffce ----->{}<-----".format(
56+
FDATA(MIPET, "ARGINF"))
57+
print(D); MIOUT.write(D)
58+
59+
MIPET.sendline("--bugzilla https://bugs.documentfoundation.org/rest --debug info --products")
60+
D = "Catch output bugzilla with `--products` ----->{}<-----".format(
61+
FDATA(MIPET, "STRING"))
62+
print(D); MIOUT.write(D)
63+
64+
D = "Catch being wait again ----->{}<-----".format(
65+
FDATA(MIPET, "ARGINF"))
66+
print(D); MIOUT.write(D)
67+
68+
MIPET.sendline("--bugzilla https://bugs.documentfoundation.org/rest --debug query --json --from-url "
69+
"'buglist.cgi?chfield=rep_platform&chfieldto=Now&component=LibreOffice&product=LibreOffice"
70+
"&query_format=advanced&resolution=---&short_desc=overflow&short_desc_type=allwordssubstr'")
71+
D = "Catch json output with `--from-url` ----->{}<-----".format(
72+
FDATA(MIPET, "STRING"))
73+
print(D); MIOUT.write(D)
74+
75+
################################################
76+
print("WILL SEND SIGKILL")
77+
MIPET.kill(signal.SIGKILL)
78+
MIOUT.close()
79+
print("END")
80+
################################################

0 commit comments

Comments
 (0)