From 392b8c9a6f202cff37b3ff463f019cf26cd14052 Mon Sep 17 00:00:00 2001 From: Justin Forest Date: Tue, 11 Dec 2012 00:39:05 +0400 Subject: [PATCH] Support for megaplan.ru Requires python-megaplan to work; if not installed, megaplan won't be supported. --- bugwarrior/services/__init__.py | 7 ++++ bugwarrior/services/mplan.py | 60 +++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 bugwarrior/services/mplan.py diff --git a/bugwarrior/services/__init__.py b/bugwarrior/services/__init__.py index 1f37be648..be243744b 100644 --- a/bugwarrior/services/__init__.py +++ b/bugwarrior/services/__init__.py @@ -99,6 +99,13 @@ def get_owner(self, issue): } +try: + from mplan import MegaplanService + SERVICES['megaplan'] = MegaplanService +except ImportError: + pass + + def aggregate_issues(conf): """ Return all issues from every target. diff --git a/bugwarrior/services/mplan.py b/bugwarrior/services/mplan.py new file mode 100644 index 000000000..2762469cf --- /dev/null +++ b/bugwarrior/services/mplan.py @@ -0,0 +1,60 @@ +from twiggy import log + +from bugwarrior.services import IssueService +from bugwarrior.config import die + +import datetime +import urllib2 +import json + +import megaplan + + +class MegaplanService(IssueService): + def __init__(self, *args, **kw): + super(MegaplanService, self).__init__(*args, **kw) + + self.hostname = self.config.get(self.target, 'hostname') + _login = self.config.get(self.target, 'login') + _password = self.config.get(self.target, 'password') + + self.client = megaplan.Client(self.hostname) + self.client.authenticate(_login, _password) + + self.project_name = self.hostname + if self.config.has_option(self.target, "project_name"): + self.project_name = self.config.get(self.target, "project_name") + + @classmethod + def validate_config(cls, config, target): + for k in ('login', 'password', 'hostname'): + if not config.has_option(target, k): + die("[%s] has no '%s'" % (target, k)) + + IssueService.validate_config(config, target) + + def get_issue_id(self, issue): + if issue["Id"] > 1000000: + return issue["Id"] - 1000000 + return issue["Id"] + + def get_issue_title(self, issue): + parts = issue["Name"].split("|") + return parts[-1].strip() + + def get_issue_url(self, issue): + return "https://%s/%s/card/" % (self.hostname, issue["Id"]) + + def issues(self): + issues = self.client.get_actual_tasks() + log.debug(" Found {0} total.", len(issues)) + + return [dict( + description=self.description( + self.get_issue_title(issue), + self.get_issue_url(issue), + self.get_issue_id(issue), cls="issue", + ), + project=self.project_name, + priority=self.default_priority, + ) for issue in issues]