40 from pkg_resources
import parse_version
41 from email.utils
import formatdate
49 from catkin_pkg.changelog
import get_changelog_from_path
50 from catkin_pkg.changelog
import CHANGELOG_FILENAME
51 except ImportError
as err:
52 debug(traceback.format_exc())
53 error(
"catkin_pkg was not detected, please install it.", exit=
True)
58 debug(traceback.format_exc())
59 error(
"empy was not detected, please install it.", exit=
True)
63 package_maintainer_name,
64 package_maintainer_email,
66 releaser_history=None):
67 if releaser_history
is None:
68 warnings.warn(
"No historical releaser history, using current maintainer name and email for each versioned "
69 "changelog entry.", Warning)
72 if os.path.exists(changelog_path):
73 changelog = get_changelog_from_path(changelog_path)
75 maintainer = (package_maintainer_name, package_maintainer_email)
76 for version, date, changes
in changelog.foreach_version(reverse=
True):
78 date_str = formatdate(float(date.strftime(
"%s")), date.tzinfo)
80 changes_str.extend([
' ' + i
for i
in to_unicode(item).splitlines()])
82 releaser, email = releaser_history.get(version, maintainer)
84 version, date_str,
'\n'.join(changes_str), releaser, email
88 warnings.warn(
"No {0} found for package '{1}'".format(CHANGELOG_FILENAME, package_name))
94 package_maintainer_name,
95 package_maintainer_email,
97 package_debian_increment,
98 package_changelog_path,
101 package_maintainer_name,
102 package_maintainer_email,
103 package_changelog_path)
104 if changelogs
and package_version
not in [x[0]
for x
in changelogs]:
106 A CHANGELOG.rst was found, but no changelog for this version was found.
107 You REALLY should have a entry (even a blank one) for each version of your package.
112 date = datetime.datetime.now()
113 if package_version
not in [x[0]
for x
in changelogs]:
114 changelogs.insert(0, (
116 formatdate(float(date.strftime(
"%s")), date.tzinfo),
117 ' * Autogenerated, no changelog for this version found in CHANGELOG.rst.',
118 package_maintainer_name,
119 package_maintainer_email
121 bad_changelog =
False
123 if package_version != changelogs[0][0]:
125 The version of the first changelog entry '{0}' is not the
126 same as the version being currently released '{1}'.
127 """.format(package_version, changelogs[0][0]))
130 for changelog
in changelogs:
131 if parse_version(package_version) < parse_version(changelog[0]):
133 There is at least one changelog entry, '{0}', which has a
134 newer version than the version of package '{1}' being released, '{2}'.
135 """.format(changelog[0], package_name, package_version))
138 sys.exit(
"This is almost certainly by mistake, you should really take a\nlook at the changelogs for the package '{0}' you are releasing '{1}'.".format(package_name, package_version))
143 data[
'DebianInc'] =
'' if native
else '-{0}'.format(package_debian_increment)
145 data[
'Package'] = package_name
147 data[
'changelogs'] = changelogs
149 data[
'Distribution'] = package_distribution
151 template = (
"@[for change_version, change_date, changelog, main_name, main_email in changelogs]@(Package) (@("
152 "change_version)@(DebianInc)@(Distribution)) @(Distribution); urgency=high\n\n@(changelog)\n\n -- @("
153 "main_name) <@(main_email)> @(change_date)\n\n@[end for]\n")
156 result = em.expand(template, **data)
159 error(
"Failed to expand template")
161 if sys.version_info.major == 2:
162 result = result.decode(
'utf-8')
163 output_path.write(result)
166 if __name__ ==
'__main__':
167 parser = argparse.ArgumentParser()
168 parser.description =
"Convert ROS CHANGELOG.rst to debian changelog"
169 parser.prog =
'create_debian_changelog'
171 parser.add_argument(
'name', nargs=1, help=
'The package name', type=str)
172 parser.add_argument(
'version', nargs=1, help=
'The package version', type=str)
173 parser.add_argument(
'maintainer_name', nargs=1, help=
'The package maintainer name', type=str)
174 parser.add_argument(
'maintainer_email', nargs=1, help=
'The package maintainer email', type=str)
175 parser.add_argument(
'distribution', nargs=1, help=
'The package distribution', type=str)
176 parser.add_argument(
'debian_increment', nargs=1, help=
'The debian increment', type=str)
177 parser.add_argument(
'changelog_path', nargs=1, help=
'CHANGELOG.rst file path', type=str)
178 parser.add_argument(
'-o',
'--output', help=
'Debian changelog output file path', default=sys.stdout,
179 type=argparse.FileType(
'w'))
180 arguments = parser.parse_args()
182 arguments.version[0],
183 arguments.maintainer_name[0],
184 arguments.maintainer_email[0],
185 arguments.distribution[0],
186 arguments.debian_increment[0],
187 arguments.changelog_path[0],