ADCT Python
Python client API implementation for publishing ADCT data
Loading...
Searching...
No Matches
Functions
adctk_publish Namespace Reference

Functions

 get_args ()
 
 setup_builder (app_name)
 
 setup_publisher ()
 
Builder get_data_section_from_file (filepath)
 
int main ()
 

Function Documentation

◆ get_args()

adctk_publish.get_args ( )
16def get_args():
17 parser = argparse.ArgumentParser()
18 parser.add_argument("app_name", type=str,
19 help="Name of application (posts to collection of this name)")
20 parser.add_argument("--app-data", dest="app_data", type=str, default=None,
21 help="Path to app data file containing json")
22 parser.add_argument("--dry-run", dest="dry_run", action="store_true", default=False,
23 help="don't actually post")
24 parser.add_argument("--logger-filepath", dest="logger_filepath", default="", type=str,
25 help="Directory pointing to path where log file will be written " + \
26 "only directory path is accepted at this time")
27 parser.add_argument("--logger-stream", dest="logger_stream", action="store_true", default=False,
28 help="Enable stream output to stdout")
29 return parser.parse_args()
30
31

◆ get_data_section_from_file()

Builder adctk_publish.get_data_section_from_file (   filepath)
40def get_data_section_from_file(filepath) -> Builder:
41 data = None
42 try:
43 with open(filepath, 'r') as file:
44 data = json.load(file)
45 except FileNotFoundError:
46 print("The file was not found.")
47 except json.JSONDecodeError:
48 print("Failed to decode JSON. Check if the file is correctly formatted.")
50 b.add_json_string(json.dumps(data, skipkeys=True))
51 # done-cbb: maybe iterate the keys in data and add them so that data is typed in json result.
52 # but if user wanted that, they wouldn't be calling us with a json blob.
53 return b
54
builder.Builder get_builder()
Create an empty builder object or subobject for an adctk message.
Definition factory.py:44

◆ main()

int adctk_publish.main ( )
55def main() -> int:
56 args = get_args()
57
58 if args.logger_stream:
59 setup_stream_handler()
60
61 if args.logger_filepath:
62 setup_file_handler(args.logger_filepath)
63
64 builder = setup_builder(args.app_name)
65
66 if args.app_data:
67 section = get_data_section_from_file(args.app_data)
68 builder.add_section(section)
69
70 if args.dry_run:
71 logger.info("Exiting because dry_run was supplied")
72 return 0
73
74 publisher = setup_publisher()
75 ret = publisher.publish(builder)
76 print(ret)
77 return 0
78
79

◆ setup_builder()

adctk_publish.setup_builder (   app_name)
32def setup_builder(app_name):
33 return Builder.BasicBuilder(app_name)
34
35

◆ setup_publisher()

adctk_publish.setup_publisher ( )
36def setup_publisher():
37 return HttpPublisher()
38
39