bbbctl 0.4__tar.gz → 0.4.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bbbctl
3
- Version: 0.4
3
+ Version: 0.4.2
4
4
  Summary: BigBlueButton API command-line client
5
5
  Author-email: Marcel Hellkamp <marc@gsites.de>
6
6
  Requires-Python: >=3.6
@@ -17,14 +17,10 @@ Project-URL: Homepage, https://github.com/defnull/bbbctl
17
17
  This is a small but useful command-line client for controlling meetings and recordings on
18
18
  a [BigBlueButton](https://docs.bigbluebutton.org/) server or cluster directly via the
19
19
  [REST API](https://docs.bigbluebutton.org/dev/api.html). It allows administrators to bypass
20
- front-end applications ([greenlight](https://github.com/bigbluebutton/greenlight),
21
- [moodle](https://moodle.com/certified-integrations/bigbluebutton/) or alternatives) and
20
+ front-end applications (e.g. [greenlight](https://github.com/bigbluebutton/greenlight) or
21
+ [moodle](https://moodle.com/certified-integrations/bigbluebutton/)) and
22
22
  directly access the backing BBB servers for administrative tasks, monitoring or testing.
23
23
 
24
- The module can also be imported as a python library, but please note that this project is
25
- not yet considered stable in any way. A stable and more usable API for python scripting
26
- might follow.
27
-
28
24
  ## Install
29
25
 
30
26
  You can install bbbctl the usual way with `pip install bbbctl` into a virtual environment.
@@ -51,7 +47,6 @@ export BBBCTL_SECRET="..." # or --secret as a parameter
51
47
 
52
48
  # Check if your secret works:
53
49
  bbbctl meeting list
54
-
55
50
  ```
56
51
 
57
52
  ## Command overview
@@ -80,6 +75,21 @@ The default output format is a human readable plain text format. You can switch
80
75
  compact version with `--format=compact`. Other formats that are better suited for scripted
81
76
  usage are also supported: `json`, `jsonline` or `xml`
82
77
 
78
+ ## Use `BBBApiClient` from Python
79
+
80
+ You can use the `BBBApiClient` class from Python, too. This thin wrapper around the
81
+ BBB REST API can send signed API requests and return parsed XML `ElementTree`
82
+ instances. Some convenience methods exist to get just the part of the XML you need.
83
+
84
+ ```python
85
+ from bbbctl import BBBApiClient
86
+
87
+ client = BBBApiClient(api="bbb.example.com", secret="***")
88
+
89
+ for meeting in client.getMeetings():
90
+ print(meeting.findtext("./meetingID"), meeting.findtext("./meetingName"))
91
+ ```
92
+
83
93
  # License
84
94
 
85
95
  Copyright (c) 2020-2062, Marcel Hellkamp.
@@ -3,14 +3,10 @@
3
3
  This is a small but useful command-line client for controlling meetings and recordings on
4
4
  a [BigBlueButton](https://docs.bigbluebutton.org/) server or cluster directly via the
5
5
  [REST API](https://docs.bigbluebutton.org/dev/api.html). It allows administrators to bypass
6
- front-end applications ([greenlight](https://github.com/bigbluebutton/greenlight),
7
- [moodle](https://moodle.com/certified-integrations/bigbluebutton/) or alternatives) and
6
+ front-end applications (e.g. [greenlight](https://github.com/bigbluebutton/greenlight) or
7
+ [moodle](https://moodle.com/certified-integrations/bigbluebutton/)) and
8
8
  directly access the backing BBB servers for administrative tasks, monitoring or testing.
9
9
 
10
- The module can also be imported as a python library, but please note that this project is
11
- not yet considered stable in any way. A stable and more usable API for python scripting
12
- might follow.
13
-
14
10
  ## Install
15
11
 
16
12
  You can install bbbctl the usual way with `pip install bbbctl` into a virtual environment.
@@ -37,7 +33,6 @@ export BBBCTL_SECRET="..." # or --secret as a parameter
37
33
 
38
34
  # Check if your secret works:
39
35
  bbbctl meeting list
40
-
41
36
  ```
42
37
 
43
38
  ## Command overview
@@ -66,6 +61,21 @@ The default output format is a human readable plain text format. You can switch
66
61
  compact version with `--format=compact`. Other formats that are better suited for scripted
67
62
  usage are also supported: `json`, `jsonline` or `xml`
68
63
 
64
+ ## Use `BBBApiClient` from Python
65
+
66
+ You can use the `BBBApiClient` class from Python, too. This thin wrapper around the
67
+ BBB REST API can send signed API requests and return parsed XML `ElementTree`
68
+ instances. Some convenience methods exist to get just the part of the XML you need.
69
+
70
+ ```python
71
+ from bbbctl import BBBApiClient
72
+
73
+ client = BBBApiClient(api="bbb.example.com", secret="***")
74
+
75
+ for meeting in client.getMeetings():
76
+ print(meeting.findtext("./meetingID"), meeting.findtext("./meetingName"))
77
+ ```
78
+
69
79
  # License
70
80
 
71
81
  Copyright (c) 2020-2062, Marcel Hellkamp.
@@ -6,7 +6,7 @@ build-backend = "flit_core.buildapi"
6
6
 
7
7
  [project]
8
8
  name = "bbbctl"
9
- version = "0.4"
9
+ version = "0.4.2"
10
10
  description = "BigBlueButton API command-line client"
11
11
  readme = "README.md"
12
12
  requires-python = ">=3.6"
@@ -335,10 +335,18 @@ class ApiError(RuntimeError):
335
335
 
336
336
 
337
337
  class BBBApiClient:
338
- def __init__(self, api, secret, ssl_context=None):
338
+ def __init__(self, api, secret, ssl_context=None, debug=0):
339
+ # Add scheme if missing
340
+ if "://" not in api:
341
+ api = "https://" + api
342
+ # Add default API path, but only if there is no path yet
343
+ if api.count("/") == 2:
344
+ api += "/bigbluebutton/api"
345
+
339
346
  self.api = api.rstrip("/")
340
347
  self.secret = secret
341
348
  self.ssl = ssl_context or ssl.create_default_context()
349
+ self.debug = max(0, debug)
342
350
 
343
351
  def makeurl(self, command, **query):
344
352
  query = urllib.parse.urlencode(
@@ -354,14 +362,21 @@ class BBBApiClient:
354
362
 
355
363
  def call(self, command, **query):
356
364
  url = self.makeurl(command, **query)
365
+ if self.debug:
366
+ print(f">>> {url}", file=sys.stderr)
357
367
  with urllib.request.urlopen(url, context=self.ssl) as f:
358
368
  xml = f.read().decode("utf8")
369
+ if self.debug >= 2:
370
+ for line in xml:
371
+ print(f"<<< {line}", file=sys.stderr)
359
372
  root = ET.fromstring(xml)
360
373
  if (status := root.find("./returncode")) is None or status.text != "SUCCESS":
361
374
  raise ApiError(root)
362
375
  return root
363
376
 
364
- def getJoinLink(self, **query):
377
+ def getJoinLink(self, meetingID, fullName, **query):
378
+ query["meetingID"] = meetingID
379
+ query["fullName"] = fullName
365
380
  return self.makeurl("join", **query)
366
381
 
367
382
  def getMeetings(self, **query):
@@ -370,13 +385,17 @@ class BBBApiClient:
370
385
  def getRecordings(self, **query):
371
386
  return self.call("getRecordings", **query).findall("./recordings/recording")
372
387
 
373
- def getMeetingInfo(self, **query):
388
+ def getMeetingInfo(self, meetingID, **query):
389
+ query["meetingID"] = meetingID
374
390
  return self.call("getMeetingInfo", **query)
375
391
 
376
- def createMeeting(self, **query):
392
+ def createMeeting(self, meetingID, name, **query):
393
+ query["meetingID"] = meetingID
394
+ query["name"] = name
377
395
  return self.call("create", **query)
378
396
 
379
- def end(self, **query):
397
+ def end(self, meetingID, **query):
398
+ query["meetingID"] = meetingID
380
399
  return self.call("end", **query)
381
400
 
382
401
  def publishRecordings(self, recordID, publish):
@@ -418,6 +437,12 @@ def build_parser():
418
437
  help="Skip TLS verification and accept self-signed or expired SSL certificates",
419
438
  action="store_true",
420
439
  )
440
+ parser.add_argument(
441
+ "-v",
442
+ "--debug",
443
+ help="Print alls API calls. Repeat to also print all API responses.",
444
+ action="count",
445
+ )
421
446
 
422
447
  formats = ["human", "compact", "xml", "json", "jsonline"]
423
448
  parser.add_argument(
@@ -632,18 +657,12 @@ def main():
632
657
  )
633
658
  )
634
659
 
635
- server = server.rstrip("/")
636
- if "://" not in server:
637
- server = "https://" + server
638
- if not server.endswith("/bigbluebutton/api"):
639
- server += "/bigbluebutton/api"
640
-
641
660
  ctx = ssl.create_default_context()
642
661
  if args.insecure:
643
662
  ctx.check_hostname = False
644
663
  ctx.verify_mode = ssl.CERT_NONE
645
664
 
646
- client = BBBApiClient(server, secret, ssl_context=ctx)
665
+ client = BBBApiClient(server, secret, ssl_context=ctx, debug=args.debug)
647
666
 
648
667
  try:
649
668
  args.cmd(client, args)
File without changes