psytricks 2.2.0a8__tar.gz → 2.2.0a10__tar.gz

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.

Potentially problematic release.


This version of psytricks might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: psytricks
3
- Version: 2.2.0a8
3
+ Version: 2.2.0a10
4
4
  Summary: PowerShell Python Citrix Tricks.
5
5
  License-Expression: GPL-3.0-or-later
6
6
  License-File: LICENSE
@@ -7,7 +7,7 @@ authors = [
7
7
  license = "GPL-3.0-or-later"
8
8
  readme = "README.md"
9
9
  dynamic = []
10
- version = "2.2.0-a.8"
10
+ version = "2.2.0-a.10"
11
11
 
12
12
  [tool.poetry]
13
13
  documentation = "https://imcf.one/apidocs/psytricks/psytricks.html"
@@ -3,7 +3,7 @@
3
3
  .. include:: ../../CHANGELOG.md
4
4
  """
5
5
 
6
- __version__ = "2.2.0-a.8"
6
+ __version__ = "2.2.0-a.10"
7
7
 
8
8
  # style exceptions for pdoc-include-only docstrings:
9
9
  # ruff: noqa: D400 (missing-trailing-period)
@@ -5,7 +5,7 @@ Collection of functions and other definitions to be sourced by other scripts.
5
5
  #>
6
6
 
7
7
  # the version variable will be filled by poetry at build time:
8
- $Version = "2.2.0-a.8"
8
+ $Version = "2.2.0-a.10"
9
9
 
10
10
 
11
11
  #region properties-selectors
@@ -18,7 +18,7 @@ from .literals import Action, RequestName, MsgStyle
18
18
 
19
19
 
20
20
  class ResTricksWrapper:
21
- """Wrapper performing REST requests and processing the responses.
21
+ """Perform requests to a ResTricks service and process the responses.
22
22
 
23
23
  Parameters
24
24
  ----------
@@ -91,7 +91,7 @@ class ResTricksWrapper:
91
91
  log.debug(f"{verb} 'read-only' mode.")
92
92
  self._read_only = value
93
93
 
94
- def connect(self):
94
+ def connect(self) -> None:
95
95
  """Connect to the ResTricks service unless already connected.
96
96
 
97
97
  Raises
@@ -127,7 +127,7 @@ class ResTricksWrapper:
127
127
  f"Connecting to {self.base_url} failed: {ex}"
128
128
  ) from ex
129
129
 
130
- def validate_version(self, server_ver):
130
+ def validate_version(self, server_ver) -> bool:
131
131
  """Validate the server version against the local module.
132
132
 
133
133
  Parse the version strings of the local module and the server response
@@ -187,7 +187,7 @@ class ResTricksWrapper:
187
187
  return False
188
188
 
189
189
  @staticmethod
190
- def _check_response(response):
190
+ def _check_response(response) -> None:
191
191
  """Check the HTTP response code and JSON status attributes."""
192
192
  if response.status_code == 200:
193
193
  return
@@ -209,7 +209,9 @@ class ResTricksWrapper:
209
209
  log.warning(response.text)
210
210
  raise ValueError(f"Malformed response: {response.text}") from ex
211
211
 
212
- def send_get_request(self, raw_url: str, auto_conn: bool = True):
212
+ def send_get_request(
213
+ self, raw_url: str, auto_conn: bool = True
214
+ ) -> list[dict] | dict | None:
213
215
  """Perform a `GET` request and process the response.
214
216
 
215
217
  Parameters
@@ -260,7 +262,9 @@ class ResTricksWrapper:
260
262
 
261
263
  return data
262
264
 
263
- def send_post_request(self, raw_url: str, payload: dict, no_json: bool = False):
265
+ def send_post_request(
266
+ self, raw_url: str, payload: dict, no_json: bool = False
267
+ ) -> list[dict] | dict | None:
264
268
  """Perform a `POST` request and process the response.
265
269
 
266
270
  The response will be checked for a valid HTTP status code and will be
@@ -329,7 +333,23 @@ class ResTricksWrapper:
329
333
  Returns
330
334
  -------
331
335
  list(dict)
332
- The `Data` dicts parsed from the JSON returned by the REST service.
336
+ The `Data` dicts parsed from the JSON returned by the REST service
337
+ with the current machine state details. Each dict is expected to
338
+ contain the following keys:
339
+ - `AgentVersion`
340
+ - `AssociatedUserUPNs`
341
+ - `DesktopGroupName`
342
+ - `DNSName`
343
+ - `HostedDNSName`
344
+ - `InMaintenanceMode`
345
+ - `PowerState`
346
+ - `RegistrationState`
347
+ - `SessionClientVersion`
348
+ - `SessionDeviceId`
349
+ - `SessionStartTime`
350
+ - `SessionStateChangeTime`
351
+ - `SessionUserName`
352
+ - `SummaryState`
333
353
  """
