Compiled and tested examples¶
These listings are included directly from sources compiled or executed by CI.
C quickstart¶
1#include <postproject/postproject.h>
2
3#include <stdio.h>
4
5static void print_uuid(const pp_uuid_t *id) {
6 for (size_t index = 0; index < sizeof(id->bytes); ++index) {
7 printf("%02x", id->bytes[index]);
8 }
9 putchar('\n');
10}
11
12int main(int argc, char **argv) {
13 if (argc != 3) {
14 fprintf(stderr,
15 "usage: postproject-c-example OUTPUT_PRODUCTION MEDIA_FILE\n");
16 return 2;
17 }
18
19 pp_production_t *production = NULL;
20 pp_transaction_t *transaction = NULL;
21 pp_representation_set_t *representations = NULL;
22 pp_error_t *error = NULL;
23 pp_uuid_t asset_id = {{0}};
24 pp_error_code_t status =
25 pp_production_create(argv[1], "C quickstart", &production, &error);
26 if (status == PP_OK) {
27 status = pp_production_begin_transaction(production, &transaction, &error);
28 }
29 if (status == PP_OK) {
30 status = pp_transaction_import_media(transaction, argv[2], NULL, &asset_id,
31 &error);
32 }
33 if (status == PP_OK) {
34 status = pp_transaction_commit(transaction, &error);
35 }
36 if (status == PP_OK) {
37 status = pp_production_representations(production, &asset_id,
38 &representations, &error);
39 }
40
41 if (status != PP_OK) {
42 fprintf(stderr, "operation failed (%u): %s\n", status,
43 error != NULL ? pp_error_message(error) : "no details");
44 } else {
45 print_uuid(&asset_id);
46 printf("representations: %llu\n",
47 (unsigned long long)pp_representation_set_count(representations));
48 }
49 pp_error_release(error);
50 pp_representation_set_release(representations);
51 pp_transaction_release(transaction);
52 pp_production_release(production);
53 return status == PP_OK ? 0 : 1;
54}
C++17 quickstart¶
1#include <postproject/postproject.hpp>
2
3#include <exception>
4#include <iostream>
5
6int main(int argc, char **argv) {
7 if (argc != 3) {
8 std::cerr
9 << "usage: postproject-cpp-example OUTPUT_PRODUCTION MEDIA_FILE\n";
10 return 2;
11 }
12
13 try {
14 auto production = postproject::Production::create(argv[1], "C++ quickstart");
15 auto transaction = production.beginTransaction();
16 const auto asset_id = transaction.importMedia(argv[2], "Quickstart media");
17 transaction.commit();
18 std::cout << "representations: "
19 << production.representations(asset_id).size() << '\n';
20 } catch (const postproject::Error &error) {
21 std::cerr << error.what() << '\n';
22 return 1;
23 }
24}
Python quickstart¶
1"""Create a production and import one opaque media fixture."""
2
3from __future__ import annotations
4
5import argparse
6from pathlib import Path
7
8from postproject import OriginIdentity, Production
9
10
11def main() -> None:
12 parser = argparse.ArgumentParser()
13 parser.add_argument("production", type=Path)
14 parser.add_argument("media", type=Path)
15 args = parser.parse_args()
16
17 with Production.create(args.production, "Python quickstart") as production:
18 with production.transaction(
19 origin=OriginIdentity("org.postproject:python-quickstart"),
20 message="Import quickstart media",
21 ) as transaction:
22 asset_id = transaction.import_media(
23 args.media, display_name="Quickstart media"
24 )
25
26 representations = production.representations[asset_id]
27 print(f"representations: {len(representations)}")
28
29
30if __name__ == "__main__":
31 main()