9
9
import traceback
10
10
from concurrent .futures import ThreadPoolExecutor , as_completed
11
11
from datetime import datetime , timedelta
12
- from typing import Iterator , Literal , Optional , Sequence , cast
12
+ from typing import Iterator , Literal , Optional , Sequence , cast , Union
13
13
14
14
import semver
15
15
16
- from .api import RSConnectClient , RSConnectServer , emit_task_log
16
+ from .api import RSConnectServer , SPCSConnectServer , RSConnectClient , emit_task_log
17
17
from .exception import RSConnectException
18
18
from .log import logger
19
19
from .metadata import ContentBuildStore , ContentItemWithBuildState
@@ -33,7 +33,7 @@ def content_build_store() -> ContentBuildStore:
33
33
return _content_build_store
34
34
35
35
36
- def ensure_content_build_store (connect_server : RSConnectServer ) -> ContentBuildStore :
36
+ def ensure_content_build_store (connect_server : Union [ RSConnectServer , SPCSConnectServer ] ) -> ContentBuildStore :
37
37
global _content_build_store
38
38
if not _content_build_store :
39
39
logger .info ("Initializing ContentBuildStore for %s" % connect_server .url )
@@ -42,7 +42,7 @@ def ensure_content_build_store(connect_server: RSConnectServer) -> ContentBuildS
42
42
43
43
44
44
def build_add_content (
45
- connect_server : RSConnectServer ,
45
+ connect_server : Union [ RSConnectServer , SPCSConnectServer ] ,
46
46
content_guids_with_bundle : Sequence [ContentGuidWithBundle ],
47
47
):
48
48
"""
@@ -85,7 +85,7 @@ def _validate_build_rm_args(guid: Optional[str], all: bool, purge: bool):
85
85
86
86
87
87
def build_remove_content (
88
- connect_server : RSConnectServer ,
88
+ connect_server : Union [ RSConnectServer , SPCSConnectServer ] ,
89
89
guid : Optional [str ],
90
90
all : bool ,
91
91
purge : bool ,
@@ -109,20 +109,20 @@ def build_remove_content(
109
109
return guids
110
110
111
111
112
- def build_list_content (connect_server : RSConnectServer , guid : str , status : Optional [str ]):
112
+ def build_list_content (connect_server : Union [ RSConnectServer , SPCSConnectServer ] , guid : str , status : Optional [str ]):
113
113
build_store = ensure_content_build_store (connect_server )
114
114
if guid :
115
115
return [build_store .get_content_item (g ) for g in guid ]
116
116
else :
117
117
return build_store .get_content_items (status = status )
118
118
119
119
120
- def build_history (connect_server : RSConnectServer , guid : str ):
120
+ def build_history (connect_server : Union [ RSConnectServer , SPCSConnectServer ] , guid : str ):
121
121
return ensure_content_build_store (connect_server ).get_build_history (guid )
122
122
123
123
124
124
def build_start (
125
- connect_server : RSConnectServer ,
125
+ connect_server : Union [ RSConnectServer , SPCSConnectServer ] ,
126
126
parallelism : int ,
127
127
aborted : bool = False ,
128
128
error : bool = False ,
@@ -251,7 +251,9 @@ def build_start(
251
251
build_monitor .shutdown ()
252
252
253
253
254
- def _monitor_build (connect_server : RSConnectServer , content_items : list [ContentItemWithBuildState ]):
254
+ def _monitor_build (
255
+ connect_server : Union [RSConnectServer , SPCSConnectServer ], content_items : list [ContentItemWithBuildState ]
256
+ ):
255
257
"""
256
258
:return bool: True if the build completed without errors, False otherwise
257
259
"""
@@ -296,7 +298,9 @@ def _monitor_build(connect_server: RSConnectServer, content_items: list[ContentI
296
298
return True
297
299
298
300
299
- def _build_content_item (connect_server : RSConnectServer , content : ContentItemWithBuildState , poll_wait : int ):
301
+ def _build_content_item (
302
+ connect_server : Union [RSConnectServer , SPCSConnectServer ], content : ContentItemWithBuildState , poll_wait : int
303
+ ):
300
304
build_store = ensure_content_build_store (connect_server )
301
305
with RSConnectClient (connect_server ) as client :
302
306
# Pending futures will still try to execute when ThreadPoolExecutor.shutdown() is called
@@ -351,7 +355,7 @@ def write_log(line: str):
351
355
352
356
353
357
def emit_build_log (
354
- connect_server : RSConnectServer ,
358
+ connect_server : Union [ RSConnectServer , SPCSConnectServer ] ,
355
359
guid : str ,
356
360
format : str ,
357
361
task_id : Optional [str ] = None ,
@@ -369,7 +373,7 @@ def emit_build_log(
369
373
raise RSConnectException ("Log file not found for content: %s" % guid )
370
374
371
375
372
- def download_bundle (connect_server : RSConnectServer , guid_with_bundle : ContentGuidWithBundle ):
376
+ def download_bundle (connect_server : Union [ RSConnectServer , SPCSConnectServer ] , guid_with_bundle : ContentGuidWithBundle ):
373
377
"""
374
378
:param guid_with_bundle: models.ContentGuidWithBundle
375
379
"""
@@ -387,7 +391,7 @@ def download_bundle(connect_server: RSConnectServer, guid_with_bundle: ContentGu
387
391
return client .download_bundle (guid_with_bundle .guid , guid_with_bundle .bundle_id )
388
392
389
393
390
- def get_content (connect_server : RSConnectServer , guid : str | list [str ]):
394
+ def get_content (connect_server : Union [ RSConnectServer , SPCSConnectServer ] , guid : str | list [str ]):
391
395
"""
392
396
:param guid: a single guid as a string or list of guids.
393
397
:return: a list of content items.
@@ -401,7 +405,7 @@ def get_content(connect_server: RSConnectServer, guid: str | list[str]):
401
405
402
406
403
407
def search_content (
404
- connect_server : RSConnectServer ,
408
+ connect_server : Union [ RSConnectServer , SPCSConnectServer ] ,
405
409
published : bool ,
406
410
unpublished : bool ,
407
411
content_type : Sequence [str ],
0 commit comments