334
354
  log.debug("Requesting current status of machines...")
335
355
  return self.send_get_request("GetMachineStatus")["Data"]
@@ -341,28 +361,28 @@ class ResTricksWrapper:
341
361
  -------
342
362
  list(dict)
343
363
  The `Data` dicts parsed from the JSON returned by the REST service,
344
- containing details about the currently existing sessions.
364
+ containing details about the currently existing sessions. Each dict
365
+ is expected to contain the following keys:
366
+ - `ClientAddress`
367
+ - `ClientName`
368
+ - `ClientPlatform`
369
+ - `ClientProductId`
370
+ - `ClientVersion`
371
+ - `ConnectedViaHostName`
372
+ - `DesktopGroupName`
373
+ - `DNSName`
374
+ - `MachineSummaryState`
375
+ - `Protocol`
376
+ - `SessionState`
377
+ - `SessionStateChangeTime`
378
+ - `StartTime`
379
+ - `Uid`
380
+ - `UserName`
381
+ - `UserUPN`
345
382
  """
346
383
  log.debug("Requesting current sessions...")
347
384
  return self.send_get_request("GetSessions")["Data"]
348
385
 
349
- def get_access_users(self, group: str) -> list:
350
- """Send a `GET` request with `GetAccessUsers`.
351
-
352
- Parameters
353
- ----------
354
- group : str
355
- The name of the Delivery Group to request users having access.
356
-
357
- Returns
358
- -------
359
- list(dict)
360
- The `Data` dicts parsed from the JSON returned by the REST service,
361
- containing the user objects having access to the given group.
362
- """
363
- log.debug(f"Requesting users having access to group [{group}]...")
364
- return self.send_get_request(f"GetAccessUsers/{group}")["Data"]
365
-
366
386
  def disconnect_session(self, machine: str) -> dict:
367
387
  """Send a `POST` request with `DisconnectSession`.
368
388
 
@@ -379,7 +399,24 @@ class ResTricksWrapper:
379
399
  contains an empty `Data` object, an empty dict will be returned.
380
400
  Please note that sending a disconnect request for a session that is
381
401
  already disconnected will not change the session state but still
382
- return the session details.
402
+ return the session details. The dict is expected to contain the
403
+ following keys:
404
+ - `ClientAddress`
405
+ - `ClientName`
406
+ - `ClientPlatform`
407
+ - `ClientProductId`
408
+ - `ClientVersion`
409
+ - `ConnectedViaHostName`
410
+ - `DesktopGroupName`
411
+ - `DNSName`
412
+ - `MachineSummaryState`
413
+ - `Protocol`
414
+ - `SessionState`
415
+ - `SessionStateChangeTime`
416
+ - `StartTime`
417
+ - `Uid`
418
+ - `UserName`
419
+ - `UserUPN`
383
420
  """
384
421
  log.debug(f"Requesting session on [{machine}] to be disconnected...")
385
422
  payload = {"DNSName": machine}
@@ -390,6 +427,34 @@ class ResTricksWrapper:
390
427
 
391
428
  return session
392
429
 
430
+ def get_access_users(self, group: str) -> list:
431
+ """Send a `GET` request with `GetAccessUsers`.
432
+
433
+ Parameters
434
+ ----------
435
+ group : str
436
+ The name of the Delivery Group to request users having access.
437
+
438
+ Returns
439
+ -------
440
+ list(dict)
441
+ The `Data` dicts parsed from the JSON returned by the REST service,
442
+ containing details on the user objects having access to the given
443
+ Delivery Group. Each dict is expected to contain the following keys:
444
+ - `DirectoryContext`
445
+ - `FullName`
446
+ - `HomeZoneName`
447
+ - `HomeZoneUid`
448
+ - `IdentityClaims`
449
+ - `Name`
450
+ - `NameLookupFailureCount`
451
+ - `PrimaryClaim`
452
+ - `SID`
453
+ - `UPN`
454
+ """
455
+ log.debug(f"Requesting users having access to group [{group}]...")
456
+ return self.send_get_request(f"GetAccessUsers/{group}")["Data"]
457
+
393
458
  def set_access_users(self, group: str, users: str, disable: bool) -> list:
394
459
  """Send a `POST` request with `SetAccessUsers`.
