From f8ede651ead5734419a788153592bbbf2f8a31c7 Mon Sep 17 00:00:00 2001 From: Jonathan Le_Bonzec Date: Wed, 29 Nov 2017 16:37:54 +0100 Subject: [PATCH] Fixed several mistakes Some variables were undeclared or badly used --- quantifiedcode/backend/api/v1/diff.py | 3 ++- quantifiedcode/backend/api/v1/public_projects.py | 2 +- quantifiedcode/backend/api/v1/snapshot.py | 2 ++ quantifiedcode/backend/tasks/helpers.py | 10 +++++----- quantifiedcode/backend/tasks/periodic.py | 4 ++-- quantifiedcode/backend/tasks/project/delete.py | 2 ++ quantifiedcode/backend/utils/api.py | 2 ++ quantifiedcode/frontend/app.py | 1 + .../git/backend/api/v1/resources/git_snapshots.py | 1 + .../plugins/git/backend/api/v1/resources/project.py | 12 +++++++----- quantifiedcode/settings/default.yml | 8 ++++---- 11 files changed, 29 insertions(+), 18 deletions(-) diff --git a/quantifiedcode/backend/api/v1/diff.py b/quantifiedcode/backend/api/v1/diff.py index 19f47b6..539ec8d 100755 --- a/quantifiedcode/backend/api/v1/diff.py +++ b/quantifiedcode/backend/api/v1/diff.py @@ -154,7 +154,8 @@ def get(self, project_id, snapshot_a_id, snapshot_b_id, path=None): diff_issue_occurrence_table.c.issue_occurrence == issue_occurrence_table.c.pk, *issue_type_query))\ .join(issue_table, issue_table.c.pk == issue_occurrence_table.c.issue)\ - .join(issue_classes_cte, issue_classes_cte.c.analyzer_code == issue_table.c.analyzer + ':' + issue_table.c.code)\ + .join(issue_classes_cte, issue_classes_cte.c.analyzer_code == issue_table.c.analyzer + ':' + issue_table.c.code) \ + .alias('select_table') #we construct the table we will select issues from file_revision_query = select([fr_table.c.pk])\ diff --git a/quantifiedcode/backend/api/v1/public_projects.py b/quantifiedcode/backend/api/v1/public_projects.py index b497008..5d19fae 100644 --- a/quantifiedcode/backend/api/v1/public_projects.py +++ b/quantifiedcode/backend/api/v1/public_projects.py @@ -45,7 +45,7 @@ def get(self): form = PublicProjectsForm(request.args) if not form.validate(): - return {'message' : 'please correct the errors mentioned below', errors: form.errors}, 400 + return {'message' : 'please correct the errors mentioned below', 'errors': form.errors}, 400 data = form.data diff --git a/quantifiedcode/backend/api/v1/snapshot.py b/quantifiedcode/backend/api/v1/snapshot.py index 7c2f68a..a7f6142 100755 --- a/quantifiedcode/backend/api/v1/snapshot.py +++ b/quantifiedcode/backend/api/v1/snapshot.py @@ -106,6 +106,7 @@ def get(self, project_id, snapshot_id, path=None): .join(issue_occurrence_table, issue_occurrence_table.c.file_revision == snapshot_file_revisions_table.c.filerevision)\ .join(issue_table, and_(issue_table.c.pk == issue_occurrence_table.c.issue, issue_table.c.ignore == ignore) )\ .join(issue_classes_cte, issue_classes_cte.c.analyzer_code == issue_table.c.analyzer + ':' + issue_table.c.code)\ + .alias('fr_select_table') #we construct the file revisions query file_revisions_query = select([snapshot_file_revisions_table.c.filerevision])\ @@ -124,6 +125,7 @@ def get(self, project_id, snapshot_id, path=None): .join(issue_occurrence_table, issue_occurrence_table.c.file_revision == fr_table.c.pk)\ .join(issue_table, and_(issue_table.c.pk == issue_occurrence_table.c.issue, issue_table.c.ignore == ignore))\ .join(issue_classes_cte, issue_classes_cte.c.analyzer_code == issue_table.c.analyzer + ':' + issue_table.c.code)\ + .alias('select_table') #we construct the issues query diff --git a/quantifiedcode/backend/tasks/helpers.py b/quantifiedcode/backend/tasks/helpers.py index c5ebb0d..9844ae9 100755 --- a/quantifiedcode/backend/tasks/helpers.py +++ b/quantifiedcode/backend/tasks/helpers.py @@ -70,7 +70,7 @@ def __init__(self, task, level=logging.INFO, backend=None, ping=True): def __enter__(self): kwargs = { - 'filename': os.path.join(settings.get('backend.path'), settings.get('backend.paths.tasks'), + 'filename': os.path.join(settings.get('project_path'), settings.get('backend.paths.tasks'), self.task.pk + '.log'), 'encoding': "utf-8", 'mode': "w", @@ -139,10 +139,10 @@ def task_is_being_processed(current_task=None): try: res = celery.AsyncResult(task.celery_task_id) with self.backend.transaction(): - if res.state == ResultState.Started: + if res.state == self.ResultState.Started: self.backend.update(task, {'status': 'in_progress'}) return True - elif res.state == ResultState.Pending: + elif res.state == self.ResultState.Pending: if task.get('last_ping'): # if we haven't heard from the task in a while, we mark it as failed... if datetime.datetime.now() - task.last_ping > datetime.timedelta(seconds=60 * 10): @@ -151,9 +151,9 @@ def task_is_being_processed(current_task=None): elif datetime.datetime.now() - task.created_at < datetime.timedelta(seconds=60 * 20): self.backend.update(task, {'status': 'in_progress'}) return True - elif res.state == ResultState.Failure: + elif res.state == self.ResultState.Failure: self.backend.update(task, {'status': 'failed'}) - elif res.state == ResultState.Success: + elif res.state == self.ResultState.Success: self.backend.update(task, {'status': 'succeeded'}) except Task.DoesNotExist: # sometimes a task object will get deleted by another worker while diff --git a/quantifiedcode/backend/tasks/periodic.py b/quantifiedcode/backend/tasks/periodic.py index 604b960..b91af46 100644 --- a/quantifiedcode/backend/tasks/periodic.py +++ b/quantifiedcode/backend/tasks/periodic.py @@ -35,8 +35,8 @@ def delete_pending_project(): @celery.task(queue="delete", ignore_result=False, time_limit=3600) def delete_pending_user(): - pending_projects = backend.filter(User, {'delete': True}).sort('updated_at', 1).limit(100) - logger.debug("%d users marked for deletion" % len(pending_projects)) + pending_users = backend.filter(User, {'delete': True}).sort('updated_at', 1).limit(100) + logger.debug("%d users marked for deletion" % len(pending_users)) for pending_user in pending_users: return delete_user(pending_user.pk, task_id=delete_pending_user.request.id) logger.debug("No users left to delete...") diff --git a/quantifiedcode/backend/tasks/project/delete.py b/quantifiedcode/backend/tasks/project/delete.py index 1366cd5..ec2c4b0 100644 --- a/quantifiedcode/backend/tasks/project/delete.py +++ b/quantifiedcode/backend/tasks/project/delete.py @@ -21,6 +21,7 @@ from checkmate.management.commands.reset import Command as ResetCommand from quantifiedcode.settings import settings, backend from quantifiedcode.backend.settings import BACKEND_PATH +from quantifiedcode.backend.tasks.helpers import ExclusiveTask, TaskLogger from ...worker import celery from ...models import (Project, @@ -28,6 +29,7 @@ UserRole, IssueClass, ProjectIssueClass) +from ..project.analyze import analyze_project @celery.task(queue="analysis", ignore_result=False) def delete_project(project_id, task_id=None): diff --git a/quantifiedcode/backend/utils/api.py b/quantifiedcode/backend/utils/api.py index 149a0bb..3bd553f 100644 --- a/quantifiedcode/backend/utils/api.py +++ b/quantifiedcode/backend/utils/api.py @@ -11,7 +11,9 @@ from quantifiedcode.settings import settings +from flask import jsonify import logging +import traceback logger = logging.getLogger(__name__) diff --git a/quantifiedcode/frontend/app.py b/quantifiedcode/frontend/app.py index dee5bf1..c3275cf 100644 --- a/quantifiedcode/frontend/app.py +++ b/quantifiedcode/frontend/app.py @@ -136,4 +136,5 @@ def configure(app, settings): if __name__ == '__main__': app = get_app(settings) + debug = settings.get('debug') app.run(debug=debug, host='0.0.0.0', port=8000,threaded = False) diff --git a/quantifiedcode/plugins/git/backend/api/v1/resources/git_snapshots.py b/quantifiedcode/plugins/git/backend/api/v1/resources/git_snapshots.py index 8b1c276..c6d23eb 100644 --- a/quantifiedcode/plugins/git/backend/api/v1/resources/git_snapshots.py +++ b/quantifiedcode/plugins/git/backend/api/v1/resources/git_snapshots.py @@ -10,6 +10,7 @@ from __future__ import print_function import logging +import subprocess from datetime import datetime from flask import request diff --git a/quantifiedcode/plugins/git/backend/api/v1/resources/project.py b/quantifiedcode/plugins/git/backend/api/v1/resources/project.py index 199114c..f9b6eb4 100644 --- a/quantifiedcode/plugins/git/backend/api/v1/resources/project.py +++ b/quantifiedcode/plugins/git/backend/api/v1/resources/project.py @@ -79,11 +79,13 @@ def post(self): 'url' : form.url.data } - try: - project = create_project(project_data, git_data, user) - except DuplicateProject: - return ({'message': 'A project with the same name already exists for your account.'}, - 403) + project = create_project(project_data, git_data, user) + # FIXME: handle duplicate project exception + # try: + # pass + # except DuplicateProject: + # return ({'message': 'A project with the same name already exists for your account.'}, + # 403) return ({'message': 'success!', 'project': self.export(project)}, 200) diff --git a/quantifiedcode/settings/default.yml b/quantifiedcode/settings/default.yml index cb7aa70..ff04851 100755 --- a/quantifiedcode/settings/default.yml +++ b/quantifiedcode/settings/default.yml @@ -2,10 +2,10 @@ backend: url: /api # by default, we use an in-memory instance of SQLite for testing. - db_url: 'postgresql://qc:password@db/quantified' + db_url: 'postgresql+psycopg2://qc:password@db/quantified' db_url_test: 'sqlite:///qc_test.sqlite' paths: - repositories: "data/repositories" + git_repositories: "data/repositories" tasks: "data/tasks" celery: config: @@ -15,8 +15,8 @@ backend: timezone: Europe/Oslo enable_utc: true worker_hijack_root_logger: false - broker_url: 'amqp://guest:guest@rabbitmq:5672/' - result_backend: 'amqp://guest:guest@rabbitmq:5672/' + broker_url: 'redis://redis:6379/' + result_backend: 'redis://redis:6379/' task_default_queue: tasks task_queues: - {name: tasks, routing_key: 'task'}