Re: [pkg-go] [PATCH] dakweb: add /golang/import_paths query

2017-10-24 Thread Michael Stapelberg
Updated patch attached (as per Ganneff’s review).

On Sun, Oct 22, 2017 at 6:41 PM, Michael Stapelberg
 wrote:
> Please keep me CC'ed, I’m not subscribed to debian-dak.
>
> Please consider merging the following patch which you can find
> attached to this email or at
> https://github.com/stapelberg/dak/tree/golang. Thank you!
>
> This query will replace a heuristic in dh-make-golang(1) and help us resolve
> Go build dependencies into Debian build dependencies accurately.
> ---
>  dakweb/dakwebserver.py   |  1 +
>  dakweb/queries/golang.py | 52 
> 
>  2 files changed, 53 insertions(+)
>  create mode 100644 dakweb/queries/golang.py
>
> diff --git a/dakweb/dakwebserver.py b/dakweb/dakwebserver.py
> index 0ddc10cf..bd6b62ff 100755
> --- a/dakweb/dakwebserver.py
> +++ b/dakweb/dakwebserver.py
> @@ -45,6 +45,7 @@ from queries.archive import *
>  from queries.madison import *
>  from queries.source import *
>  from queries.suite import *
> +from queries.golang import *
>
>  # Set up our initial database connection
>  d = DBConn()
> diff --git a/dakweb/queries/golang.py b/dakweb/queries/golang.py
> new file mode 100644
> index ..0c343424
> --- /dev/null
> +++ b/dakweb/queries/golang.py
> @@ -0,0 +1,52 @@
> +"""Golang related queries
> +
> +@contact: https://pkg-go.alioth.debian.org/
> +@copyright: 2017 Michael Stapelberg 
> +@license: GNU General Public License version 2 or later
> +"""
> +
> +import bottle
> +import json
> +
> +from daklib.dbconn import DBConn, MetadataKey
> +from dakweb.webregister import QueryRegister
> +
> +
> +@bottle.route('/golang/import_paths')
> +def import_paths():
> +"""
> +Returns a mapping of Go import path to Debian binary package name and
> +corresponding Debian source package name.
> +
> +@rtype: dictionary
> +@return: A list of dictionaries of
> + - binary
> + - source
> + - importpath
> +"""
> +
> +s = DBConn().session()
> +conn = s.connection()
> +res = conn.execute("""
> +SELECT
> +binaries.package,
> +source.source,
> +source_metadata.value AS importpath
> +FROM
> +binaries LEFT JOIN
> +source ON (binaries.source = source.id) LEFT JOIN
> +source_metadata ON (source.id = source_metadata.src_id) LEFT JOIN
> +metadata_keys ON (source_metadata.key_id = metadata_keys.key_id)
> +WHERE
> +metadata_keys.key = 'Go-Import-Path'
> +GROUP BY
> +binaries.package,
> +source.source,
> +source_metadata.value;
> +""")
> +out = [{'binary': res[0], 'source': res[1], 'importpath': res[2]}
> for res in res]
> +s.close()
> +
> +return json.dumps(out)
> +
> +QueryRegister().register_path('/golang/import_paths', import_paths)
> --
> 2.14.2



-- 
Best regards,
Michael
From 2a26e89d407d37ccb4a7d245fa32a732ecf83468 Mon Sep 17 00:00:00 2001
From: Michael Stapelberg 
Date: Sun, 22 Oct 2017 18:32:04 +0200
Subject: [PATCH] dakweb: add /binary/by_metadata query

This query will replace a heuristic in dh-make-golang(1) and help us resolve
Go build dependencies into Debian build dependencies accurately.

Signed-off-by: Michael Stapelberg 
---
 dakweb/dakwebserver.py   |  1 +
 dakweb/queries/binary.py | 50 
 2 files changed, 51 insertions(+)
 create mode 100644 dakweb/queries/binary.py

diff --git a/dakweb/dakwebserver.py b/dakweb/dakwebserver.py
index 0ddc10cf..7b957344 100755
--- a/dakweb/dakwebserver.py
+++ b/dakweb/dakwebserver.py
@@ -45,6 +45,7 @@ from queries.archive import *
 from queries.madison import *
 from queries.source import *
 from queries.suite import *
+from queries.binary import *
 
 # Set up our initial database connection
 d = DBConn()
