2019-03-22 06:47:17 +01:00
|
|
|
# coding: utf-8
|
|
|
|
# Copyright: (c) 2019, Ansible Project
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
|
|
|
|
# Make coding more python3-ish
|
|
|
|
from __future__ import (absolute_import, division, print_function)
|
|
|
|
__metaclass__ = type
|
|
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
from collections import UserString
|
|
|
|
from distutils.version import LooseVersion
|
|
|
|
|
2019-05-01 20:57:03 +02:00
|
|
|
# Pylint doesn't understand Python3 namespace modules.
|
|
|
|
from ..commands import Command # pylint: disable=relative-beyond-top-level
|
2019-07-16 21:19:01 +02:00
|
|
|
from .. import errors # pylint: disable=relative-beyond-top-level
|
2019-03-22 06:47:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
class VersionStr(UserString):
|
|
|
|
def __init__(self, string):
|
|
|
|
super().__init__(string.strip())
|
|
|
|
self.ver_obj = LooseVersion(string)
|
|
|
|
|
|
|
|
|
2019-05-01 20:57:03 +02:00
|
|
|
def transform_args(args):
|
2019-03-22 06:47:17 +01:00
|
|
|
# Make it possible to sort versions in the jinja2 templates
|
|
|
|
new_versions = []
|
|
|
|
for version in args.versions:
|
|
|
|
new_versions.append(VersionStr(version))
|
|
|
|
args.versions = new_versions
|
|
|
|
|
|
|
|
return args
|
|
|
|
|
|
|
|
|
|
|
|
def write_message(filename, message):
|
|
|
|
if filename != '-':
|
|
|
|
with open(filename, 'w') as out_file:
|
|
|
|
out_file.write(message)
|
|
|
|
else:
|
|
|
|
sys.stdout.write('\n\n')
|
|
|
|
sys.stdout.write(message)
|
|
|
|
|
|
|
|
|
2019-05-01 20:57:03 +02:00
|
|
|
class ReleaseAnnouncementCommand(Command):
|
|
|
|
name = 'release-announcement'
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def init_parser(cls, add_parser):
|
|
|
|
parser = add_parser(cls.name,
|
|
|
|
description="Generate email and twitter announcements from template")
|
2019-03-22 06:47:17 +01:00
|
|
|
|
2019-05-01 20:57:03 +02:00
|
|
|
parser.add_argument("--version", dest="versions", type=str, required=True, action='append',
|
|
|
|
help="Versions of Ansible to announce")
|
|
|
|
parser.add_argument("--name", type=str, required=True, help="Real name to use on emails")
|
|
|
|
parser.add_argument("--email-out", type=str, default="-",
|
|
|
|
help="Filename to place the email announcement into")
|
|
|
|
parser.add_argument("--twitter-out", type=str, default="-",
|
|
|
|
help="Filename to place the twitter announcement into")
|
2019-03-22 06:47:17 +01:00
|
|
|
|
2019-07-16 21:19:01 +02:00
|
|
|
@classmethod
|
|
|
|
def main(cls, args):
|
|
|
|
if sys.version_info < (3, 6):
|
|
|
|
raise errors.DependencyError('The {0} subcommand needs Python-3.6+'
|
|
|
|
' to run'.format(cls.name))
|
|
|
|
|
|
|
|
# Import here because these functions are invalid on Python-3.5 and the command plugins and
|
|
|
|
# init_parser() method need to be compatible with Python-3.4+ for now.
|
|
|
|
# Pylint doesn't understand Python3 namespace modules.
|
|
|
|
from .. announce import create_short_message, create_long_message # pylint: disable=relative-beyond-top-level
|
|
|
|
|
2019-05-01 20:57:03 +02:00
|
|
|
args = transform_args(args)
|
2019-03-22 06:47:17 +01:00
|
|
|
|
2019-07-16 21:19:01 +02:00
|
|
|
twitter_message = create_short_message(args.versions)
|
|
|
|
email_message = create_long_message(args.versions, args.name)
|
2019-03-22 06:47:17 +01:00
|
|
|
|
2019-05-01 20:57:03 +02:00
|
|
|
write_message(args.twitter_out, twitter_message)
|
|
|
|
write_message(args.email_out, email_message)
|
|
|
|
return 0
|