Skip to content

Commit

Permalink
MAINT: delete-from-tms-index-script: log success infos
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasbaumann committed Sep 11, 2024
1 parent f0b9a4d commit 7fb5e15
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion core/src/zeit/retresco/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
@zeit.cms.cli.runner(principal=zeit.cms.cli.principal_from_args)
def delete_content_from_tms_indexes():
errors = []
infos = []
parser = argparse.ArgumentParser(description='Delete content from TMS indexes')
required = parser.add_argument_group('required arguments')
required.add_argument(
Expand Down Expand Up @@ -45,8 +46,10 @@ def delete_content_from_tms_indexes():
tms = zope.component.getUtility(zeit.retresco.interfaces.ITMS)
if options.retract:
tms.unpublish_id(uuid)
infos.append('Deleted from zeit_content', uniqueId)
if options.delete:
tms.delete_id(uuid)
infos.append('Deleted from zeit_pool_content', uniqueId)
except TypeError:
errors.append(('no content/uuid', uniqueId))
except zeit.retresco.interfaces.TMSError as e:
Expand All @@ -61,6 +64,15 @@ def delete_content_from_tms_indexes():
filename = os.path.expanduser(f'~/errors_{current_time}.txt')
log.info(f'\n🚨 {len(set(errors))}. Writing {filename} ...')
with open(filename, 'w') as f:
for content, error in set(errors):
for error, content in set(errors):
f.write(f'{error}: {content}\n')
log.info(f'\nSee errors in {filename}')

if infos:
current_time = pendulum.now().strftime('%Y%m%d%H%M%S')
filename = os.path.expanduser(f'~/infos_{current_time}.txt')
log.info(f'\nℹ️ {len(set(infos))}. Writing {filename} ...')
with open(filename, 'w') as f:
for info, content in set(infos):
f.write(f'{info}: {content}\n')
log.info(f'\nSee infos in {filename}')

0 comments on commit 7fb5e15

Please sign in to comment.