@@ -67,28 +67,40 @@ async def unpublish(obj: ServiceRegistry, record_id):
6767 await _change_publish_flag (obj , record_id , model .RecordingState .UNPUBLISHED )
6868
6969
70- async def _change_publish_flag (obj : ServiceRegistry , record_id , state :model .RecordingState ):
70+ async def _change_publish_flag (
71+ obj : ServiceRegistry , record_id , state : model .RecordingState
72+ ):
7173 importer = await obj .use ("importer" , RecordingManager )
7274 db = await obj .use ("db" , DBContext )
7375
7476 async with db .session () as session :
75- stmt = model .Recording .select (model .Recording .record_id .in_ (record_id ), model .Recording .state != state ).options (sqlalchemy .orm .joinedload (model .Recording .tenant ))
77+ stmt = model .Recording .select (
78+ model .Recording .record_id .in_ (record_id ), model .Recording .state != state
79+ ).options (sqlalchemy .orm .joinedload (model .Recording .tenant ))
7680 records = (await session .execute (stmt )).scalars ().all ()
7781 for record in records :
7882 record .state = state
7983 await session .commit ()
8084 if state == model .RecordingState .PUBLISHED :
81- await asyncio .to_thread (importer .publish , record .tenant .name , record .record_id )
85+ await asyncio .to_thread (
86+ importer .publish , record .tenant .name , record .record_id
87+ )
8288 else :
83- await asyncio .to_thread (importer .unpublish , record .tenant .name , record .record_id )
84-
89+ await asyncio .to_thread (
90+ importer .unpublish , record .tenant .name , record .record_id
91+ )
8592
8693
8794@recording .command ("import" )
8895@click .option ("--tenant" , help = "Override the tenant found in the recording" )
96+ @click .option (
97+ "--publish/--unpublish" ,
98+ help = "Publish or unpublsh recording after import" ,
99+ default = None ,
100+ )
89101@click .argument ("FILE" , type = click .Path (dir_okay = True ), default = "-" )
90102@async_command ()
91- async def _import (obj : ServiceRegistry , tenant : str , file : str ):
103+ async def _import (obj : ServiceRegistry , tenant : str , publish : bool | None , file : str ):
92104 """Import one or more recordings from a tar archive"""
93105 importer = await obj .use ("importer" , RecordingManager )
94106
@@ -99,16 +111,34 @@ async def reader(file):
99111
100112 task = await importer .start_import (reader (file ), force_tenant = tenant )
101113 await task .wait ()
102- if task .error :
103- click .echo (f"ERROR { task .error } " )
104- raise SystemExit (1 )
105114
106- click .echo ("OK" )
115+ for format in task .formats :
116+ click .echo (
117+ f"Imported: { format .recording .tenant .name } /{ format .recording .record_id } ({ format .format } )"
118+ )
119+ if (
120+ publish is True
121+ and format .recording .started != model .RecordingState .PUBLISHED
122+ ):
123+ await _change_publish_flag (
124+ obj , [format .recording .record_id ], model .RecordingState .PUBLISHED
125+ )
126+ elif (
127+ publish is False
128+ and format .recording .started != model .RecordingState .UNPUBLISHED
129+ ):
130+ await _change_publish_flag (
131+ obj , [format .recording .record_id ], model .RecordingState .UNPUBLISHED
132+ )
133+ for error in task .errors :
134+ click .echo (f"ERROR: { error } " )
135+ if task .errors :
136+ raise SystemExit (1 )
107137
108138
109139@recording .command ()
110140@click .option (
111- "--dry-run" , "-n" , help = "Simulate changes without changing anything ." , is_flag = True
141+ "--dry-run" , "-n" , help = "Do not actually remove any recordings ." , is_flag = True
112142)
113143@async_command ()
114144async def remove_orphans (obj : ServiceRegistry , dry_run : bool ):
0 commit comments