2019-09-04 17:01:16 -03:00
|
|
|
#!/usr/bin/python3
|
2007-11-07 20:05:37 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2007-09-07 14:36:50 +02:00
|
|
|
#
|
2008-08-11 20:06:35 +02:00
|
|
|
# submittodebian - tool to submit patches to Debian's BTS
|
2009-12-11 13:46:28 -08:00
|
|
|
# Copyright (C) 2007, 2009 Canonical Ltd.
|
|
|
|
# Author: Soren Hansen <soren@ubuntu.com>,
|
|
|
|
# Steve Langasek <slangasek@canonical.com>
|
2007-09-07 14:36:50 +02:00
|
|
|
#
|
2008-08-11 20:06:35 +02:00
|
|
|
# ##################################################################
|
2007-09-07 14:36:50 +02:00
|
|
|
#
|
2008-08-11 20:06:35 +02:00
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
2010-12-03 00:06:43 +01:00
|
|
|
#
|
2008-08-11 20:06:35 +02:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2010-12-03 00:06:43 +01:00
|
|
|
#
|
2008-08-11 20:06:35 +02:00
|
|
|
# See file /usr/share/common-licenses/GPL for more details.
|
2007-09-07 14:36:50 +02:00
|
|
|
#
|
2008-08-11 20:06:35 +02:00
|
|
|
# ##################################################################
|
2007-09-07 14:36:50 +02:00
|
|
|
|
2012-05-05 19:34:02 +02:00
|
|
|
import optparse
|
2011-06-25 17:53:44 +02:00
|
|
|
import os
|
|
|
|
import re
|
2011-12-03 00:06:35 +02:00
|
|
|
import shutil
|
2011-06-25 17:53:44 +02:00
|
|
|
import sys
|
2023-01-30 21:28:47 +01:00
|
|
|
from subprocess import DEVNULL, PIPE, Popen, call, check_call, run
|
2011-11-13 00:09:41 +02:00
|
|
|
from tempfile import mkdtemp
|
2007-09-03 10:53:11 +02:00
|
|
|
|
2019-09-05 09:50:09 -03:00
|
|
|
from debian.changelog import Changelog
|
2023-01-30 21:28:47 +01:00
|
|
|
from distro_info import DistroDataOutdated, UbuntuDistroInfo
|
2011-01-21 19:20:04 +01:00
|
|
|
|
2018-10-12 18:54:07 -04:00
|
|
|
from ubuntutools import getLogger
|
2023-01-30 21:28:47 +01:00
|
|
|
from ubuntutools.config import ubu_email
|
|
|
|
from ubuntutools.question import EditFile, YesNoQuestion
|
|
|
|
from ubuntutools.update_maintainer import restore_maintainer, update_maintainer
|
2023-01-30 19:45:36 +01:00
|
|
|
|
2021-02-01 18:26:13 -05:00
|
|
|
Logger = getLogger()
|
2018-10-12 18:54:07 -04:00
|
|
|
|
2012-06-20 22:17:07 +02:00
|
|
|
|
2007-09-03 10:53:11 +02:00
|
|
|
def get_most_recent_debian_version(changelog):
|
2011-09-09 23:54:36 +02:00
|
|
|
for block in changelog:
|
2011-09-09 20:20:29 +02:00
|
|
|
version = block.version.full_version
|
2023-01-30 19:45:36 +01:00
|
|
|
if not re.search("(ubuntu|build)", version):
|
2011-09-09 20:20:29 +02:00
|
|
|
return version
|
2007-09-03 10:53:11 +02:00
|
|
|
|
2012-06-20 22:17:07 +02:00
|
|
|
|
2007-09-03 10:53:11 +02:00
|
|
|
def get_bug_body(changelog):
|
2011-09-09 23:54:36 +02:00
|
|
|
entry = next(iter(changelog))
|
2012-06-20 22:17:07 +02:00
|
|
|
msg = """
|
|
|
|
In Ubuntu, the attached patch was applied to achieve the following:
|
2010-11-30 11:56:36 +01:00
|
|
|
|
|
|
|
## ---------------- REPLACE THIS WITH ACTUAL INFORMATION ---------------------
|
2010-12-01 16:51:09 +00:00
|
|
|
## Please add all necessary information about why the change needed to go in
|
2010-11-30 11:56:36 +01:00
|
|
|
## Ubuntu, quote policy, spec or any other background material and why it can
|
2010-12-01 16:51:09 +00:00
|
|
|
## and should be used in Debian too. If the patch is composed of multiple
|
|
|
|
## independent pieces, please send them as separate bug reports.
|
2010-11-30 11:56:36 +01:00
|
|
|
## ---------------- REPLACE THIS WITH ACTUAL INFORMATION ---------------------
|
|
|
|
|
2007-09-03 10:53:11 +02:00
|
|
|
%s
|
2010-11-30 11:56:36 +01:00
|
|
|
|
|
|
|
Thanks for considering the patch.
|
2023-01-30 19:45:36 +01:00
|
|
|
""" % (
|
|
|
|
"\n".join([a for a in entry.changes()])
|
|
|
|
)
|
2010-12-27 14:21:01 +01:00
|
|
|
return msg
|
2007-09-03 10:53:11 +02:00
|
|
|
|
2012-06-20 22:17:07 +02:00
|
|
|
|
2012-05-06 19:46:05 +02:00
|
|
|
def build_source_package():
|
2023-01-30 19:45:36 +01:00
|
|
|
if os.path.isdir(".bzr"):
|
|
|
|
cmd = ["bzr", "bd", "--builder=dpkg-buildpackage", "-S", "--", "-uc", "-us", "-nc"]
|
2012-05-06 19:46:05 +02:00
|
|
|
else:
|
2023-01-30 19:45:36 +01:00
|
|
|
cmd = ["dpkg-buildpackage", "-S", "-uc", "-us", "-nc"]
|
2012-06-20 22:44:12 +02:00
|
|
|
env = os.environ.copy()
|
|
|
|
# Unset DEBEMAIL in case there's an @ubuntu.com e-mail address
|
2023-01-30 19:45:36 +01:00
|
|
|
env.pop("DEBEMAIL", None)
|
2012-06-20 22:44:12 +02:00
|
|
|
check_call(cmd, env=env)
|
2012-05-06 19:46:05 +02:00
|
|
|
|
2012-06-20 22:17:07 +02:00
|
|
|
|
2011-11-13 00:09:41 +02:00
|
|
|
def gen_debdiff(tmpdir, changelog):
|
2010-12-22 01:28:00 +01:00
|
|
|
pkg = changelog.package
|
2007-09-03 10:53:11 +02:00
|
|
|
|
2011-09-09 23:54:36 +02:00
|
|
|
changelog_it = iter(changelog)
|
|
|
|
newver = next(changelog_it).version
|
|
|
|
oldver = next(changelog_it).version
|
2007-09-03 10:53:11 +02:00
|
|
|
|
2023-01-30 19:45:36 +01:00
|
|
|
debdiff = os.path.join(tmpdir, "%s_%s.debdiff" % (pkg, newver))
|
2009-12-27 12:58:05 -08:00
|
|
|
|
2023-01-30 19:45:36 +01:00
|
|
|
diff_cmd = ["bzr", "diff", "-r", "tag:" + str(oldver)]
|
2019-02-11 14:30:01 -05:00
|
|
|
if call(diff_cmd, stdout=DEVNULL, stderr=DEVNULL) == 1:
|
2023-01-31 11:13:07 +01:00
|
|
|
Logger.info("Extracting bzr diff between %s and %s", oldver, newver)
|
2010-12-22 01:28:00 +01:00
|
|
|
else:
|
|
|
|
if oldver.epoch is not None:
|
2023-01-30 19:45:36 +01:00
|
|
|
oldver = str(oldver)[str(oldver).index(":") + 1 :]
|
2010-12-22 01:28:00 +01:00
|
|
|
if newver.epoch is not None:
|
2023-01-30 19:45:36 +01:00
|
|
|
newver = str(newver)[str(newver).index(":") + 1 :]
|
2007-09-03 10:53:11 +02:00
|
|
|
|
2023-01-30 19:45:36 +01:00
|
|
|
olddsc = "../%s_%s.dsc" % (pkg, oldver)
|
|
|
|
newdsc = "../%s_%s.dsc" % (pkg, newver)
|
2007-09-03 10:53:11 +02:00
|
|
|
|
2010-12-22 01:28:00 +01:00
|
|
|
check_file(olddsc)
|
|
|
|
check_file(newdsc)
|
2009-12-11 13:46:28 -08:00
|
|
|
|
2023-01-31 11:13:07 +01:00
|
|
|
Logger.info("Generating debdiff between %s and %s", oldver, newver)
|
2023-01-30 19:45:36 +01:00
|
|
|
diff_cmd = ["debdiff", olddsc, newdsc]
|
2011-11-13 20:54:05 +02:00
|
|
|
|
2023-01-30 19:45:36 +01:00
|
|
|
with Popen(diff_cmd, stdout=PIPE, encoding="utf-8") as diff:
|
|
|
|
with open(debdiff, "w", encoding="utf-8") as debdiff_f:
|
|
|
|
run(
|
|
|
|
["filterdiff", "-x", "*changelog*"],
|
|
|
|
stdin=diff.stdout,
|
|
|
|
stdout=debdiff_f,
|
|
|
|
encoding="utf-8",
|
|
|
|
)
|
2007-09-03 10:53:11 +02:00
|
|
|
|
2010-12-22 01:28:00 +01:00
|
|
|
return debdiff
|
2007-09-03 10:53:11 +02:00
|
|
|
|
2012-06-20 22:17:07 +02:00
|
|
|
|
|
|
|
def check_file(fname, critical=True):
|
2010-12-22 01:28:00 +01:00
|
|
|
if os.path.exists(fname):
|
|
|
|
return fname
|
|
|
|
else:
|
2010-12-27 20:02:11 +01:00
|
|
|
if not critical:
|
|
|
|
return False
|
2023-01-31 11:13:07 +01:00
|
|
|
Logger.info("Couldn't find «%s».\n", fname)
|
2010-12-22 01:28:00 +01:00
|
|
|
sys.exit(1)
|
2007-11-07 20:05:37 +01:00
|
|
|
|
2012-06-20 22:17:07 +02:00
|
|
|
|
2010-12-27 20:02:11 +01:00
|
|
|
def submit_bugreport(body, debdiff, deb_version, changelog):
|
2012-05-06 10:15:54 +02:00
|
|
|
try:
|
|
|
|
devel = UbuntuDistroInfo().devel()
|
2019-09-04 17:01:16 -03:00
|
|
|
except DistroDataOutdated as e:
|
2018-10-12 18:54:07 -04:00
|
|
|
Logger.info(str(e))
|
2023-01-30 19:45:36 +01:00
|
|
|
devel = ""
|
2011-12-02 23:42:29 +02:00
|
|
|
|
2023-01-30 19:45:36 +01:00
|
|
|
if os.path.dirname(sys.argv[0]).startswith("/usr/bin"):
|
|
|
|
editor_path = "/usr/share/ubuntu-dev-tools"
|
2011-12-02 23:42:29 +02:00
|
|
|
else:
|
|
|
|
editor_path = os.path.dirname(sys.argv[0])
|
|
|
|
env = dict(os.environ.items())
|
2023-01-30 19:45:36 +01:00
|
|
|
if "EDITOR" in env:
|
|
|
|
env["UDT_EDIT_WRAPPER_EDITOR"] = env["EDITOR"]
|
|
|
|
if "VISUAL" in env:
|
|
|
|
env["UDT_EDIT_WRAPPER_VISUAL"] = env["VISUAL"]
|
|
|
|
env["EDITOR"] = os.path.join(editor_path, "enforced-editing-wrapper")
|
|
|
|
env["VISUAL"] = os.path.join(editor_path, "enforced-editing-wrapper")
|
|
|
|
env["UDT_EDIT_WRAPPER_TEMPLATE_RE"] = ".*REPLACE THIS WITH ACTUAL INFORMATION.*"
|
|
|
|
env["UDT_EDIT_WRAPPER_FILE_DESCRIPTION"] = "bug report"
|
2011-12-02 23:42:29 +02:00
|
|
|
|
2012-07-02 15:05:39 +02:00
|
|
|
# In external mua mode, attachments are lost (Reportbug bug: #679907)
|
|
|
|
internal_mua = True
|
2023-01-30 19:45:36 +01:00
|
|
|
for cfgfile in ("/etc/reportbug.conf", "~/.reportbugrc"):
|
2012-07-02 15:05:39 +02:00
|
|
|
cfgfile = os.path.expanduser(cfgfile)
|
|
|
|
if not os.path.exists(cfgfile):
|
|
|
|
continue
|
2023-01-30 19:45:36 +01:00
|
|
|
with open(cfgfile, "r") as f:
|
2012-07-02 15:05:39 +02:00
|
|
|
for line in f:
|
|
|
|
line = line.strip()
|
2023-01-30 19:45:36 +01:00
|
|
|
if line in ("gnus", "mutt", "nmh") or line.startswith("mua "):
|
2012-07-02 15:05:39 +02:00
|
|
|
internal_mua = False
|
|
|
|
break
|
|
|
|
|
2023-01-30 19:45:36 +01:00
|
|
|
cmd = (
|
|
|
|
"reportbug",
|
|
|
|
"--no-check-available",
|
|
|
|
"--no-check-installed",
|
|
|
|
"--pseudo-header",
|
|
|
|
"User: ubuntu-devel@lists.ubuntu.com",
|
|
|
|
"--pseudo-header",
|
|
|
|
"Usertags: origin-ubuntu %s ubuntu-patch" % devel,
|
|
|
|
"--tag",
|
|
|
|
"patch",
|
|
|
|
"--bts",
|
|
|
|
"debian",
|
|
|
|
"--include",
|
|
|
|
body,
|
|
|
|
"--attach" if internal_mua else "--include",
|
|
|
|
debdiff,
|
|
|
|
"--package-version",
|
|
|
|
deb_version,
|
|
|
|
changelog.package,
|
|
|
|
)
|
2011-12-02 23:42:29 +02:00
|
|
|
check_call(cmd, env=env)
|
2007-09-03 10:53:11 +02:00
|
|
|
|
2011-12-02 21:33:10 +02:00
|
|
|
|
2011-06-22 12:15:57 +02:00
|
|
|
def check_reportbug_config():
|
2023-01-30 23:10:31 +01:00
|
|
|
reportbugrc_filename = os.path.expanduser("~/.reportbugrc")
|
|
|
|
if os.path.exists(reportbugrc_filename):
|
2011-06-22 12:15:57 +02:00
|
|
|
return
|
|
|
|
email = ubu_email()[1]
|
2023-01-30 19:45:36 +01:00
|
|
|
reportbugrc = (
|
|
|
|
"""# Reportbug configuration generated by submittodebian(1)
|
2011-06-22 12:15:57 +02:00
|
|
|
# See reportbug.conf(5) for the configuration file format.
|
|
|
|
|
|
|
|
# Use Debian's reportbug SMTP Server:
|
|
|
|
# Note: it's limited to 5 connections per hour, and cannot CC you at submission
|
|
|
|
# time. See /usr/share/doc/reportbug/README.Users.gz for more details.
|
|
|
|
smtphost reportbug.debian.org:587
|
|
|
|
header "X-Debbugs-CC: %s"
|
|
|
|
no-cc
|
|
|
|
|
|
|
|
# Use GMail's SMTP Server:
|
|
|
|
#smtphost smtp.googlemail.com:587
|
|
|
|
#smtpuser "<your address>@gmail.com"
|
|
|
|
#smtptls
|
2023-01-30 19:45:36 +01:00
|
|
|
"""
|
|
|
|
% email
|
|
|
|
)
|
2011-06-22 12:15:57 +02:00
|
|
|
|
2023-01-30 23:10:31 +01:00
|
|
|
with open(reportbugrc_filename, "w") as f:
|
2011-06-22 12:15:57 +02:00
|
|
|
f.write(reportbugrc)
|
|
|
|
|
2023-01-30 19:45:36 +01:00
|
|
|
Logger.info(
|
|
|
|
"""\
|
2011-06-25 15:35:17 +02:00
|
|
|
You have not configured reportbug. Assuming this is the first time you have
|
|
|
|
used it. Writing a ~/.reportbugrc that will use Debian's mail server, and CC
|
|
|
|
the bug to you at <%s>
|
2011-06-22 12:15:57 +02:00
|
|
|
|
|
|
|
--- Generated ~/.reportbugrc ---
|
|
|
|
%s
|
|
|
|
--- End of ~/.reportbugrc ---
|
|
|
|
|
|
|
|
If this is not correct, please exit now and edit ~/.reportbugrc or run
|
|
|
|
reportbug --configure for its configuration wizard.
|
2023-01-31 11:13:07 +01:00
|
|
|
""",
|
|
|
|
email,
|
|
|
|
reportbugrc.strip(),
|
2023-01-30 19:45:36 +01:00
|
|
|
)
|
2011-06-22 12:15:57 +02:00
|
|
|
|
2011-06-25 15:35:17 +02:00
|
|
|
if YesNoQuestion().ask("Continue submitting this bug", "yes") == "no":
|
2011-06-22 12:15:57 +02:00
|
|
|
sys.exit(1)
|
|
|
|
|
2012-06-20 22:17:07 +02:00
|
|
|
|
2010-12-27 20:02:11 +01:00
|
|
|
def main():
|
2023-01-30 19:45:36 +01:00
|
|
|
description = (
|
|
|
|
"Submit the Ubuntu changes in a package to Debian. "
|
|
|
|
+ "Run inside an unpacked Ubuntu source package."
|
|
|
|
)
|
2012-05-27 00:46:24 +02:00
|
|
|
parser = optparse.OptionParser(description=description)
|
2012-05-05 19:34:02 +02:00
|
|
|
parser.parse_args()
|
2012-05-12 19:21:39 -07:00
|
|
|
|
2023-01-30 19:45:36 +01:00
|
|
|
if not os.path.exists("/usr/bin/reportbug"):
|
|
|
|
Logger.error(
|
|
|
|
"This utility requires the «reportbug» package, which isn't currently installed."
|
|
|
|
)
|
2012-05-12 19:21:39 -07:00
|
|
|
sys.exit(1)
|
|
|
|
|
2011-06-22 12:15:57 +02:00
|
|
|
check_reportbug_config()
|
2023-01-30 19:45:36 +01:00
|
|
|
changelog_file = check_file("debian/changelog", critical=False) or check_file(
|
|
|
|
"../debian/changelog"
|
|
|
|
)
|
2019-09-04 17:01:16 -03:00
|
|
|
with open(changelog_file) as f:
|
|
|
|
changelog = Changelog(f.read())
|
2007-09-03 10:53:11 +02:00
|
|
|
|
2010-12-27 20:02:11 +01:00
|
|
|
deb_version = get_most_recent_debian_version(changelog)
|
|
|
|
bug_body = get_bug_body(changelog)
|
2007-09-03 10:53:11 +02:00
|
|
|
|
2011-11-13 00:09:41 +02:00
|
|
|
tmpdir = mkdtemp()
|
2023-01-30 19:45:36 +01:00
|
|
|
body = os.path.join(tmpdir, "bug_body")
|
|
|
|
with open(body, "wb") as f:
|
|
|
|
f.write(bug_body.encode("utf-8"))
|
2007-09-03 10:53:11 +02:00
|
|
|
|
2023-01-30 19:45:36 +01:00
|
|
|
restore_maintainer("debian")
|
2012-05-06 19:46:05 +02:00
|
|
|
build_source_package()
|
2023-01-30 19:45:36 +01:00
|
|
|
update_maintainer("debian")
|
2012-05-06 19:46:05 +02:00
|
|
|
|
2011-11-13 00:09:41 +02:00
|
|
|
debdiff = gen_debdiff(tmpdir, changelog)
|
2011-11-13 21:31:01 +02:00
|
|
|
|
2012-05-06 19:46:05 +02:00
|
|
|
# Build again as the user probably doesn't expect the Maintainer to be
|
|
|
|
# reverted in the most recent build
|
|
|
|
build_source_package()
|
|
|
|
|
2023-01-30 19:45:36 +01:00
|
|
|
EditFile(debdiff, "debdiff").edit(optional=True)
|
2011-11-13 21:31:01 +02:00
|
|
|
|
2010-12-27 20:02:11 +01:00
|
|
|
submit_bugreport(body, debdiff, deb_version, changelog)
|
|
|
|
os.unlink(body)
|
|
|
|
os.unlink(debdiff)
|
2011-12-03 00:06:35 +02:00
|
|
|
shutil.rmtree(tmpdir)
|
2010-12-27 20:02:11 +01:00
|
|
|
|
2017-05-01 00:20:03 +02:00
|
|
|
|
2023-01-30 19:45:36 +01:00
|
|
|
if __name__ == "__main__":
|
2010-12-27 20:02:11 +01:00
|
|
|
main()
|