|
1 | 1 | # bcf |
2 | 2 |
|
3 | | -A simple Python implementation of BCF. |
4 | | -Manipulation of BCF-XML is available via `bcfxml.py` and manipulation of BCF-API |
5 | | -is available via `bcfapi.py`. |
6 | | - |
7 | | -It tries to support BCF-XML version 2.1 and 3.0, and BCF-API 3.0. |
8 | | - |
9 | | -## bcfxml |
10 | | - |
11 | | -The `bcfxml.load` function lets you read a BCF-XML file. |
12 | | -It takes care of using the right version based on the "bcf.version" file contained in the BCF package. |
13 | | - |
14 | | -The BCF files are extracted and parsed on-demand, and edits are stored in memory until you call the `save` method. |
15 | | - |
16 | | -```python |
17 | | -from bcf.bcfxml import load |
18 | | - |
19 | | -# Load a project |
20 | | -with load("/path/to/file.bcf") as bcfxml: |
21 | | - project = bcfxml.project |
22 | | - print(project.name) |
23 | | - |
24 | | - # To edit a project, just modify the object directly |
25 | | - bcfxml.project.name = "New name" |
26 | | - |
27 | | - # Get a dictionary of topics |
28 | | - topics = bcfxml.topics |
29 | | - |
30 | | - for topic_guid, topic_handler in bcfxml.topics.items(): |
31 | | - topic = topic_handler.topic |
32 | | - print("Topic guid is", topic.guid) |
33 | | - print("Topic title is", topic.title) |
34 | | - |
35 | | - # Fetch extra data about a topic |
36 | | - header = topic_handler.header |
37 | | - comments = topic_handler.comments |
38 | | - viewpoints = topic_handler.viewpoints |
39 | | - |
40 | | - for comment in comments: |
41 | | - print(comment.guid) |
42 | | - print(comment.comment) |
43 | | - print(comment.author) |
44 | | - |
45 | | - # Get a particular topic |
46 | | - topic = bcfxml.get_topic(guid) |
47 | | - |
48 | | - # Modify a topic |
49 | | - topic.title = "New title" |
50 | | - |
51 | | - bcfxml.save() |
52 | | -``` |
53 | | - |
54 | | -## bcfapi |
55 | | - |
56 | | -The `bcfapi` module lets you interact with the BCF-API standard. |
57 | | - |
58 | | -```python |
59 | | -from bcf.v3.bcfapi import FoundationClient, BcfClient |
60 | | - |
61 | | -foundation_client = FoundationClient("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET", "OPENCDE_BASEURL") |
62 | | -auth_methods = foundation_client.get_auth_methods() |
63 | | - |
64 | | -# Our library currently only implements the authorization_code flow |
65 | | -if "authorization_code" in auth_methods: |
66 | | - foundation_client.login() |
67 | | - |
68 | | -bcf_client = BcfClient(foundation_client) |
69 | | - |
70 | | -versions = foundation_client.get_versions() |
71 | | -for version in versions: |
72 | | -if "3.0" in versions: |
73 | | - if version["api_id"] == "bcf" and version["version_id"] == "3.0": |
74 | | - bcf_client.set_version(version) |
75 | | - |
76 | | -data = bcf_client.get_projects() |
77 | | -print(data) |
78 | | -project_id = data[0]["project_id"] |
79 | | -print(project_id) |
80 | | -data = bcf_client.get_project(project_id) |
81 | | -print(data) |
82 | | -data = bcf_client.get_extensions(project_id) |
83 | | -print(data) |
84 | | -``` |
| 3 | +A simple Python implementation of the BCF standard. Manipulation of BCF-XML is |
| 4 | +available via `bcfxml.py` and manipulation of BCF-API is available via |
| 5 | +`bcfapi.py`. |
0 commit comments