diff --git a/dakweb/queries/binary.py b/dakweb/queries/binary.py
new file mode 100644
index ..7a5692a2
--- /dev/null
+++ b/dakweb/queries/binary.py
@@ -0,0 +1,50 @@
+"""Debian binary package related queries.
+
+@copyright: 2017 Michael Stapelberg 
+@license: GNU General Public License version 2 or later
+"""
+
+import bottle
+import json
+
+from daklib.dbconn import DBConn, DBBinary, DBSource, SourceMetadata, MetadataKey
+from dakweb.webregister import QueryRegister
+
+
+@bottle.route('/binary/by_metadata/')
+def binary_by_metadata(key=None):
+"""
+
+Finds all Debian binary packages which have the specified metadata set.
+
+E.g., to find out the Go import paths of all Debian Go packages, query
+/binary/by_metadata/Go-Import-Path.
+
+@type key: string
+@param key: Metadata key to search for.
+
+@rtype: dictionary
+@return: A list of dictionaries of
+ - binary
+ - source
+ - metadata value
+"""
+
+if not key:
+return bottle.HTTPError(503, 'Metadata key not 

[pkg-go] [PATCH] dakweb: add /golang/import_paths query

2017-10-22 Thread Michael Stapelberg
Please keep me CC'ed, I’m not subscribed to debian-dak.

Please consider merging the following patch which you can find
attached to this email or at
https://github.com/stapelberg/dak/tree/golang. Thank you!

This query will replace a heuristic in dh-make-golang(1) and help us resolve
Go build dependencies into Debian build dependencies accurately.
---
 dakweb/dakwebserver.py   |  1 +
 dakweb/queries/golang.py | 52 
 2 files changed, 53 insertions(+)
 create mode 100644 dakweb/queries/golang.py

diff --git a/dakweb/dakwebserver.py b/dakweb/dakwebserver.py
index 0ddc10cf..bd6b62ff 100755
--- a/dakweb/dakwebserver.py
+++ b/dakweb/dakwebserver.py
@@ -45,6 +45,7 @@ from queries.archive import *
 from queries.madison import *
 from queries.source import *
 from queries.suite import *
+from queries.golang import *

 # Set up our initial database connection
 d = DBConn()
diff --git a/dakweb/queries/golang.py b/dakweb/queries/golang.py
new file mode 100644
index ..0c343424
--- /dev/null
+++ b/dakweb/queries/golang.py
@@ -0,0 +1,52 @@
+"""Golang related queries
+
+@contact: https://pkg-go.alioth.debian.org/
+@copyright: 2017 Michael Stapelberg 
+@license: GNU General Public License version 2 or later
+"""
+
+import bottle
+import json
+
+from daklib.dbconn import DBConn, MetadataKey
+from dakweb.webregister import QueryRegister
+
+
+@bottle.route('/golang/import_paths')
+def import_paths():
+"""
+Returns a mapping of Go import path to Debian binary package name and
+corresponding Debian source package name.
+
+@rtype: dictionary
+@return: A list of dictionaries of
+ - binary
+ - source
+ - importpath
+"""
+
+s = DBConn().session()
+conn = s.connection()
+res = conn.execute("""
+SELECT
+binaries.package,
+source.source,
+source_metadata.value AS importpath
+FROM
+binaries LEFT JOIN
+source ON (binaries.source = source.id) LEFT JOIN
+source_metadata ON (source.id = source_metadata.src_id) LEFT JOIN
+metadata_keys ON (source_metadata.key_id = metadata_keys.key_id)
+WHERE
+metadata_keys.key = 'Go-Import-Path'
+GROUP BY
+binaries.package,
+source.source,
+source_metadata.value;
+""")
+out = [{'binary': res[0], 'source': res[1], 'importpath': res[2]}
for res in res]
+s.close()
+
+return json.dumps(out)
+
+QueryRegister().register_path('/golang/import_paths', import_paths)
-- 
2.14.2
From 50470f6ba177058fbc77a6652c5883322f78c4fb Mon Sep 17 00:00:00 2001
From: Michael Stapelberg 
Date: Sun, 22 Oct 2017 18:32:04 +0200
Subject: [PATCH] dakweb: add /golang/import_paths query

This query will replace a heuristic in dh-make-golang(1) and help us resolve
Go build dependencies into Debian build dependencies accurately.
---
 dakweb/dakwebserver.py   |  1 +
 dakweb/queries/golang.py | 52 
 2 files changed, 53 insertions(+)
 create mode 100644 dakweb/queries/golang.py

diff --git a/dakweb/dakwebserver.py b/dakweb/dakwebserver.py
index 0ddc10cf..bd6b62ff 100755
--- a/dakweb/dakwebserver.py
+++ b/dakweb/dakwebserver.py
@@ -45,6 +45,7 @@ from queries.archive import *
 from queries.madison import *
 from queries.source import *
 from queries.suite import *
+from queries.golang import *
 
 # Set up our initial database connection
 d = DBConn()
diff --git a/dakweb/queries/golang.py b/dakweb/queries/golang.py
new file mode 100644
index ..0c343424
--- /dev/null
+++ b/dakweb/queries/golang.py
@@ -0,0 +1,52 @@
+"""Golang related queries
+
+@contact: https://pkg-go.alioth.debian.org/
+@copyright: 2017 Michael Stapelberg 
+@license: GNU General Public License version 2 or later
+"""
+
+import bottle
+import json
+
+from daklib.dbconn import DBConn, MetadataKey
+from dakweb.webregister import QueryRegister
+
+
+@bottle.route('/golang/import_paths')
+def import_paths():
+"""
+Returns a mapping of Go import path to Debian binary package name and
+corresponding Debian source package name.
+
+@rtype: dictionary
+@return: A list of dictionaries of
+ - binary
+ - source
+ - importpath
+"""
+
+s = DBConn().session()
+conn = s.connection()
+res = conn.execute("""
+SELECT
+binaries.package,
+source.source,
+source_metadata.value AS importpath
+FROM
+binaries LEFT JOIN
+source ON (binaries.source = source.id) LEFT JOIN
+source_metadata ON (source.id = source_metadata.src_id) LEFT JOIN
+metadata_keys ON (source_metadata.key_id = metadata_keys.key_id)
+WHERE
+metadata_keys.key = 'Go-Import-Path'
+GROUP BY
+binaries.package,
+source.source,
+source_metadata.value;
+""")
+out = [{'binary': res[0], 'source':