From 9550ca3edd9a8cd03f4fc2fd5632bb59d66fce4e Mon Sep 17 00:00:00 2001
From: Nicolas Dandrimont <nicolas@dandrimont.eu>
Date: Thu, 17 Mar 2016 20:35:08 +0100
Subject: [PATCH] storage_utils: Add constants to a constants module

---
 swh/lister/github/constants.py     |  7 +++++++
 swh/lister/github/converters.py    | 11 ++++++-----
 swh/lister/github/storage_utils.py | 15 +++++----------
 3 files changed, 18 insertions(+), 15 deletions(-)
 create mode 100644 swh/lister/github/constants.py

diff --git a/swh/lister/github/constants.py b/swh/lister/github/constants.py
new file mode 100644
index 00000000..08dcc893
--- /dev/null
+++ b/swh/lister/github/constants.py
@@ -0,0 +1,7 @@
+# Copyright © 2016 The Software Heritage Developers <swh-devel@inria.fr>
+# License: GNU General Public License version 3, or any later version
+# See top-level LICENSE file for more information
+
+GITHUB_ORGS_UUID = '9f7b34d9-aa98-44d4-8907-b332c1036bc3'
+GITHUB_USERS_UUID = 'ad6df473-c1d2-4f40-bc58-2b091d4a750e'
+GITHUB_LISTER_UUID = '34bd6b1b-463f-43e5-a697-785107f598e4'
diff --git a/swh/lister/github/converters.py b/swh/lister/github/converters.py
index e630a64a..4846f85e 100644
--- a/swh/lister/github/converters.py
+++ b/swh/lister/github/converters.py
@@ -8,7 +8,7 @@ from email.utils import format_datetime
 
 from dateutil.parser import parse as parse_datetime
 
-from . import cache, storage_utils
+from . import cache, constants
 
 
 def utcnow():
@@ -42,7 +42,7 @@ def repository_to_entity(orig_entity, repo):
     entity['active'] = True
     entity['generated'] = True
 
-    entity['lister_metadata']['lister'] = storage_utils.GITHUB_LISTER_UUID
+    entity['lister_metadata']['lister'] = constants.GITHUB_LISTER_UUID
     entity['lister_metadata']['type'] = 'repository'
     entity['lister_metadata']['id'] = repo['id']
     entity['lister_metadata']['fork'] = repo['fork']
@@ -61,10 +61,11 @@ def user_to_entity(orig_entity, user):
     entity = copy.deepcopy(orig_entity)
 
     if user['type'] == 'User':
-        parent = storage_utils.GITHUB_USERS_UUID
+        parent = constants.GITHUB_USERS_UUID
+
         type = 'person'
     elif user['type'] == 'Organization':
-        parent = storage_utils.GITHUB_ORGS_UUID
+        parent = constants.GITHUB_ORGS_UUID
         type = 'group_of_persons'
     else:
         raise ValueError("Unknown GitHub user type %s" % user['type'])
@@ -81,7 +82,7 @@ def user_to_entity(orig_entity, user):
     entity['active'] = True
     entity['generated'] = True
 
-    entity['lister_metadata']['lister'] = storage_utils.GITHUB_LISTER_UUID
+    entity['lister_metadata']['lister'] = constants.GITHUB_LISTER_UUID
     entity['lister_metadata']['type'] = 'user'
     entity['lister_metadata']['id'] = user['id']
     entity['lister_metadata']['login'] = user['login']
diff --git a/swh/lister/github/storage_utils.py b/swh/lister/github/storage_utils.py
index e08b1a07..f625fab7 100644
--- a/swh/lister/github/storage_utils.py
+++ b/swh/lister/github/storage_utils.py
@@ -4,12 +4,7 @@
 
 import uuid
 
-from . import cache, converters
-
-
-GITHUB_ORGS_UUID = '9f7b34d9-aa98-44d4-8907-b332c1036bc3'
-GITHUB_USERS_UUID = 'ad6df473-c1d2-4f40-bc58-2b091d4a750e'
-GITHUB_LISTER_UUID = '34bd6b1b-463f-43e5-a697-785107f598e4'
+from . import cache, constants, converters
 
 
 def update_user_entities(storage, users):
@@ -19,7 +14,7 @@ def update_user_entities(storage, users):
     users = list(sorted(users, key=lambda u: u['id']))
 
     query = [{
-        'lister': GITHUB_LISTER_UUID,
+        'lister': constants.GITHUB_LISTER_UUID,
         'type': 'user',
         'id': user['id'],
     } for user in users]
@@ -59,7 +54,7 @@ def update_repo_entities(storage, repos):
         update_user_entities(storage, users.values())
 
     query = [{
-        'lister': GITHUB_LISTER_UUID,
+        'lister': constants.GITHUB_LISTER_UUID,
         'type': 'repository',
         'id': repo['id'],
     } for repo in repos]
@@ -89,7 +84,7 @@ def repo_last_modified(storage, id):
         entity = storage.entity_get_one(entity_id)
     else:
         entity = list(storage.entity_get_from_lister_metadata([{
-            'lister': GITHUB_LISTER_UUID,
+            'lister': constants.GITHUB_LISTER_UUID,
             'type': 'repository',
             'id': id,
         }]))[0]
@@ -109,7 +104,7 @@ def user_last_modified(storage, id):
         entity = storage.entity_get_one(entity_id)
     else:
         entity = list(storage.entity_get_from_lister_metadata([{
-            'lister': GITHUB_LISTER_UUID,
+            'lister': constants.GITHUB_LISTER_UUID,
             'type': 'user',
             'id': id,
         }]))[0]
-- 
GitLab