Skip to content

Commit

Permalink
Merge pull request #2 from philips-forks/frups-csv
Browse files Browse the repository at this point in the history
csv support and bug fixes
  • Loading branch information
MartinBarkerPhilips authored Oct 7, 2022
2 parents 26f8a65 + f5fd5bd commit 4c983ad
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 18 deletions.
129 changes: 129 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
rtcclient
=========

.. image:: https://readthedocs.org/projects/rtcclient/badge/?version=latest
:target: https://readthedocs.org/projects/rtcclient

.. image:: https://img.shields.io/pypi/v/rtcclient.svg
:target: https://pypi.python.org/pypi/rtcclient

.. image:: https://img.shields.io/pypi/dm/rtcclient.svg
:target: https://pypi.python.org/pypi/rtcclient

.. image:: https://api.travis-ci.org/dixudx/rtcclient.svg?branch=master
:target: https://pypi.python.org/pypi/rtcclient


A Python-based Client/API for Rational Team Concert (RTC)

About this library
------------------

IBM® Rational Team Concert™, is built on the Jazz platform, allowing
application development teams to use one tool to plan across teams, code,
run standups, plan sprints, and track work. For more info, please refer
to here_.

.. _here: http://www.ibm.com/developerworks/downloads/r/rtc/

**IMPORTANT NOTE: This is NOT an official-released Python-based RTC Client.**

This library can help you:

* Interacts with an RTC server to retrieve objects which contain the detailed information/configuration, including **Project Areas**, **Team Areas**, **Workitems** and etc;
* Creates all kinds of **Workitems** through self-customized templates or copies from some existing **Workitems**;
* Performs some actions on the retrieved **Workitems**, including get/add **Comments**, get/add/remove **Subscribers**/**Children**/**Parent**, get/upload **Attachments** and etc;
* Query **Workitems** using specified filtered rules or directly from your saved queries;
* Logs all the activities and messages during your operation;


Python & Rational Team Concert Versions
---------------------------------------

The project has been tested against ``Rational Team Concert`` **5.0.1**,
**5.0.2** and **6.0** on Python 2.6, 2.7 and 3.3.


Important Links
---------------

Support and bug-reports:
https://github.com/dixudx/rtcclient/issues?q=is%3Aopen+sort%3Acomments-desc

Project source code: https://github.com/dixudx/rtcclient

Project documentation: https://readthedocs.org/projects/rtcclient/


Installation
------------

To install rtcclient, simply:

.. code-block:: bash
$ pip install rtcclient
Example
-------

RTCClient is intended to map the objects in RTC (e.g. Project Areas,
Team Areas, Workitems) into easily managed Python objects:

.. code-block:: python
>>> from rtcclient.utils import setup_basic_logging
>>> from rtcclient import RTCClient
# you can remove this if you don't need logging
# default debug logging for console output
>>> setup_basic_logging()
# url ends with jazz
>>> url = "https://your_domain:9443/jazz"
>>> username = "your_username"
>>> password = "your_password"
# if your rtc server is behind a proxy, remember to set "proxies"
# explicitly. detailed can be found in quick start of the doc
# if your url ends with ccm, set ends_with_jazz to False
# refer to issue #68 for detailed explanation
>>> myclient = RTCClient(url, username, password, ends_with_jazz=True)
# it will be faster if returned properties is specified
# see in below query example
>>> wk = myclient.getWorkitem(123456) # get a workitem whose id is 123456
# get all workitems
# If both projectarea_id and projectarea_name are None, all the workitems
# in all ProjectAreas will be returned
>>> workitems_list = myclient.getWorkitems(projectarea_id=None,
projectarea_name=None)
>>> myquery = myclient.query # query class
>>> projectarea_name = "your_projectarea_name"
# customize your query string
# below query string means: query all the workitems with title "use case 1"
>>> myquerystr = 'dc:title="use case 1"'
# specify the returned properties: title, id, state, owner
# This is optional. All properties will be returned if not specified
>>> returned_prop = "dc:title,dc:identifier,rtc_cm:state,rtc_cm:ownedBy"
>>> queried_wis = myquery.queryWorkitems(query_str=myquerystr,
projectarea_name=projectarea_name,
returned_properties=returned_prop)
Testing
-------

