|
22 | 22 |
|
23 | 23 | """Identifier Service Class""" |
24 | 24 |
|
| 25 | +import json |
| 26 | + |
25 | 27 | SERVER_VERSION = "version" |
26 | 28 | BUILD_TIME = "buildTime" |
27 | 29 | OS_NAME = "os" |
@@ -113,8 +115,26 @@ def __init__(self, params): |
113 | 115 | else: |
114 | 116 | self.tsp_version = None |
115 | 117 |
|
116 | | - def to_string(self): |
117 | | - ''' |
118 | | - to_string method |
119 | | - ''' |
120 | | - return f"Identifier[version={self.server_version}, buildTime={self.build_time}, os={self.os_name}, osArch={self.os_arch}, osVersion={self.os_version}, cpuCount={self.cpu_count}, maxMemory={self.max_memory}, productId={self.product_id}, launcherName={self.launcher_name}, tspVersion={self.tsp_version}]" |
| 118 | + def __repr__(self): |
| 119 | + return f'Identifier(version={self.server_version}, build_time={self.build_time}, os={self.os_name}, os_arch={self.os_arch}, os_version={self.os_version}, cpu_count={self.cpu_count}, max_memory={self.max_memory}, product_id={self.product_id}, launcher_name={self.launcher_name}, tsp_version={self.tsp_version})' |
| 120 | + |
| 121 | + def to_json(self): |
| 122 | + return json.dumps(self, cls=IdentifierEncoder, indent=4) |
| 123 | + |
| 124 | + |
| 125 | +class IdentifierEncoder(json.JSONEncoder): |
| 126 | + def default(self, obj): |
| 127 | + if isinstance(obj, Identifier): |
| 128 | + return { |
| 129 | + SERVER_VERSION: obj.server_version, |
| 130 | + BUILD_TIME: obj.build_time, |
| 131 | + OS_NAME: obj.os_name, |
| 132 | + OS_ARCH: obj.os_arch, |
| 133 | + OS_VERSION: obj.os_version, |
| 134 | + CPU_COUNT: obj.cpu_count, |
| 135 | + MAX_MEMORY: obj.max_memory, |
| 136 | + PRODUCT_ID: obj.product_id, |
| 137 | + LAUNCHER_NAME: obj.launcher_name, |
| 138 | + TSP_VERSION: obj.tsp_version |
| 139 | + } |
| 140 | + return super().default(obj) |
0 commit comments