2020-12-15 14:49:29 +11:00
|
|
|
# bcf
|
|
|
|
|
|
|
|
|
|
A simple Python implementation of BCF. The data model is described in `data.py`.
|
|
|
|
|
Manipulation of BCF-XML is available via `bcfxml.py` and manipulation of BCF-API
|
|
|
|
|
is available via `bcfapi.py`.
|
|
|
|
|
|
2021-08-12 12:40:25 +05:30
|
|
|
- BCF-XML version 2.1: Fully supported
|
|
|
|
|
- BCF-API version 2.1: Not supported, will probably tackle this after BCF-API v3.0
|
|
|
|
|
- BCF-XML version 3.0: Almost fully supported, except for the documents module
|
|
|
|
|
- BCF-API version 3.0: Almost fully supported, except for two requests.
|
2020-12-17 22:47:15 +11:00
|
|
|
|
|
|
|
|
## bcfxml
|
|
|
|
|
|
|
|
|
|
The `bcfxml` module lets you interact with the BCF-XML standard.
|
|
|
|
|
|
2021-07-15 18:21:18 +10:00
|
|
|
```python
|
2021-05-17 05:04:31 +05:30
|
|
|
from bcf import bcfxml
|
2020-12-17 22:47:15 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# Load a project
|
2021-05-17 05:04:31 +05:30
|
|
|
bcfxml = bcfxml.load("/path/to/file.bcf")
|
|
|
|
|
|
2020-12-17 22:47:15 +11:00
|
|
|
|
|
|
|
|
# The project is also stored in the module
|
|
|
|
|
# project == bcfxml.project
|
2021-05-17 05:04:31 +05:30
|
|
|
project=bcfxml.get_project()
|
2020-12-17 22:47:15 +11:00
|
|
|
print(project.name)
|
|
|
|
|
|
|
|
|
|
# To edit a project, just modify the object directly
|
|
|
|
|
bcfxml.project.name = "New name"
|
|
|
|
|
bcfxml.edit_project()
|
|
|
|
|
|
|
|
|
|
# The BCF file is extracted to this temporary directory
|
|
|
|
|
print(bcfxml.filepath)
|
|
|
|
|
|
|
|
|
|
# Get a dictionary of topics
|
|
|
|
|
topics = bcfxml.get_topics()
|
|
|
|
|
|
|
|
|
|
# Note: topics == bcfxml.topics
|
|
|
|
|
for guid, topic in bcfxml.topics.items():
|
|
|
|
|
print("Topic guid is", guid)
|
|
|
|
|
print("Topic guid is", topic.guid)
|
|
|
|
|
print("Topic title is", topic.title)
|
|
|
|
|
|
|
|
|
|
# Fetch extra data about a topic
|
|
|
|
|
header = bcfxml.get_header(guid)
|
|
|
|
|
comments = bcfxml.get_comments(guid)
|
|
|
|
|
viewpoints = bcfxml.get_viewpoints(guid)
|
|
|
|
|
|
|
|
|
|
# Note: comments == topic.comments, and so on
|
|
|
|
|
for comment_guid, comment in comments.items():
|
|
|
|
|
print(comment_guid)
|
|
|
|
|
print(comment.comment)
|
|
|
|
|
print(comment.author)
|
|
|
|
|
|
|
|
|
|
# Get a particular topic
|
|
|
|
|
topic = bcfxml.get_topic(guid)
|
|
|
|
|
|
|
|
|
|
# Modify a topic
|
|
|
|
|
topic.title = "New title"
|
|
|
|
|
bcfxml.edit_topic(topic)
|
|
|
|
|
```
|
2021-07-15 18:02:16 +10:00
|
|
|
|
|
|
|
|
## bcfapi
|
|
|
|
|
|
|
|
|
|
The `bcfapi` module lets you interact with the BCF-API standard.
|
|
|
|
|
|
2021-07-15 18:21:18 +10:00
|
|
|
```python
|
2021-08-06 16:44:47 +10:00
|
|
|
from bcf.v3.bcfapi import FoundationClient, BcfClient
|
2021-07-15 18:02:16 +10:00
|
|
|
|
2021-08-04 18:03:52 +10:00
|
|
|
foundation_client = FoundationClient("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET", "OPENCDE_BASEURL")
|
|
|
|
|
auth_methods = foundation_client.get_auth_methods()
|
2021-07-15 18:02:16 +10:00
|
|
|
|
|
|
|
|
# Our library currently only implements the authorization_code flow
|
|
|
|
|
if "authorization_code" in auth_methods:
|
2021-08-12 12:40:25 +05:30
|
|
|
foundation_client.login()
|
2021-07-15 18:02:16 +10:00
|
|
|
|
2021-08-12 12:40:25 +05:30
|
|
|
bcf_client = BcfClient(foundation_client)
|
2021-07-15 18:02:16 +10:00
|
|
|
|
2021-08-04 18:03:52 +10:00
|
|
|
versions = foundation_client.get_versions()
|
|
|
|
|
for version in versions:
|
2021-07-15 18:02:16 +10:00
|
|
|
if "3.0" in versions:
|
2021-08-04 18:03:52 +10:00
|
|
|
if version["api_id"] == "bcf" and version["version_id"] == "3.0":
|
|
|
|
|
bcf_client.set_version(version)
|
2021-07-15 18:02:16 +10:00
|
|
|
|
2021-08-04 18:03:52 +10:00
|
|
|
data = bcf_client.get_projects()
|
2021-07-15 18:02:16 +10:00
|
|
|
print(data)
|
|
|
|
|
project_id = data[0]["project_id"]
|
|
|
|
|
print(project_id)
|
2021-08-04 18:03:52 +10:00
|
|
|
data = bcf_client.get_project(project_id)
|
2021-07-15 18:02:16 +10:00
|
|
|
print(data)
|
2021-08-04 18:03:52 +10:00
|
|
|
data = bcf_client.get_extensions(project_id)
|
2021-07-15 18:02:16 +10:00
|
|
|
print(data)
|
|
|
|
|
```
|
2021-07-17 12:12:19 +05:30
|
|
|
|
2021-08-04 18:03:52 +10:00
|
|
|
## Todo List
|
2021-08-12 12:40:25 +05:30
|
|
|
|
2021-07-17 12:12:19 +05:30
|
|
|
The remaining work that needs to be completed in `bcfxml.py` and `bcfapi.py`.
|
|
|
|
|
|
2021-08-12 12:40:25 +05:30
|
|
|
- For `bcfxml.py` two xsds support is remaining namely 'documents.xsd`and`extensions.xsd`.
|
|
|
|
|
- For `bcfapi.py` two requests that are `get_topics` and `get_comments` are remaining.
|