Using a virtualenv is recommended. Setuptools will automatically fetch
missing test dependencies.

If you have installed the tox_ on your system already, you can run
the tests using pytest_ with the following command:

.. _tox: https://pypi.python.org/pypi/tox
.. _pytest: http://pytest.org/latest/

.. code-block:: bash
virtualenv
source .venv/bin/active
(venv) tox -e py27
(venv) tox -e py33
(venv) tox -e pep8
42 changes: 24 additions & 18 deletions rtcclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from rtcclient.query import Query
import six
from rtcclient import requests
from multiprocessing.pool import ThreadPool as Pool
import urllib.parse
import pprint

Expand Down Expand Up @@ -991,15 +992,15 @@ def getWorkitems(self, projectarea_id=None, projectarea_name=None,
return None
return workitems_list

def getChildrenInfo(self, parent_id):
def getChildrenInfo(self, parent_id, rtc_url):
child_ids = []

headers = copy.deepcopy(self.headers)
verify=False
proxies=None
timeout=60
kwargs={}
url="https://rtcus1.ta.philips.com/ccm/oslc/workitems/"+parent_id+"/rtc_cm:com.ibm.team.workitem.linktype.parentworkitem.children"
url=rtc_url+"/oslc/workitems/"+parent_id+"/rtc_cm:com.ibm.team.workitem.linktype.parentworkitem.children"

requests.packages.urllib3.disable_warnings()
requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS += ':HIGH:!DH:!aNULL'
Expand Down Expand Up @@ -1201,15 +1202,16 @@ def getFeaturePlannedForValue(self, url):
retVal = raw_data[root_key].get("dc:identifier")
return retVal

def getUserEmail(self, user_id):
def getUserEmail(self, user_id, rtc_url):
print("getUserEmail user_id="+user_id+", rtc_url="+rtc_url)
userEmail = ""

headers = copy.deepcopy(self.headers)
verify=False
proxies=None
timeout=60
kwargs={}
url="https://rtcus1.ta.philips.com/ccm/oslc/users/"+user_id
url=rtc_url+"/oslc/users/"+user_id

requests.packages.urllib3.disable_warnings()
requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS += ':HIGH:!DH:!aNULL'
Expand All @@ -1228,11 +1230,15 @@ def getUserEmail(self, user_id):
response.raise_for_status()

#retreive user email from xml
raw_data = xmltodict.parse(response.content)
root_key = list(raw_data.keys())[0]
userEmail = raw_data[root_key].get("rtc_cm:emailAddress")
#url decode and trim 'mailto:'
userEmail = urllib.parse.unquote(userEmail).replace('mailto:', '')
try:
raw_data = xmltodict.parse(response.content)
root_key = list(raw_data.keys())[0]
userEmail = raw_data[root_key].get("rtc_cm:emailAddress")
#url decode and trim 'mailto:'
userEmail = urllib.parse.unquote(userEmail).replace('mailto:', '')
except Exception as e:
print("error getting user email ", e)
userEmail=""

return userEmail

Expand Down Expand Up @@ -1461,7 +1467,7 @@ def _pre_get_resource(self, projectarea_id=None, projectarea_name=None):

def _get_paged_resources(self, resource_name, projectarea_id=None,
workitem_id=None, customized_attr=None,
page_size="100", archived=False,
page_size="10", archived=False,
returned_properties=None, filter_rule=None):
# TODO: multi-thread

Expand Down Expand Up @@ -1633,14 +1639,14 @@ def _get_paged_resources(self, resource_name, projectarea_id=None,
break

# iterate all the entries
for entry in entries:
resource = self._handle_resource_entry(resource_name,
entry,
projectarea_url=pa_url,
archived=archived,
filter_rule=filter_rule)
if resource is not None:
resources_list.append(resource)
with Pool() as p:
resources_list_new = list(
filter(
None,
p.starmap(self._handle_resource_entry,
[(resource_name, entry, pa_url, archived,
filter_rule) for entry in entries])))
resources_list = resources_list + resources_list_new

# find the next page
url_next = raw_data.get('oslc_cm:Collection').get('@oslc_cm:next')
Expand Down

0 comments on commit 4c983ad

Please sign in to comment.