Skip to content

Commit

Permalink
WCM-167: we have all the information inside our interface, so lets us…
Browse files Browse the repository at this point in the history
…e it for the cli arguments
  • Loading branch information
stollero committed Jan 8, 2025
1 parent 0fde11e commit 66c3c1c
Showing 1 changed file with 16 additions and 40 deletions.
56 changes: 16 additions & 40 deletions core/src/zeit/cms/workflow/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import transaction
import zope.component

from zeit.cms.workflow.interfaces import IManualPublicationOptions, IPublish, IPublishInfo
import zeit.cms.celery
import zeit.cms.cli

Expand All @@ -19,7 +20,7 @@ def publish_content(options: dict):
we do not want to unregister and reregister the hooks for the application if this
function is called inside the regular vivi process
"""
options = zeit.cms.workflow.interfaces.IManualPublicationOptions(options)
options = IManualPublicationOptions(options)
registry = zope.component.getGlobalSiteManager()

# No option, since there is no usecase for re-activating old breaking news
Expand Down Expand Up @@ -66,7 +67,7 @@ def publish_content(options: dict):
log.warn('Skipping %s, not found', uid)
continue

info = zeit.cms.workflow.interfaces.IPublishInfo(content)
info = IPublishInfo(content)
if not (info.published or options.force_unpublished):
log.info('Skipping %s, not published and no --force-unpublished', uid)
continue
Expand All @@ -81,7 +82,7 @@ def publish_content(options: dict):
continue

try:
zeit.cms.workflow.interfaces.IPublish(content).publish(background=False)
IPublish(content).publish(background=False)
transaction.commit()
except Exception:
transaction.abort()
Expand All @@ -91,42 +92,17 @@ def publish_content(options: dict):
def publish():
parser = argparse.ArgumentParser(description='Publish content')
parser.add_argument('--filename', '-f', help='filename with uniqueId per line')
parser.add_argument(
'--force-unpublished', action='store_true', help='Publish even if currently unpublished'
)
parser.add_argument(
'--force-changed', action='store_true', help='Publish even if with semantic change'
)
parser.add_argument('--skip-deps', action='store_true', help='Ignore publication dependencies')

parser.add_argument(
'--use-checkin-hooks',
action='store_true',
help='Notify webhooks after checkin, like contenthub',
)
parser.add_argument(
'--use-publish-hooks',
action='store_true',
help='Notify webhooks after publish, like contenthub',
)

parser.add_argument(
'--ignore-services',
default=[],
help=f'Ignore 3rd party services; default: {IGNORE_SERVICES} will be extended by yours;',
nargs='+',
)
parser.add_argument(
'--wait-tms', action='store_true', help='Have publisher wait for TMS before fastly purge'
)
parser.add_argument(
'--skip-tms-enrich',
action='store_true',
help='Skip TMS enrich, e.g. checkin already happened',
)
parser.add_argument(
'--dlps', action='store_true', help='Update date_last_published_semantic timestamp'
)
for name, field in zope.schema.getFields(IManualPublicationOptions).items():
arg_name = f'--{name.replace("_", "-")}'
if isinstance(field, zope.schema.Bool):
parser.add_argument(arg_name, action='store_true', help=field.title)
elif isinstance(field, zope.schema.TextLine):
parser.add_argument(arg_name, help=field.title, default=field.default)
elif isinstance(field, zope.schema.Text):
parser.add_argument(arg_name, help=field.title, default=field.default)
else:
parser.add_argument(arg_name, help=field.title)

options = parser.parse_args()
if not options.filename:
Expand Down Expand Up @@ -172,13 +148,13 @@ def retract():
log.warn('Skipping %s, not found', id)
continue

info = zeit.cms.workflow.interfaces.IPublishInfo(content)
info = IPublishInfo(content)
if not (info.published or options.force):
log.info('Skipping %s, not published and no --force', id)
continue

try:
zeit.cms.workflow.interfaces.IPublish(content).retract(background=False)
IPublish(content).retract(background=False)
transaction.commit()
except Exception:
transaction.abort()

0 comments on commit 66c3c1c

Please sign in to comment.