-
-
Notifications
You must be signed in to change notification settings - Fork 318
/
import_metadata.py
52 lines (45 loc) · 1.37 KB
/
import_metadata.py
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
50
51
52
from argparse import ArgumentParser
from xml.dom import minidom
from office365.graph_client import GraphClient
from office365.sharepoint.client_context import ClientContext
from tests import (
test_client_credentials,
test_client_id,
test_client_secret,
test_site_url,
test_tenant,
)
def export_to_file(path, content):
metadata_xml = minidom.parseString(content.decode("utf-8")).toprettyxml(
indent=" "
)
with open(path, "w") as fh:
fh.write(metadata_xml)
parser = ArgumentParser()
parser.add_argument(
"-e",
"--endpoint",
dest="endpoint",
help="Import metadata endpoint",
default="sharepoint",
)
parser.add_argument(
"-p",
"--path",
dest="path",
default="./metadata/SharePoint.xml",
help="Import metadata endpoint",
)
args = parser.parse_args()
if args.endpoint == "sharepoint":
print("Importing SharePoint model metadata...")
ctx = ClientContext(test_site_url).with_credentials(test_client_credentials)
result = ctx.get_metadata().execute_query()
export_to_file(args.path, result.value)
elif args.endpoint == "microsoftgraph":
print("Importing Microsoft Graph model metadata...")
client = GraphClient.with_client_secret(
test_tenant, test_client_id, test_client_secret
)
result = client.get_metadata().execute_query()
export_to_file(args.path, result.value)