395
460
 
@@ -409,8 +474,19 @@ class ResTricksWrapper:
409
474
  -------
410
475
  list(dict)
411
476
  The `Data` dicts parsed from the JSON returned by the REST service,
412
- containing the user objects having access to the given group *after*
413
- the operation has been performed.
477
+ containing the user objects having access to the given Delivery
478
+ Group *after* the operation has been performed. Each dict is
479
+ expected to contain the following keys:
480
+ - `DirectoryContext`
481
+ - `FullName`
482
+ - `HomeZoneName`
483
+ - `HomeZoneUid`
484
+ - `IdentityClaims`
485
+ - `Name`
486
+ - `NameLookupFailureCount`
487
+ - `PrimaryClaim`
488
+ - `SID`
489
+ - `UPN`
414
490
  """
415
491
  verb = "Removing" if disable else "Adding"
416
492
  log.debug(f"{verb} access to group [{group}] for user(s) [{users}]...")
@@ -436,6 +512,21 @@ class ResTricksWrapper:
436
512
  -------
437
513
  dict
438
514
  The `Data` dict parsed from the JSON returned by the REST service.
515
+ It is expected to contain the following keys:
516
+ - `AgentVersion`
517
+ - `AssociatedUserUPNs`
518
+ - `DesktopGroupName`
519
+ - `DNSName`
520
+ - `HostedDNSName`
521
+ - `InMaintenanceMode`
522
+ - `PowerState`
523
+ - `RegistrationState`
524
+ - `SessionClientVersion`
525
+ - `SessionDeviceId`
526
+ - `SessionStartTime`
527
+ - `SessionStateChangeTime`
528
+ - `SessionUserName`
529
+ - `SummaryState`
439
530
  """
440
531
  verb = "Disabling" if disable else "Enabling"
441
532
  log.debug(f"{verb} maintenance mode on [{machine}]...")
@@ -445,7 +536,9 @@ class ResTricksWrapper:
445
536
  }
446
537
  return self.send_post_request("SetMaintenanceMode", payload)["Data"]
447
538
 
448
- def send_message(self, machine: str, message: str, title: str, style: MsgStyle):
539
+ def send_message(
540
+ self, machine: str, message: str, title: str, style: MsgStyle
541
+ ) -> None:
449
542
  """Send a `POST` request with `SendSessionMessage`.
450
543
 
451
544
  Parameters
@@ -483,7 +576,26 @@ class ResTricksWrapper:
483
576
  -------
484
577
  dict
485
578
  The `Data` dict parsed from the JSON returned by the REST service
486
- containing details on the power action status of the machine.
579
+ containing details on the power action status of the machine. The
580
+ dict is expected to contain the following keys:
581
+ - `Action`
582
+ - `ActionCompletionTime`
583
+ - `ActionStartTime`
584
+ - `ActualPriority`
585
+ - `BasePriority`
586
+ - `DNSName`
587
+ - `FailureReason`
588
+ - `HostedMachineId`
589
+ - `HostedMachineName`
590
+ - `HypHypervisorConnectionUid`
591
+ - `HypervisorConnectionUid`
592
+ - `MachineName`
593
+ - `MetadataMap`
594
+ - `Origin`
595
+ - `RequestTime`
596
+ - `Sid`
597
+ - `State`
598
+ - `Uid`
487
599
  """
488
600
  log.debug(f"Requesting action [{action}] for machine [{machine}]...")
