[2019-02-02 17:27] Mattia Rizzolo <mat...@debian.org>
> Also, I'd like for you to check with the mentors.d.n code and make sure
> the template matches, keeping in mind that there is some kind of plan to
> make mentors send such mail automatically.

While formatting was inspired by mentors.d.o, the whole idea of
debrequest is that it produce much more detailed template.  Probably,
the most important feature is automatic deduction of programming
language. Also, dgit tries to accomodate to different workflows, like
dgit.

Definitely, some things are quite opinionated (assumtion of dep-5, for
example). Here is prelimitary patch. It builds, installs manpage and
works for me. Could you please review it?

Also, if you prefer, you could take a look at commit
  309eb408cdc3d25839a6a4006023415a60e08213
at https://salsa.debian.org/kaction/devscripts

From 309eb408cdc3d25839a6a4006023415a60e08213 Mon Sep 17 00:00:00 2001
From: Dmitry Bogatov <kact...@debian.org>
Date: Sun, 3 Feb 2019 16:33:56 +0000
Subject: [PATCH] New script: debrequest

---
 scripts/debrequest                            | 112 +++++++++++++
 scripts/debrequest.1                          | 158 ++++++++++++++++++
 .../devscripts/templates/debrequest-itp.j2    |  25 +++
 .../templates/debrequest-package-info.j2      |   9 +
 .../devscripts/templates/debrequest-rfs.j2    |  68 ++++++++
 scripts/devscripts/test/__init__.py           |   1 +
 scripts/setup.py                              |   3 +-
 7 files changed, 375 insertions(+), 1 deletion(-)
 create mode 100755 scripts/debrequest
 create mode 100644 scripts/debrequest.1
 create mode 100644 scripts/devscripts/templates/debrequest-itp.j2
 create mode 100644 scripts/devscripts/templates/debrequest-package-info.j2
 create mode 100644 scripts/devscripts/templates/debrequest-rfs.j2

