From 33b72ecc687c95df1515746d159aad01c1aa5743 Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Tue, 19 Feb 2013 15:16:39 +0100 Subject: [PATCH 1/3] Add a new management comment to list all projects --- django_redmine/management/__init__.py | 0 .../management/commands/__init__.py | 0 .../management/commands/list_projects.py | 43 +++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 django_redmine/management/__init__.py create mode 100644 django_redmine/management/commands/__init__.py create mode 100644 django_redmine/management/commands/list_projects.py diff --git a/django_redmine/management/__init__.py b/django_redmine/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/django_redmine/management/commands/__init__.py b/django_redmine/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/django_redmine/management/commands/list_projects.py b/django_redmine/management/commands/list_projects.py new file mode 100644 index 0000000..c963759 --- /dev/null +++ b/django_redmine/management/commands/list_projects.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# +# Copyright (c) 2013 Rodolphe Quiédeville +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +""" +List all projects +""" +import logging +from django.conf import settings +from django.core.management.base import BaseCommand +from django_redmine.utils import RedmineClient + +logger = logging.getLogger(__name__) + + +class Command(BaseCommand): + help = 'List all projects' + + def handle(self, *args, **options): + """ + Handle the munin command + """ + r = RedmineClient(settings.REDMINE_URL, + settings.REDMINE_USERNAME, + settings.REDMINE_PASSWORD, + '') + for proj in r.get_projects(): + print "%-3d %s" % (int(proj.get_element('id')), + proj.get_element('name')) + From dc5fb3fd94f257adfde48a81c62d53f81bbc450f Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Tue, 19 Feb 2013 15:18:48 +0100 Subject: [PATCH 2/3] Fiw the wrong license header, mine default is GPL, now the file is licensed under BSD as project --- .../management/commands/list_projects.py | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/django_redmine/management/commands/list_projects.py b/django_redmine/management/commands/list_projects.py index c963759..36c8009 100644 --- a/django_redmine/management/commands/list_projects.py +++ b/django_redmine/management/commands/list_projects.py @@ -2,18 +2,17 @@ # # Copyright (c) 2013 Rodolphe Quiédeville # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the University nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. # """ List all projects From 6d8a526a7c2764e15ad73a454c7e16e035e47f4b Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Tue, 19 Feb 2013 15:29:12 +0100 Subject: [PATCH 3/3] Manage tracker --- .../management/commands/list_trackers.py | 42 +++++++++++++++++++ django_redmine/utils.py | 36 ++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 django_redmine/management/commands/list_trackers.py diff --git a/django_redmine/management/commands/list_trackers.py b/django_redmine/management/commands/list_trackers.py new file mode 100644 index 0000000..54389ac --- /dev/null +++ b/django_redmine/management/commands/list_trackers.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +# +# Copyright (c) 2013 Rodolphe Quiédeville +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the University nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +""" +List all trackers +""" +import logging +from django.conf import settings +from django.core.management.base import BaseCommand +from django_redmine.utils import RedmineClient + +logger = logging.getLogger(__name__) + + +class Command(BaseCommand): + help = 'List all trackers' + + def handle(self, *args, **options): + """ + Handle the munin command + """ + r = RedmineClient(settings.REDMINE_URL, + settings.REDMINE_USERNAME, + settings.REDMINE_PASSWORD, + '') + for track in r.get_trackers(): + print "%-3d %s" % (int(track.get_element('id')), + track.get_element('name')) + diff --git a/django_redmine/utils.py b/django_redmine/utils.py index ebfafd2..0802656 100644 --- a/django_redmine/utils.py +++ b/django_redmine/utils.py @@ -85,6 +85,19 @@ def __init__(self, project = None): """ RedmineResource.__init__(self, None, project, 'project') + +class RedmineTracker(RedmineResource): + def __init__(self, tracker = None): + """ + Redmine tracker representation, tied to the API XML form. + + >>> r = RedmineTracker(None) + >>> r.to_xml() + '' + """ + RedmineResource.__init__(self, None, tracker, 'tracker') + + class RedmineIssue(RedmineResource): def __init__(self, issue = None): """ @@ -116,6 +129,29 @@ def __init__(self, base, user, password, key): self.http.add_credentials(user, password) self.key = key + # ---- Trackers ---- + + def get_trackers(self): + """ + Get a [list] of all trackers + GET $base/trackers.xml + http://www.redmine.org/projects/redmine/wiki/Rest_Trackers + Warning Tracker are considerated as alpha version and available since Redmine 1.3 + + >>> r = RedmineClient('http://redmine.example.com', 'test_username', 'test_password', 'test_key') + >>> p = r.get_trackers() + >>> len(p) > 0 + True + """ + url = "%s/trackers.xml?key=%s" % (self.base, self.key) + response, content = self.http.request(url, "GET") + trackers = [] + trackersRoot = minidom.parseString(content) + trackersList = trackersRoot.documentElement.getElementsByTagName('tracker') + for tracker in trackersList: + trackers.append(RedmineTracker(tracker)) + return trackers + # ---- Projects ---- def get_projects(self):