489
601
  payload = {
@@ -547,7 +659,9 @@ class PSyTricksWrapper:
547
659
  log.debug(f"Using PowerShell script [{self.pswrapper}].")
548
660
  log.debug(f"Using Delivery Controller [{self.deliverycontroller}].")
549
661
 
550
- def run_ps1_script(self, request: RequestName, extra_params: list = None) -> list:
662
+ def run_ps1_script(
663
+ self, request: RequestName, extra_params: (list | None) = None
664
+ ) -> list[dict] | dict | None:
551
665
  """Call the PowerShell wrapper to retrieve information from Citrix.
552
666
 
553
667
  Parameters
@@ -560,9 +674,10 @@ class PSyTricksWrapper:
560
674
 
561
675
  Returns
562
676
  -------
563
- list(str)
677
+ list(dict) or dict or None
564
678
  The "Data" section of the JSON parsed from the output returned by
565
- the PS1 wrapper script.
679
+ the PS1 wrapper script. Depending on the command, this can be a list
680
+ of dicts or a single dict or None.
566
681
 
567
682
  Raises
568
683
  ------
@@ -612,6 +727,7 @@ class PSyTricksWrapper:
612
727
  f"Call returned a non-zero state: {ex.returncode} {ex.stderr}"
613
728
  ) from ex
614
729
 
730
+ stdout = "PRE-DECODING-DUMMY-VALUE"
615
731
  try:
616
732
  tstart = time.time()
617
733
  stdout = completed.stdout.decode(encoding="cp850")
@@ -650,8 +766,23 @@ class PSyTricksWrapper:
650
766
 
651
767
  Returns
652
768
  -------
653
- list(str)
654
- The parsed JSON.
769
+ list(dict)
770
+ A list of dicts with the current machine state details. Each dict is
771
+ expected to contain the following keys:
772
+ - `AgentVersion`
773
+ - `AssociatedUserUPNs`
774
+ - `DesktopGroupName`
775
+ - `DNSName`
776
+ - `HostedDNSName`
777
+ - `InMaintenanceMode`
778
+ - `PowerState`
779
+ - `RegistrationState`
780
+ - `SessionClientVersion`
781
+ - `SessionDeviceId`
782
+ - `SessionStartTime`
783
+ - `SessionStateChangeTime`
784
+ - `SessionUserName`
785
+ - `SummaryState`
655
786
  """
656
787
  return self.run_ps1_script(request="GetMachineStatus")
657
788
 
@@ -660,12 +791,29 @@ class PSyTricksWrapper:
660
791
 
661
792
  Returns
662
793
  -------
663
- list(str)
664
- The parsed JSON.
794
+ list(dict)
795
+ A list of dicts with the current session details. Each dict is
796
+ expected to contain the following keys:
797
+ - `ClientAddress`
798
+ - `ClientName`
799
+ - `ClientPlatform`
800
+ - `ClientProductId`
801
+ - `ClientVersion`
802
+ - `ConnectedViaHostName`
803
+ - `DesktopGroupName`
804
+ - `DNSName`
805
+ - `MachineSummaryState`
806
+ - `Protocol`
807
+ - `SessionState`
808
+ - `SessionStateChangeTime`
809
+ - `StartTime`
810
+ - `Uid`
811
+ - `UserName`
812
+ - `UserUPN`
665
813
  """
666
814
  return self.run_ps1_script(request="GetSessions")
667
815
 
668
- def disconnect_session(self, machine: str) -> list:
816
+ def disconnect_session(self, machine: str) -> dict:
669
817
  """Call the wrapper with command `DisconnectSession`.
670
818
 
671
819
  Parameters
@@ -675,8 +823,26 @@ class PSyTricksWrapper:
675
823
 
676
824
  Returns
677
825
  -------
678
- list(str)
679
- The parsed JSON as returned by the wrapper script.
826
+ dict
827
+ A dict with the details on the session that was requested to be
828
+ disconnected. The dict is expected to contain the following keys:
829
+ - `ClientAddress`
830
+ - `ClientName`
831
+ - `ClientPlatform`
832
+ - `ClientProductId`
833
+ - `ClientVersion`
834
+ - `ConnectedViaHostName`
835
+ - `DesktopGroupName`
836
+ - `DNSName`
837
+ - `MachineSummaryState`
838
+ - `Protocol`
839
+ - `SessionState`
840
+ - `SessionStateChangeTime`
841
+ - `StartTime`
842
+ - `Uid`
843
+ - `UserName`
844
+ - `UserUPN`
845
+
680
846
  """
681
847
  return self.run_ps1_script(
682
848
  request="DisconnectSession",
@@ -693,8 +859,20 @@ class PSyTricksWrapper:
693
859
 
694
860
  Returns
695
861
  -------
696
- list(str)
697
- The parsed JSON as returned by the wrapper script.
862
+ list(dict)
863
+ A list of dicts with the details on the user objects having access
864
+ to the given Delivery Group. Each dict is expected to contain the
865
+ following keys:
866
+ - `DirectoryContext`
867
+ - `FullName`
868
+ - `HomeZoneName`
869
+ - `HomeZoneUid`
870
+ - `IdentityClaims`
871
+ - `Name`
872
+ - `NameLookupFailureCount`
873
+ - `PrimaryClaim`
874
+ - `SID`
875
+ - `UPN`
698
876
  """
699
877
  return self.run_ps1_script(
700
878
  request="GetAccessUsers",
@@ -717,8 +895,20 @@ class PSyTricksWrapper:
717
895
 
718
896
  Returns
719
897
  -------
720
- list(str)
721
- The parsed JSON as returned by the wrapper script.
898
+ list(dict)
899
+ A list of dicts with the details on the user objects having access
900
+ to the given Delivery Group *after* the operation has been
901
+ performed. Each dict is expected to contain the following keys:
902
+ - `DirectoryContext`
903
+ - `FullName`
904
+ - `HomeZoneName`
905
+ - `HomeZoneUid`
906
+ - `IdentityClaims`
907
+ - `Name`
908
+ - `NameLookupFailureCount`
909
+ - `PrimaryClaim`
910
+ - `SID`
911
+ - `UPN`
722
912
  """
723
913
  extra_params = [
724
914
  "-Group",
@@ -731,7 +921,7 @@ class PSyTricksWrapper:
731
921
 
732
922
  return self.run_ps1_script(request="SetAccessUsers", extra_params=extra_params)
733
923
 
734
- def set_maintenance(self, machine: str, disable: bool) -> list:
924
+ def set_maintenance(self, machine: str, disable: bool) -> dict:
735
925
  """Call the wrapper with command `SetMaintenanceMode`.
736
926
 
737
927
  Parameters
@@ -744,8 +934,23 @@ class PSyTricksWrapper:
744
934
 
745
935
  Returns
746
936
  -------
747
- list(str)
748
- The parsed JSON as returned by the wrapper script.
937
+ dict
938
+ A dict created from the parsed JSON as returned by the wrapper
939
+ script. The dict is expected to contain the following keys:
940
+ - `AgentVersion`
941
+ - `AssociatedUserUPNs`
942
+ - `DesktopGroupName`
943
+ - `DNSName`
944
+ - `HostedDNSName`
945
+ - `InMaintenanceMode`
946
+ - `PowerState`
947
+ - `RegistrationState`
948
+ - `SessionClientVersion`
949
+ - `SessionDeviceId`
950
+ - `SessionStartTime`
951
+ - `SessionStateChangeTime`
952
+ - `SessionUserName`
953
+ - `SummaryState`
749
954
  """
750
955
  extra_params = ["-DNSName", machine]
751
956
  if disable:
@@ -755,7 +960,9 @@ class PSyTricksWrapper:
755
960
  request="SetMaintenanceMode", extra_params=extra_params
756
961
  )
757
962
 
758
- def send_message(self, machine: str, message: str, title: str, style: MsgStyle):
963
+ def send_message(
964
+ self, machine: str, message: str, title: str, style: MsgStyle
965
+ ) -> None:
759
966
  """Call the wrapper with command `SendSessionMessage`.
760
967
 
761
968
  Parameters
@@ -783,7 +990,7 @@ class PSyTricksWrapper:
783
990
 
784
991
  self.run_ps1_script(request="SendSessionMessage", extra_params=extra_params)
785
992
 
786
- def perform_poweraction(self, machine: str, action: Action) -> None:
993
+ def perform_poweraction(self, machine: str, action: Action) -> dict:
787
994
  """Call the wrapper with command `MachinePowerAction`.
788
995
 
789
996
  Parameters
@@ -792,6 +999,31 @@ class PSyTricksWrapper:
792
999
  The FQDN of the machine to disconnect the session on.
793
1000
  action : str
794
1001
  The power action to perform, one of `psytricks.literals.Action`.
1002
+
1003
+ Returns
1004
+ -------
1005
+ dict
1006
+ The `Data` dict parsed from the JSON returned by the wrapper script,
1007
+ containing details on the power action status of the machine. The
1008
+ dict is expected to contain the following keys:
1009
+ - `Action`
1010
+ - `ActionCompletionTime`
1011
+ - `ActionStartTime`
1012
+ - `ActualPriority`
1013
+ - `BasePriority`
1014
+ - `DNSName`
1015
+ - `FailureReason`
1016
+ - `HostedMachineId`
1017
+ - `HostedMachineName`
1018
+ - `HypHypervisorConnectionUid`
1019
+ - `HypervisorConnectionUid`
1020
+ - `MachineName`
1021
+ - `MetadataMap`
1022
+ - `Origin`
1023
+ - `RequestTime`
1024
+ - `Sid`
1025
+ - `State`
1026
+ - `Uid`
795
1027
  """
796
1028
  extra_params = ["-DNSName", machine, "-Action", action]
797
1029
  return self.run_ps1_script(
File without changes
File without changes