From c34531c3beaf535c76d805f805cdac0c83e369ad Mon Sep 17 00:00:00 2001 From: Andy Doan Date: Fri, 21 Nov 2014 15:23:31 -0600 Subject: fix broken commit ea20228e346cc2fbbbebcb32a44331c534943cf7 This broke the parsemail.py and update-commited-patches scripts and is preventing us from updating production. Change-Id: I658c43487039f7e4c343c67a08ba8ed37d00d4f0 --- .../roles/settings/templates/local_settings.tmpl.py | 1 - apps/patchwork/bin/parsemail.py | 11 +++++++---- apps/patchwork/bin/update-committed-patches.py | 18 +++++++++--------- apps/patchwork/db.py | 4 ++-- apps/patchwork/utils.py | 2 +- apps/settings.py | 3 --- 6 files changed, 19 insertions(+), 20 deletions(-) diff --git a/ansible/roles/settings/templates/local_settings.tmpl.py b/ansible/roles/settings/templates/local_settings.tmpl.py index dc6d417..defe3ea 100644 --- a/ansible/roles/settings/templates/local_settings.tmpl.py +++ b/ansible/roles/settings/templates/local_settings.tmpl.py @@ -29,7 +29,6 @@ PATCHWORK_GIT_REPOS_DIR = '{{ patchwork_repos_path }}' CROWD_GROUPS_WHITELIST = os.path.join( ROOT_DIR, 'lib', '{{ whitelist_groups_file }}') -CROWD_USERS_DB_FILE = os.path.join('{{ crowd_cache_path }}', 'crowd_users.db') AUTH_CROWD_APPLICATION_USER = '{{ crowd_app_name }}' AUTH_CROWD_APPLICATION_PASSWORD = '{{ crowd_app_password }}' diff --git a/apps/patchwork/bin/parsemail.py b/apps/patchwork/bin/parsemail.py index fe643d8..64ccb83 100755 --- a/apps/patchwork/bin/parsemail.py +++ b/apps/patchwork/bin/parsemail.py @@ -22,8 +22,8 @@ import chardet import datetime import operator +import os import re -import settings import sys from email import message_from_file @@ -36,6 +36,10 @@ except ImportError: from email.Header import Header, decode_header from email.Utils import parsedate_tz, mktime_tz +here = os.path.abspath(os.path.dirname(__file__)) +sys.path.append(os.path.join(here, '../..')) +import settings + from patchmetrics.crowd import Crowd from patchwork.db import PatchworkDB from patchwork.parser import parse_patch @@ -494,13 +498,12 @@ def is_valid_patch(submitter, author): valid_patch |= True if not valid_patch: - if (settings.AUTH_CROWD_APPLICATION_USER is not None and - settings.CROWD_USERS_DB_FILE is not None): + if settings.AUTH_CROWD_APPLICATION_USER is not None: crwd = Crowd(settings.AUTH_CROWD_APPLICATION_USER, settings.AUTH_CROWD_APPLICATION_PASSWORD, settings.AUTH_CROWD_SERVER_REST_URI) - cache_db = PatchworkDB(settings.CROWD_USERS_DB_FILE) + cache_db = PatchworkDB() with cache_db: valid_patch |= is_linaro_user(submitter.email, cache_db, crwd) if author is not None: diff --git a/apps/patchwork/bin/update-committed-patches.py b/apps/patchwork/bin/update-committed-patches.py index 5fe1755..c11b5e8 100755 --- a/apps/patchwork/bin/update-committed-patches.py +++ b/apps/patchwork/bin/update-committed-patches.py @@ -9,17 +9,22 @@ # accepted into sub-maintainer/custodian branches will only be marked as # accepted once they reach the master branch. +import os import sys from datetime import datetime -from django.conf import settings -from django.db.models import Q from dulwich.repo import Repo from lockfile import FileLock, LockFailed, LockTimeout from operator import attrgetter -from patchmetrics.crowd import Crowd +here = os.path.abspath(os.path.dirname(__file__)) +sys.path.append(os.path.join(here, '../..')) from patchwork.db import PatchworkDB + +from django.conf import settings +from django.db.models import Q + +from patchmetrics.crowd import Crowd from patchwork.models import Project, State from patchwork.utils import ( ensure_source_checkout_for_project, @@ -41,12 +46,7 @@ def main(): settings.AUTH_CROWD_APPLICATION_PASSWORD, settings.AUTH_CROWD_SERVER_REST_URI) - if settings.CROWD_USERS_DB_FILE is None: - print >> sys.stderr, ("CROWD_USERS_DB_FILE not defined in " - "settings.py.\n") - sys.exit(1) - - cache_db = PatchworkDB(settings.CROWD_USERS_DB_FILE) + cache_db = PatchworkDB() projects = Project.objects.exclude( Q(source_tree__isnull=True) | Q(source_tree='')) diff --git a/apps/patchwork/db.py b/apps/patchwork/db.py index e886ba5..26957fc 100644 --- a/apps/patchwork/db.py +++ b/apps/patchwork/db.py @@ -77,12 +77,12 @@ class PatchworkDB(object): :param timestamp: When the user was added in the cache. """ self.cursor.execute('''INSERT INTO users(id, valid, ts) - VALUES (%s, %s, %s)''', (email, valid, timestamp)) + VALUES (%s, %s, %s)''', (email, int(valid), timestamp)) def update_user(self, email, valid, timestamp): """Updates a user in the DB.""" self.cursor.execute('''UPDATE users SET valid=%s, ts=%s WHERE id=%s''', - (valid, timestamp, email)) + (int(valid), timestamp, email)) def get_user(self, email): """Retrieves a user from the DB. diff --git a/apps/patchwork/utils.py b/apps/patchwork/utils.py index 48c31ac..7a28421 100644 --- a/apps/patchwork/utils.py +++ b/apps/patchwork/utils.py @@ -548,7 +548,7 @@ def check_cached_user_validity(cached_user, db, crowd): :param db: A PatchworkDB instance for the cache backend. :param crowd: A Crowd instance to update user data if necessary. """ - date_inserted = datetime.datetime.strptime(cached_user[2], DATE_FORMAT) + date_inserted = cached_user[2] today = datetime.datetime.now() delta = today - date_inserted diff --git a/apps/settings.py b/apps/settings.py index b5e6b66..0f7b24f 100644 --- a/apps/settings.py +++ b/apps/settings.py @@ -139,9 +139,6 @@ CROWD_CREDENTIALS_FILE = None # File with a list of groups that should be created in the DB. If other groups # are taken out from Crowd, and they are not here, they will be skipped. CROWD_GROUPS_WHITELIST = None -# Full path to a DB file. -# This is used to have a cache of which users exists in the Crowd database. -CROWD_USERS_DB_FILE = None # Number of days before checking again if a user exists in the Crowd db. CROWD_USERS_DB_EXPIRY = 30 -- cgit v1.2.3