pltr-cli 0.4.0__py3-none-any.whl → 0.5.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pltr/utils/formatting.py CHANGED
@@ -537,3 +537,748 @@ class OutputFormatter:
537
537
  return self.format_output(display_data, format_type, output_file)
538
538
  else:
539
539
  return self.format_output(status_info, format_type, output_file)
540
+
541
+ # ============================================================================
542
+ # Orchestration Formatting Methods
543
+ # ============================================================================
544
+
545
+ def format_build_detail(
546
+ self,
547
+ build: Dict[str, Any],
548
+ format_type: str = "table",
549
+ output_file: Optional[str] = None,
550
+ ) -> Optional[str]:
551
+ """
552
+ Format detailed build information.
553
+
554
+ Args:
555
+ build: Build dictionary
556
+ format_type: Output format
557
+ output_file: Optional output file path
558
+
559
+ Returns:
560
+ Formatted string if no output file specified
561
+ """
562
+ if format_type == "table":
563
+ # For table format, show key-value pairs
564
+ details = []
565
+
566
+ # Define the order of properties to display
567
+ property_order = [
568
+ "rid",
569
+ "status",
570
+ "created_by",
571
+ "created_time",
572
+ "started_time",
573
+ "finished_time",
574
+ "branch_name",
575
+ "commit_hash",
576
+ ]
577
+
578
+ for prop in property_order:
579
+ if build.get(prop) is not None:
580
+ value = build[prop]
581
+ # Format timestamps
582
+ if "time" in prop:
583
+ value = self._format_datetime(value)
584
+ details.append(
585
+ {
586
+ "Property": prop.replace("_", " ").title(),
587
+ "Value": str(value),
588
+ }
589
+ )
590
+
591
+ # Add any remaining properties
592
+ for key, value in build.items():
593
+ if key not in property_order and value is not None:
594
+ details.append(
595
+ {"Property": key.replace("_", " ").title(), "Value": str(value)}
596
+ )
597
+
598
+ return self.format_output(details, format_type, output_file)
599
+ else:
600
+ return self.format_output(build, format_type, output_file)
601
+
602
+ def format_builds_list(
603
+ self,
604
+ builds: List[Dict[str, Any]],
605
+ format_type: str = "table",
606
+ output_file: Optional[str] = None,
607
+ ) -> Optional[str]:
608
+ """
609
+ Format list of builds.
610
+
611
+ Args:
612
+ builds: List of build dictionaries
613
+ format_type: Output format
614
+ output_file: Optional output file path
615
+
616
+ Returns:
617
+ Formatted string if no output file specified
618
+ """
619
+ formatted_builds = []
620
+ for build in builds:
621
+ formatted_build = {
622
+ "RID": build.get("rid", ""),
623
+ "Status": build.get("status", ""),
624
+ "Created By": build.get("created_by", ""),
625
+ "Created": self._format_datetime(build.get("created_time")),
626
+ "Branch": build.get("branch_name", ""),
627
+ }
628
+ formatted_builds.append(formatted_build)
629
+
630
+ return self.format_output(formatted_builds, format_type, output_file)
631
+
632
+ def format_job_detail(
633
+ self,
634
+ job: Dict[str, Any],
635
+ format_type: str = "table",
636
+ output_file: Optional[str] = None,
637
+ ) -> Optional[str]:
638
+ """
639
+ Format detailed job information.
640
+
641
+ Args:
642
+ job: Job dictionary
643
+ format_type: Output format
644
+ output_file: Optional output file path
645
+
646
+ Returns:
647
+ Formatted string if no output file specified
648
+ """
649
+ if format_type == "table":
650
+ # For table format, show key-value pairs
651
+ details = []
652
+
653
+ # Define the order of properties to display
654
+ property_order = [
655
+ "rid",
656
+ "status",
657
+ "job_type",
658
+ "build_rid",
659
+ "created_time",
660
+ "started_time",
661
+ "finished_time",
662
+ ]
663
+
664
+ for prop in property_order:
665
+ if job.get(prop) is not None:
666
+ value = job[prop]
667
+ # Format timestamps
668
+ if "time" in prop:
669
+ value = self._format_datetime(value)
670
+ details.append(
671
+ {
672
+ "Property": prop.replace("_", " ").title(),
673
+ "Value": str(value),
674
+ }
675
+ )
676
+
677
+ # Add any remaining properties
678
+ for key, value in job.items():
679
+ if key not in property_order and value is not None:
680
+ details.append(
681
+ {"Property": key.replace("_", " ").title(), "Value": str(value)}
682
+ )
683
+
684
+ return self.format_output(details, format_type, output_file)
685
+ else:
686
+ return self.format_output(job, format_type, output_file)
687
+
688
+ def format_jobs_list(
689
+ self,
690
+ jobs: List[Dict[str, Any]],
691
+ format_type: str = "table",
692
+ output_file: Optional[str] = None,
693
+ ) -> Optional[str]:
694
+ """
695
+ Format list of jobs.
696
+
697
+ Args:
698
+ jobs: List of job dictionaries
699
+ format_type: Output format
700
+ output_file: Optional output file path
701
+
702
+ Returns:
703
+ Formatted string if no output file specified
704
+ """
705
+ formatted_jobs = []
706
+ for job in jobs:
707
+ formatted_job = {
708
+ "RID": job.get("rid", ""),
709
+ "Status": job.get("status", ""),
710
+ "Type": job.get("job_type", ""),
711
+ "Build": job.get("build_rid", "")[:12] + "..."
712
+ if job.get("build_rid")
713
+ else "",
714
+ "Started": self._format_datetime(job.get("started_time")),
715
+ }
716
+ formatted_jobs.append(formatted_job)
717
+
718
+ return self.format_output(formatted_jobs, format_type, output_file)
719
+
720
+ def format_schedule_detail(
721
+ self,
722
+ schedule: Dict[str, Any],
723
+ format_type: str = "table",
724
+ output_file: Optional[str] = None,
725
+ ) -> Optional[str]:
726
+ """
727
+ Format detailed schedule information.
728
+
729
+ Args:
730
+ schedule: Schedule dictionary
731
+ format_type: Output format
732
+ output_file: Optional output file path
733
+
734
+ Returns:
735
+ Formatted string if no output file specified
736
+ """
737
+ if format_type == "table":
738
+ # For table format, show key-value pairs
739
+ details = []
740
+
741
+ # Define the order of properties to display
742
+ property_order = [
743
+ "rid",
744
+ "display_name",
745
+ "description",
746
+ "paused",
747
+ "created_by",
748
+ "created_time",
749
+ "modified_by",
750
+ "modified_time",
751
+ ]
752
+
753
+ for prop in property_order:
754
+ if schedule.get(prop) is not None:
755
+ value = schedule[prop]
756
+ # Format timestamps
757
+ if "time" in prop:
758
+ value = self._format_datetime(value)
759
+ # Format boolean values
760
+ elif prop == "paused":
761
+ value = "Yes" if value else "No"
762
+ details.append(
763
+ {
764
+ "Property": prop.replace("_", " ").title(),
765
+ "Value": str(value),
766
+ }
767
+ )
768
+
769
+ # Handle special nested properties
770
+ if schedule.get("trigger"):
771
+ details.append(
772
+ {"Property": "Trigger", "Value": str(schedule["trigger"])}
773
+ )
774
+ if schedule.get("action"):
775
+ details.append({"Property": "Action", "Value": str(schedule["action"])})
776
+
777
+ # Add any remaining properties
778
+ for key, value in schedule.items():
779
+ if (
780
+ key not in property_order + ["trigger", "action"]
781
+ and value is not None
782
+ ):
783
+ details.append(
784
+ {"Property": key.replace("_", " ").title(), "Value": str(value)}
785
+ )
786
+
787
+ return self.format_output(details, format_type, output_file)
788
+ else:
789
+ return self.format_output(schedule, format_type, output_file)
790
+
791
+ def format_schedules_list(
792
+ self,
793
+ schedules: List[Dict[str, Any]],
794
+ format_type: str = "table",
795
+ output_file: Optional[str] = None,
796
+ ) -> Optional[str]:
797
+ """
798
+ Format list of schedules.
799
+
800
+ Args:
801
+ schedules: List of schedule dictionaries
802
+ format_type: Output format
803
+ output_file: Optional output file path
804
+
805
+ Returns:
806
+ Formatted string if no output file specified
807
+ """
808
+ formatted_schedules = []
809
+ for schedule in schedules:
810
+ formatted_schedule = {
811
+ "RID": schedule.get("rid", ""),
812
+ "Name": schedule.get("display_name", ""),
813
+ "Description": schedule.get("description", "")[:50] + "..."
814
+ if schedule.get("description")
815
+ else "",
816
+ "Paused": "Yes" if schedule.get("paused") else "No",
817
+ "Created": self._format_datetime(schedule.get("created_time")),
818
+ }
819
+ formatted_schedules.append(formatted_schedule)
820
+
821
+ return self.format_output(formatted_schedules, format_type, output_file)
822
+
823
+ # MediaSets formatting methods
824
+
825
+ def format_media_item_info(
826
+ self,
827
+ media_item: Dict[str, Any],
828
+ format_type: str = "table",
829
+ output_file: Optional[str] = None,
830
+ ) -> Optional[str]:
831
+ """
832
+ Format media item information for display.
833
+
834
+ Args:
835
+ media_item: Media item information dictionary
836
+ format_type: Output format
837
+ output_file: Optional output file path
838
+
839
+ Returns:
840
+ Formatted string if no output file specified
841
+ """
842
+ if format_type == "table":
843
+ details = []
844
+
845
+ property_order = [
846
+ ("media_item_rid", "Media Item RID"),
847
+ ("filename", "Filename"),
848
+ ("size", "Size"),
849
+ ("content_type", "Content Type"),
850
+ ("created_time", "Created"),
851
+ ("updated_time", "Updated"),
852
+ ]
853
+
854
+ for key, label in property_order:
855
+ if media_item.get(key) is not None:
856
+ value = media_item[key]
857
+ if key in ["created_time", "updated_time"]:
858
+ value = self._format_datetime(value)
859
+ elif key == "size":
860
+ value = self._format_file_size(value)
861
+ details.append({"Property": label, "Value": str(value)})
862
+
863
+ # Add any remaining properties
864
+ for key, value in media_item.items():
865
+ if (
866
+ key not in [prop[0] for prop in property_order]
867
+ and value is not None
868
+ ):
869
+ details.append(
870
+ {"Property": key.replace("_", " ").title(), "Value": str(value)}
871
+ )
872
+
873
+ return self.format_output(details, format_type, output_file)
874
+ else:
875
+ return self.format_output(media_item, format_type, output_file)
876
+
877
+ def format_media_path_lookup(
878
+ self,
879
+ lookup_result: Dict[str, Any],
880
+ format_type: str = "table",
881
+ output_file: Optional[str] = None,
882
+ ) -> Optional[str]:
883
+ """
884
+ Format media path lookup result for display.
885
+
886
+ Args:
887
+ lookup_result: Path lookup result dictionary
888
+ format_type: Output format
889
+ output_file: Optional output file path
890
+
891
+ Returns:
892
+ Formatted string if no output file specified
893
+ """
894
+ if format_type == "table":
895
+ details = [
896
+ {"Property": "Path", "Value": lookup_result.get("path", "")},
897
+ {"Property": "Media Item RID", "Value": lookup_result.get("rid", "")},
898
+ ]
899
+ return self.format_output(details, format_type, output_file)
900
+ else:
901
+ return self.format_output(lookup_result, format_type, output_file)
902
+
903
+ def format_media_reference(
904
+ self,
905
+ reference: Dict[str, Any],
906
+ format_type: str = "table",
907
+ output_file: Optional[str] = None,
908
+ ) -> Optional[str]:
909
+ """
910
+ Format media reference information for display.
911
+
912
+ Args:
913
+ reference: Media reference dictionary
914
+ format_type: Output format
915
+ output_file: Optional output file path
916
+
917
+ Returns:
918
+ Formatted string if no output file specified
919
+ """
920
+ if format_type == "table":
921
+ details = []
922
+
923
+ property_order = [
924
+ ("reference_id", "Reference ID"),
925
+ ("url", "URL"),
926
+ ("expires_at", "Expires At"),
927
+ ]
928
+
929
+ for key, label in property_order:
930
+ if reference.get(key) is not None:
931
+ value = reference[key]
932
+ if key == "expires_at":
933
+ value = self._format_datetime(value)
934
+ details.append({"Property": label, "Value": str(value)})
935
+
936
+ # Add any remaining properties
937
+ for key, value in reference.items():
938
+ if (
939
+ key not in [prop[0] for prop in property_order]
940
+ and value is not None
941
+ ):
942
+ details.append(
943
+ {"Property": key.replace("_", " ").title(), "Value": str(value)}
944
+ )
945
+
946
+ return self.format_output(details, format_type, output_file)
947
+ else:
948
+ return self.format_output(reference, format_type, output_file)
949
+
950
+ # Dataset formatting methods
951
+
952
+ def format_branches(
953
+ self,
954
+ branches: List[Dict[str, Any]],
955
+ format_type: str = "table",
956
+ output_file: Optional[str] = None,
957
+ ) -> Optional[str]:
958
+ """
959
+ Format dataset branches for display.
960
+
961
+ Args:
962
+ branches: List of branch dictionaries
963
+ format_type: Output format
964
+ output_file: Optional output file path
965
+
966
+ Returns:
967
+ Formatted string if no output file specified
968
+ """
969
+ formatted_branches = []
970
+ for branch in branches:
971
+ formatted_branch = {
972
+ "Name": branch.get("name", ""),
973
+ "Transaction": branch.get("transaction_rid", "")[:12] + "..."
974
+ if branch.get("transaction_rid")
975
+ else "",
976
+ "Created": self._format_datetime(branch.get("created_time")),
977
+ "Created By": branch.get("created_by", ""),
978
+ }
979
+ formatted_branches.append(formatted_branch)
980
+
981
+ return self.format_output(formatted_branches, format_type, output_file)
982
+
983
+ def format_branch_detail(
984
+ self,
985
+ branch: Dict[str, Any],
986
+ format_type: str = "table",
987
+ output_file: Optional[str] = None,
988
+ ) -> Optional[str]:
989
+ """
990
+ Format detailed branch information.
991
+
992
+ Args:
993
+ branch: Branch dictionary
994
+ format_type: Output format
995
+ output_file: Optional output file path
996
+
997
+ Returns:
998
+ Formatted string if no output file specified
999
+ """
1000
+ if format_type == "table":
1001
+ details = []
1002
+
1003
+ property_order = [
1004
+ ("name", "Branch Name"),
1005
+ ("dataset_rid", "Dataset RID"),
1006
+ ("parent_branch", "Parent Branch"),
1007
+ ("transaction_rid", "Transaction RID"),
1008
+ ("created_time", "Created"),
1009
+ ("created_by", "Created By"),
1010
+ ]
1011
+
1012
+ for key, label in property_order:
1013
+ if branch.get(key) is not None:
1014
+ value = branch[key]
1015
+ if key == "created_time":
1016
+ value = self._format_datetime(value)
1017
+ details.append({"Property": label, "Value": str(value)})
1018
+
1019
+ # Add any remaining properties
1020
+ for key, value in branch.items():
1021
+ if (
1022
+ key not in [prop[0] for prop in property_order]
1023
+ and value is not None
1024
+ ):
1025
+ details.append(
1026
+ {"Property": key.replace("_", " ").title(), "Value": str(value)}
1027
+ )
1028
+
1029
+ return self.format_output(details, format_type, output_file)
1030
+ else:
1031
+ return self.format_output(branch, format_type, output_file)
1032
+
1033
+ def format_files(
1034
+ self,
1035
+ files: List[Dict[str, Any]],
1036
+ format_type: str = "table",
1037
+ output_file: Optional[str] = None,
1038
+ ) -> Optional[str]:
1039
+ """
1040
+ Format dataset files for display.
1041
+
1042
+ Args:
1043
+ files: List of file dictionaries
1044
+ format_type: Output format
1045
+ output_file: Optional output file path
1046
+
1047
+ Returns:
1048
+ Formatted string if no output file specified
1049
+ """
1050
+ formatted_files = []
1051
+ for file in files:
1052
+ formatted_file = {
1053
+ "Path": file.get("path", ""),
1054
+ "Size": self._format_file_size(file.get("size_bytes")),
1055
+ "Last Modified": self._format_datetime(file.get("last_modified")),
1056
+ "Transaction": file.get("transaction_rid", "")[:12] + "..."
1057
+ if file.get("transaction_rid")
1058
+ else "",
1059
+ }
1060
+ formatted_files.append(formatted_file)
1061
+
1062
+ return self.format_output(formatted_files, format_type, output_file)
1063
+
1064
+ def format_transactions(
1065
+ self,
1066
+ transactions: List[Dict[str, Any]],
1067
+ format_type: str = "table",
1068
+ output_file: Optional[str] = None,
1069
+ ) -> Optional[str]:
1070
+ """
1071
+ Format dataset transactions for display.
1072
+
1073
+ Args:
1074
+ transactions: List of transaction dictionaries
1075
+ format_type: Output format
1076
+ output_file: Optional output file path
1077
+
1078
+ Returns:
1079
+ Formatted string if no output file specified
1080
+ """
1081
+ formatted_transactions = []
1082
+ for transaction in transactions:
1083
+ formatted_transaction = {
1084
+ "Transaction RID": transaction.get("transaction_rid", "")[:12] + "..."
1085
+ if transaction.get("transaction_rid")
1086
+ else "",
1087
+ "Status": transaction.get("status", ""),
1088
+ "Type": transaction.get("transaction_type", ""),
1089
+ "Branch": transaction.get("branch", ""),
1090
+ "Created": self._format_datetime(transaction.get("created_time")),
1091
+ "Created By": transaction.get("created_by", ""),
1092
+ }
1093
+ formatted_transactions.append(formatted_transaction)
1094
+
1095
+ return self.format_output(formatted_transactions, format_type, output_file)
1096
+
1097
+ def format_transaction_detail(
1098
+ self,
1099
+ transaction: Dict[str, Any],
1100
+ format_type: str = "table",
1101
+ output_file: Optional[str] = None,
1102
+ ) -> Optional[str]:
1103
+ """
1104
+ Format detailed transaction information.
1105
+
1106
+ Args:
1107
+ transaction: Transaction dictionary
1108
+ format_type: Output format
1109
+ output_file: Optional output file path
1110
+
1111
+ Returns:
1112
+ Formatted string if no output file specified
1113
+ """
1114
+ if format_type == "table":
1115
+ details = []
1116
+
1117
+ property_order = [
1118
+ ("transaction_rid", "Transaction RID"),
1119
+ ("dataset_rid", "Dataset RID"),
1120
+ ("status", "Status"),
1121
+ ("transaction_type", "Type"),
1122
+ ("branch", "Branch"),
1123
+ ("created_time", "Created"),
1124
+ ("created_by", "Created By"),
1125
+ ("committed_time", "Committed"),
1126
+ ("aborted_time", "Aborted"),
1127
+ ]
1128
+
1129
+ for key, label in property_order:
1130
+ if transaction.get(key) is not None:
1131
+ value = transaction[key]
1132
+ if "time" in key:
1133
+ value = self._format_datetime(value)
1134
+ details.append({"Property": label, "Value": str(value)})
1135
+
1136
+ # Add any remaining properties
1137
+ for key, value in transaction.items():
1138
+ if (
1139
+ key not in [prop[0] for prop in property_order]
1140
+ and value is not None
1141
+ ):
1142
+ details.append(
1143
+ {"Property": key.replace("_", " ").title(), "Value": str(value)}
1144
+ )
1145
+
1146
+ return self.format_output(details, format_type, output_file)
1147
+ else:
1148
+ return self.format_output(transaction, format_type, output_file)
1149
+
1150
+ def format_transaction_result(
1151
+ self,
1152
+ result: Dict[str, Any],
1153
+ format_type: str = "table",
1154
+ output_file: Optional[str] = None,
1155
+ ) -> Optional[str]:
1156
+ """
1157
+ Format transaction operation result.
1158
+
1159
+ Args:
1160
+ result: Transaction operation result dictionary
1161
+ format_type: Output format
1162
+ output_file: Optional output file path
1163
+
1164
+ Returns:
1165
+ Formatted string if no output file specified
1166
+ """
1167
+ if format_type == "table":
1168
+ details = []
1169
+
1170
+ property_order = [
1171
+ ("transaction_rid", "Transaction RID"),
1172
+ ("dataset_rid", "Dataset RID"),
1173
+ ("status", "Status"),
1174
+ ("success", "Success"),
1175
+ ("committed_time", "Committed Time"),
1176
+ ("aborted_time", "Aborted Time"),
1177
+ ]
1178
+
1179
+ for key, label in property_order:
1180
+ if result.get(key) is not None:
1181
+ value = result[key]
1182
+ if "time" in key:
1183
+ value = self._format_datetime(value)
1184
+ elif key == "success":
1185
+ value = "Yes" if value else "No"
1186
+ details.append({"Property": label, "Value": str(value)})
1187
+
1188
+ # Add any remaining properties
1189
+ for key, value in result.items():
1190
+ if (
1191
+ key not in [prop[0] for prop in property_order]
1192
+ and value is not None
1193
+ ):
1194
+ details.append(
1195
+ {"Property": key.replace("_", " ").title(), "Value": str(value)}
1196
+ )
1197
+
1198
+ return self.format_output(details, format_type, output_file)
1199
+ else:
1200
+ return self.format_output(result, format_type, output_file)
1201
+
1202
+ def format_views(
1203
+ self,
1204
+ views: List[Dict[str, Any]],
1205
+ format_type: str = "table",
1206
+ output_file: Optional[str] = None,
1207
+ ) -> Optional[str]:
1208
+ """
1209
+ Format dataset views for display.
1210
+
1211
+ Args:
1212
+ views: List of view dictionaries
1213
+ format_type: Output format
1214
+ output_file: Optional output file path
1215
+
1216
+ Returns:
1217
+ Formatted string if no output file specified
1218
+ """
1219
+ formatted_views = []
1220
+ for view in views:
1221
+ formatted_view = {
1222
+ "View RID": view.get("view_rid", "")[:12] + "..."
1223
+ if view.get("view_rid")
1224
+ else "",
1225
+ "Name": view.get("name", ""),
1226
+ "Description": view.get("description", "")[:50] + "..."
1227
+ if view.get("description", "")
1228
+ else "",
1229
+ "Created": self._format_datetime(view.get("created_time")),
1230
+ "Created By": view.get("created_by", ""),
1231
+ }
1232
+ formatted_views.append(formatted_view)
1233
+
1234
+ return self.format_output(formatted_views, format_type, output_file)
1235
+
1236
+ def format_view_detail(
1237
+ self,
1238
+ view: Dict[str, Any],
1239
+ format_type: str = "table",
1240
+ output_file: Optional[str] = None,
1241
+ ) -> Optional[str]:
1242
+ """
1243
+ Format detailed view information.
1244
+
1245
+ Args:
1246
+ view: View dictionary
1247
+ format_type: Output format
1248
+ output_file: Optional output file path
1249
+
1250
+ Returns:
1251
+ Formatted string if no output file specified
1252
+ """
1253
+ if format_type == "table":
1254
+ details = []
1255
+
1256
+ property_order = [
1257
+ ("view_rid", "View RID"),
1258
+ ("name", "Name"),
1259
+ ("description", "Description"),
1260
+ ("dataset_rid", "Dataset RID"),
1261
+ ("created_time", "Created"),
1262
+ ("created_by", "Created By"),
1263
+ ]
1264
+
1265
+ for key, label in property_order:
1266
+ if view.get(key) is not None:
1267
+ value = view[key]
1268
+ if key == "created_time":
1269
+ value = self._format_datetime(value)
1270
+ details.append({"Property": label, "Value": str(value)})
1271
+
1272
+ # Add any remaining properties
1273
+ for key, value in view.items():
1274
+ if (
1275
+ key not in [prop[0] for prop in property_order]
1276
+ and value is not None
1277
+ ):
1278
+ details.append(
1279
+ {"Property": key.replace("_", " ").title(), "Value": str(value)}
1280
+ )
1281
+
1282
+ return self.format_output(details, format_type, output_file)
1283
+ else:
1284
+ return self.format_output(view, format_type, output_file)