diff --git a/.gitignore b/.gitignore --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ dist/ version.txt .mypy_cache/ +venv \ No newline at end of file diff --git a/requirements.txt b/requirements.txt --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,11 @@ -# Add here external Python modules dependencies, one per line. Module names -# should match https://pypi.python.org/pypi names. For the full spec or -# dependency lines, see https://pip.readthedocs.org/en/1.1/requirements.html - +attrs==20.3.0 +attrs-strict==0.2.0 +Deprecated==1.2.10 +hypothesis==5.49.0 +iso8601==0.1.13 +psycopg2==2.8.6 +python-dateutil==2.8.1 +six==1.15.0 +sortedcontainers==2.3.0 +typing-extensions==3.7.4.3 +wrapt==1.12.1 diff --git a/swh/clearlydefined/mapping_utils.py b/swh/clearlydefined/mapping_utils.py new file mode 100644 --- /dev/null +++ b/swh/clearlydefined/mapping_utils.py @@ -0,0 +1,20 @@ +# Copyright (C) 2017-2020 The Software Heritage developers +# See the AUTHORS file at the top-level directory of this distribution +# License: GNU Affero General Public License version 3, or any later version +# See top-level LICENSE file for more information + +import psycopg2 +import swh.model.hashutil + +def map_sha1_with_swhid(sha1, dsn): + if not sha1: + return None + read_connection = psycopg2.connect(dsn) + cur = read_connection.cursor() + sha1 = swh.model.hashutil.hash_to_hex(sha1) + sha1 = "\\x{sha1}".format(sha1=sha1) + cur.execute("SELECT sha1_git from content WHERE sha1=%s;",(sha1)) + sha1_git = cur.fetchall() + sha1_git = swh.model.hashutil.hash_to_hex(sha1_git[0][0]) + swh_id = "swh:1:cnt:{sha1_git}".format(sha1_git) + return swh_id