Skip to content
This repository has been archived by the owner on Feb 15, 2023. It is now read-only.

Management command #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Empty file.
42 changes: 42 additions & 0 deletions django_redmine/management/commands/list_projects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2013 Rodolphe Quiédeville <[email protected]>
#
# 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
"""
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'))

42 changes: 42 additions & 0 deletions django_redmine/management/commands/list_trackers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2013 Rodolphe Quiédeville <[email protected]>
#
# 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'))

36 changes: 36 additions & 0 deletions django_redmine/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
'<?xml version="1.0" ?><tracker/>'
"""
RedmineResource.__init__(self, None, tracker, 'tracker')


class RedmineIssue(RedmineResource):
def __init__(self, issue = None):
"""
Expand Down Expand Up @@ -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):
Expand Down