diff --git a/scripts/debrequest b/scripts/debrequest
new file mode 100755
index 00000000..7a28b292
--- /dev/null
+++ b/scripts/debrequest
@@ -0,0 +1,112 @@
+#!/usr/bin/python3
+# debrequest --- generate Debian RFS/ITP requests
+
+# Copyright (C) 2016 Dmitry Bogatov <kact...@gnu.org>
+
+# Author: Dmitry Bogatov <kact...@gnu.org>
+
+# 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 3
+# of the License, or (at your option) any later version.
+
+# 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.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+"""
+Debrequest command line program collects machine-readable
+information from files in debian/ directory of source
+package and use is to generate RFS or ITP request.
+
+Request formatted will be output on stdout and is well-formed
+RFC822 message, suitable for piping to `/sbin/sendmail'.
+"""
+
+from glob import glob
+from os.path import isfile, isdir
+import argparse
+from debian.deb822 import Deb822
+from debian.changelog import Changelog, get_maintainer
+from jinja2 import Environment, PackageLoader, StrictUndefined
+
+
+def read_paragraphs(path):
+    "Return list of paragraphs from deb822 file at {path}."
+    return list(Deb822.iter_paragraphs(open(path)))
+
+
+def collect_information():
+    info = {}
+    (name, email) = get_maintainer()
+    info['maintainer_name'] = name
+    info['maintainer_email'] = email
+
+    (source_p, *binary_ps) = read_paragraphs('debian/control')
+    (upstream_p, *license_ps) = read_paragraphs('debian/copyright')
+    changelog = Changelog(open('debian/changelog'))
+
+    info['version'] = changelog.get_version()
+    info['package_name'] = source_p['Source']
+    info['upstream_name'] = upstream_p['Upstream-Name']
+    info['binary_packages'] = [p['Package'] for p in binary_ps]
+    info['section'] = source_p['Section']
+    info['homepage'] = source_p['Homepage']
+    info['upstream_author'] = upstream_p.get('Upstream-Contact',
+                                             source_p['Maintainer'])
+    try:
+        info['short_description'] = source_p['X-Short-Desc']
+        info['long_description'] = source_p['X-Long-Desc']
+    except KeyError:
+        (short_desc, long_desc) = binary_ps[0]['Description'].split('\n', 1)
+        info['short_description'] = short_desc
+        info['long_description'] = long_desc
+
+    licenses = [par['License'].split('\n')[0].strip() for par in license_ps]
+    info['licenses'] = list(set(licenses))
+    info['changes'] = changelog[0].changes()
+    info['upload_count'] = len(changelog)
+    try:
+        info['vcs_git'] = source_p['Vcs-Git']
+    except KeyError:
+        pass
+    info['languages'] = []
+    build_depends = [dep.strip().split()[0]
+                     for dep in source_p['Build-Depends'].split(",")
+                     if dep != '']
+    if 'guile-2.0-dev' in build_depends:
+        info['languages'].append('GNU Guile')
+    if 'dh-elpa' in build_depends:
+        info['languages'].append('Emacs Lisp')
+    if isfile('configure.ac') or isfile('configure') or glob('*.c') != []:
+        info['languages'].append('C')
+    if glob('*.cabal') != []:
+        info['languages'].append('Haskell')
+    if glob('*.pm') != []:
+        info['languages'].append('Perl')
+    if isfile('setup.py'):
+        info['languages'].append('Python')
+    info['dgit'] = isdir(".git/refs/heads/dgit") or isdir('.git/dgit')
+    return info
+
+
+def main():
+    parser = argparse.ArgumentParser(description=__doc__)
+    parser.add_argument('mode', choices=['rfs', 'itp'], type=str.lower,
+                        help='kind of request to generate')
+    args = parser.parse_args()
+    info = collect_information()
+
+    env = Environment(loader=PackageLoader('devscripts', 'templates'),
+                      line_statement_prefix='%% ',
+                      trim_blocks=True,
+                      lstrip_blocks=True,
+                      undefined=StrictUndefined)
+    template = env.get_template("debrequest-%s.j2" % args.mode)
+    print(template.render(info))
+
+
+main()
diff --git a/scripts/debrequest.1 b/scripts/debrequest.1
new file mode 100644
index 00000000..18a8cd48
--- /dev/null
+++ b/scripts/debrequest.1
@@ -0,0 +1,158 @@
+.TH DEBREQUEST "1" "October 2016" "debrequest 0.2" "User Commands"
+.SH NAME
+debrequest \- generate Debian RFS and ITP requests mails
+.SH SYNOPSIS
+.SY debrequest
+.OP -h
+rfs|itp
+.YS
+.SH DESCRIPTION
+.B debrequest
+command line program collects machine-readable information
+from files in debian/ directory of source package located in
+in current directory and use is to generate RFS or ITP request.
+
+There are at least following assumptions about command line arguments
+and source package:
+.IP * 2
+.IR debian/control
+exists and is actually Debian source package control file
+.IP "*" 2
+.I .debian/copyright
+follows
+.B DEP-5
+format and have following optional present:
+.IR Upstream-Contact ,
+.IR Upstream-Name .
+.IP * 2
+Environment variables
+.I DEBEMAIL
+and
+.I DEBFULLNAME
+are set to reasonable values.
+.PP
+Probably, there are more. If any of these assumptions are violated,
+you will receive Python error message, like this:
+.PP
+.EX
+Traceback (most recent call last):
+  File "/usr/bin/debrequest", line 91, in <module>
+    info = collect_information(args.root)
+  File "/usr/bin/debrequest", line 51, in collect_information
+    (upstream_p, *license_ps) = read_paragraphs('debian/copyright', root)
+ValueError: need more than 0 values to unpack
+.EE
+.PP
+While ValueError
+is not too informative, it is possible to understand that there is something 
wrong
+with
+.I debian/copyright.
+Patches to improve error reporting are welcome.
+.PP
+Mandatory positional argument, which either
+.B rfs
+either
+.B itp
+specifies what kind of request to generate.
+.SH EXAMPLES
+Here is example of RFS for
+.I debrequest
+itself:
+.IP "" 8
+.EX
+From: Dmitry Bogatov <kact...@gnu.org>
+To: sub...@bugs.debian.org
+Subject: RFS: debrequest/0.2 ITP
+X-Debug-Cc: debian-ment...@lists.debian.org
+
+Package: sponsorship-requests
+Severity: wishlist
+
+Dear mentors,
+
+I am looking for a sponsor for my package "debrequest"
+
+* Package name    : debrequest
+  Version         : 0.2
+  Upstream Author : Dmitry Bogatov <kact...@gnu.org>
+* Url             : 
https://anonscm.debian.org/cgit/users/kaction-guest/debrequest.git
+* Licenses        : GPL-3+
+  Section         : devel
+
+It builds those binary packages:
+
+  * debrequest
+
+To access further information about this package, visit the following URL:
+
+    https://mentors.debian.net/package/debrequest
+
+Alternatively, one can download the package with dget using this command:
+    dget -x 
https://mentors.debian.net/debian/pool/main/d/debrequest/debrequest_0.2.dsc
+
+Alternatively, you can access package debian/ directory via git from URL:
+    https://anonscm.debian.org/cgit/users/kaction-guest/debrequest.git
+
+More information about debrequest can be obtained from
+    https://anonscm.debian.org/cgit/users/kaction-guest/debrequest.git
+
+Regards,
+  Dmitry Bogatov
+.EE
+.PP
+Note, that this is RFS for first release, so changelog is not
+mentioned.  On other hand, here is RFS for cdist package. Note
+paragraph about changes.
+.PP
+.IP "" 8
+.EX
+From: Dmitry Bogatov <kact...@gnu.org>
+To: sub...@bugs.debian.org
+Subject: RFS: cdist/4.3.2-1
+X-Debug-Cc: debian-ment...@lists.debian.org
+
+Package: sponsorship-requests
+Severity: wishlist
+
+Dear mentors,
+
+I am looking for a sponsor for my package "cdist"
+
+* Package name    : cdist
+  Version         : 4.3.2-1
+  Upstream Author : Nico Schottelius <nico-debian-cd...@schottelius.org>
+* Url             : http://www.nico.schottelius.org/software/cdist/
+* Licenses        : GPL-3,GPL-3+
+  Section         : admin
+
+It builds those binary packages:
+
+  * cdist
+  * cdist-doc
+
+To access further information about this package, visit the following URL:
+
+    https://mentors.debian.net/package/cdist
+
+Alternatively, one can download the package with dget using this command:
+    dget -x 
https://mentors.debian.net/debian/pool/main/c/cdist/cdist_4.3.2-1.dsc
+
+Alternatively, you can access package debian/ directory via git from URL:
+    https://anonscm.debian.org/cgit/users/kaction-guest/cdist.git
+
+More information about cdist can be obtained from
+    http://www.nico.schottelius.org/software/cdist/
+
+Changes since last upload:
+
+  * New upstream release
+
+Regards,
+  Dmitry Bogatov
+.EE
+.SH "SEE ALSO"
+\" There is .UR macro, but it renders terrible on my tty, so here is ad-hoc
+\" version.
+.BR sendmail (8)
+.PP
+.BI DEP-5 " 
https\://www.debian.org/doc/packaging-manuals/copyright-format/1.0/"
diff --git a/scripts/devscripts/templates/debrequest-itp.j2 
b/scripts/devscripts/templates/debrequest-itp.j2
new file mode 100644
index 00000000..d9961e1c
--- /dev/null
+++ b/scripts/devscripts/templates/debrequest-itp.j2
@@ -0,0 +1,25 @@
+{# -*- jinja2 -*- #}
+From: "{{maintainer_name}}" <{{maintainer_email}}>
+To: Debian Bug Tracking System <sub...@bugs.debian.org>
+Subject: ITP: {{ upstream_name }} -- {{ short_description }}
+X-Debug-Cc: debian-de...@lists.debian.org
+
+Package: wnpp
+Severity: wishlist
+Owner: {{ maintainer_name }} <{{ maintainer_email }}>
+
+{% include 'debrequest-package-info.j2' %}
+
+
+{% if 'Haskell' in languages %}
+ I plan to maintain this package as part of Debian Haskell Group
+{% else %}
+  {% if 'Emacs Lisp' in languages %}
+ I plan to maintain this package as part of Emacsen team
+  {% else %}
+ I plan to maintain this package myself, keeping debianization in following
+ Git repository:
+
+     {{ vcs_git }}
+  {% endif -%}
+{% endif -%}
diff --git a/scripts/devscripts/templates/debrequest-package-info.j2 
b/scripts/devscripts/templates/debrequest-package-info.j2
new file mode 100644
index 00000000..679fc80c
--- /dev/null
+++ b/scripts/devscripts/templates/debrequest-package-info.j2
@@ -0,0 +1,9 @@
+* Package name     : {{ package_name }}
+  Version          : {{ version }}
+  Upstream Author  : {{ upstream_author }}
+* Url              : {{ homepage }}
+* Licenses         : {{ licenses|join(',') }}
+  Programming Lang : {{ languages|join(',') }}
+  Section          : {{ section }}
+
+{{ long_description }}
diff --git a/scripts/devscripts/templates/debrequest-rfs.j2 
b/scripts/devscripts/templates/debrequest-rfs.j2
new file mode 100644
index 00000000..bb94226c
--- /dev/null
+++ b/scripts/devscripts/templates/debrequest-rfs.j2
@@ -0,0 +1,68 @@
+{# -*- jinja2 -*- #}
+From: {{ maintainer_name }} <{{ maintainer_email  }}>
+To: sub...@bugs.debian.org
+{% if upload_count == 1 -%}
+{% set tag = 'ITP' -%}
+{% else -%}
+{% set tag = '' -%}
+{% endif -%}
+Subject: RFS: {{ package_name }}/{{ version }} {{ tag }}
+
+Package: sponsorship-requests
+Severity: wishlist
+
+Dear mentors,
+
+I am looking for a sponsor for my package "{{ package_name }}"
+
+{% include 'debrequest-package-info.j2' %}
+
+
+It builds those binary packages:
+
+{% for pkg in binary_packages %}
+  * {{ pkg }}
+{% endfor %}
+
+This package succesfully builds on debomatic machine:
+
+  http://debomatic-i386.debian.net/distribution#unstable/{{ package_name }}/{{ 
version }}
+
+{% if dgit %}
+Please note, that package is maintained with dgit(1) tool
+using dgit-maint-merge(7) workflow. For more information about how to
+sponsor this package, see dgit-sponsorship(7).
+
+With /bin/sh following commands should suffice:
+
+  $ git clone {{ vcs_git }} {{ package_name }}
+  $ cd {{ package_name }}
+  $ make -f debian/rules get-orig-source # 'gbp buildpackage' is fine
+  $ dgit sbuild
+
+{% else %}
+
+To access further information about this package, visit the following URL:
+
+    https://mentors.debian.net/package/{{ package_name }}
+
+Alternatively, one can download the package with dget using this command:
+{% set letter = package_name[0] %}
+    dget -x https://mentors.debian.net/debian/pool/main/{{ letter }}/{{ 
package_name }}/{{ package_name }}_{{ version }}.dsc
+
+{% if vcs_git is defined %}
+Alternatively, you can access package debian/ directory via git from URL:
+    {{ vcs_git }}
+{% endif %}
+
+More information about {{ package_name }} can be obtained from
+    {{ homepage }}
+
+{% endif %}
+
+{% if upload_count != 1 %}
+Changes since last upload:
+{{ changes|join('\n')}}
+{% endif %}
+Regards,
+  {{ maintainer_name }}
diff --git a/scripts/devscripts/test/__init__.py 
b/scripts/devscripts/test/__init__.py
index 335f1d40..2f2e8e84 100644
--- a/scripts/devscripts/test/__init__.py
+++ b/scripts/devscripts/test/__init__.py
@@ -19,6 +19,7 @@ import unittest
 
 SCRIPTS = [
     "debdiff-apply",
+    "debrequest",
     "reproducible-check",
     "sadt",
     "suspicious-source",
diff --git a/scripts/setup.py b/scripts/setup.py
index 5908616f..cbe41213 100755
--- a/scripts/setup.py
+++ b/scripts/setup.py
@@ -24,6 +24,7 @@ if __name__ == '__main__':
         name='devscripts',
         version=get_version(),
         scripts=SCRIPTS,
-        packages=['devscripts', 'devscripts/test'],
+        packages=['devscripts', 'devscripts/test', 'devscripts/templates'],
+        package_data={'devscripts': ['templates/*']},
         test_suite='devscripts.test',
     )
-- 
        Note, that I send and fetch email in batch, once every 24 hours.
                 If matter is urgent, try https://t.me/kaction
                                                                             --

Reply via email to