Skip to content

Commit

Permalink
PYAPI-26 PEP8
Browse files Browse the repository at this point in the history
  • Loading branch information
astromatt committed Mar 13, 2015
1 parent e698ef9 commit b931477
Show file tree
Hide file tree
Showing 16 changed files with 184 additions and 171 deletions.
Empty file removed MANIFEST.in
Empty file.
2 changes: 1 addition & 1 deletion PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: atlassian-python-api
Version: 0.7.1
Version: 0.7.10
Author: Matt Harasymczuk
Author-email: code at mattagile com
Maintainer: Matt Harasymczuk
Expand Down
11 changes: 7 additions & 4 deletions atlassian/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import logging
import requests


log = logging.getLogger("atlassian")


Expand All @@ -23,7 +22,8 @@ def log_curl_debug(self, method, path, headers={}, data=None, level=logging.DEBU
url='{0}{1}'.format(self.url, path))
log.log(level=level, msg=message)

def request(self, method='GET', path='/', headers={'Content-Type': 'application/json', 'Accept': 'application/json'}, data=None):
def request(self, method='GET', path='/',
headers={'Content-Type': 'application/json', 'Accept': 'application/json'}, data=None):
self.log_curl_debug(method, path, headers, data)
response = requests.request(
method=method,
Expand All @@ -35,8 +35,9 @@ def request(self, method='GET', path='/', headers={'Content-Type': 'application/
if response.status_code != 200:
self.log_curl_debug(method, path, headers, data, level=logging.WARNING)
log.warning(response.json())
response.raise_for_status()
log.debug('Received: {0}'.format(response.json()))
response.raise_for_status()
else:
log.debug('Received: {0}'.format(response.json()))
return response

def get(self, path, headers={'Content-Type': 'application/json', 'Accept': 'application/json'}):
Expand All @@ -56,3 +57,5 @@ def delete(self, path, headers={'Content-Type': 'application/json', 'Accept': 'a
from .jira import Jira
from .stash import Stash
from .portfolio import Portfolio

__all__ = ['Confluence', 'Jira', 'Stash', 'Portfolio']
42 changes: 21 additions & 21 deletions atlassian/confluence.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@
from atlassian import AtlassianRestAPI


log = logging.getLogger("atlassian.confluence")
log = logging.getLogger('atlassian.confluence')


class Confluence(AtlassianRestAPI):

def create_page(self, space, parent_id, title, body):
return self.post("/rest/api/content/", data={
"type": "page",
"ancestors": [{"type": "page", "id": parent_id}],
"title": title,
"space": {"key": space},
"body": {"storage": {
"value": body,
"representation": "storage"}}})
return self.post('/rest/api/content/', data={
'type': 'page',
'ancestors': [{'type': 'page', 'id': parent_id}],
'title': title,
'space': {'key': space},
'body': {'storage': {
'value': body,
'representation': 'storage'}}})

def history(self, page_id):
return self.get("/rest/api/content/{0}/history".format(page_id))
return self.get('/rest/api/content/{0}/history'.format(page_id))

def update_page(self, parent_id, page_id, title, body, type="page",):
version = self.history(page_id)["lastUpdated"]["number"] + 1
return self.put("/rest/api/content/{0}".format(page_id), data={
"id": page_id,
"type": type,
"ancestors": [{"type": "page", "id": parent_id}],
"title": title,
"body": {"storage": {
"value": body,
"representation": "storage"}},
"version": {"number": version}})
def update_page(self, parent_id, page_id, title, body, type='page',):
version = self.history(page_id)['lastUpdated']['number'] + 1
return self.put('/rest/api/content/{0}'.format(page_id), data={
'id': page_id,
'type': type,
'ancestors': [{'type': 'page', 'id': parent_id}],
'title': title,
'body': {'storage': {
'value': body,
'representation': 'storage'}},
'version': {'number': version}})
42 changes: 21 additions & 21 deletions atlassian/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,49 @@
from atlassian import AtlassianRestAPI


log = logging.getLogger("atlassian.jira")
log = logging.getLogger('atlassian.jira')


class Jira(AtlassianRestAPI):

def reindex_status(self):
return self.get("/rest/api/2/reindex")
return self.get('/rest/api/2/reindex')

def reindex(self):
return self.post("/rest/api/2/reindex")
return self.post('/rest/api/2/reindex')

def jql(self, jql):
return self.get("/rest/api/2/search?jql={0}&maxResults=999999".format(jql))
def jql(self, jql, maxresults=999999):
return self.get('/rest/api/2/search?jql={0}&maxResults={1}'.format(jql, maxresults))

def projects(self):
return self.get("/rest/api/2/project")
return self.get('/rest/api/2/project')

def user(self, username):
return self.get("/rest/api/2/user?username=%s" % username)
return self.get('/rest/api/2/user?username={0}'.format(username))

def project(self, key):
return self.get("/rest/api/2/project/{0}".format(key))
return self.get('/rest/api/2/project/{0}'.format(key))

def issue(self, key):
return self.get("/rest/api/2/issue/{0}".format(key))
return self.get('/rest/api/2/issue/{0}'.format(key))

def update_issue_field(self, key, fields):
return self.put("/rest/api/2/issue/{0}".format(key), data={"fields": fields})
return self.put('/rest/api/2/issue/{0}'.format(key), data={'fields': fields})

def project_leaders(self):
for project in self.projects():
key = project["key"]
key = project['key']
project_data = self.project(key)
lead = self.user(project_data["lead"]["key"])
lead = self.user(project_data['lead']['key'])
yield {
"project_key": key,
"project_name": project["name"],
"lead_name": lead["displayName"],
"lead_key": lead["key"],
"lead_email": lead["emailAddress"]}
'project_key': key,
'project_name': project['name'],
'lead_name': lead['displayName'],
'lead_key': lead['key'],
'lead_email': lead['emailAddress']}

def rename_sprint(self, sprint_id, name, start_date, end_date):
return self.put("/rest/greenhopper/1.0/sprint/{0}".format(sprint_id), data={
"name": name,
"startDate": start_date,
"endDate": end_date})
return self.put('/rest/greenhopper/1.0/sprint/{0}'.format(sprint_id), data={
'name': name,
'startDate': start_date,
'endDate': end_date})
57 changes: 31 additions & 26 deletions atlassian/portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,48 @@
from atlassian import AtlassianRestAPI


log = logging.getLogger("atlassian.portfolio")
log = logging.getLogger('atlassian.portfolio')


class Portfolio(AtlassianRestAPI):

def plan(self, portfolio_id):
return self.get('/rest/roadmap/1.0/plans/{0}.json'.format(portfolio_id))

def stages(self, portfolio_id):
return self.get('/rest/roadmap/1.0/plans/{0}/stages.json'.format(portfolio_id))
def plan(self, plan_id):
return self.get('/rest/roadmap/1.0/plans/{0}.json'.format(plan_id))

def teams(self, portfolio_id):
return self.get('/rest/roadmap/1.0/plans/{0}/teams.json'.format(portfolio_id))
def stages(self, plan_id):
return self.get('/rest/roadmap/1.0/plans/{0}/stages.json'.format(plan_id))

def config(self, portfolio_id):
return self.get('/rest/roadmap/1.0/plans/{0}/config.json'.format(portfolio_id))
def teams(self, plan_id):
return self.get('/rest/roadmap/1.0/plans/{0}/teams.json'.format(plan_id))

def persons(self, portfolio_id):
return self.get('/rest/roadmap/1.0/plans/{0}/persons.json'.format(portfolio_id))
def config(self, plan_id):
return self.get('/rest/roadmap/1.0/plans/{0}/config.json'.format(plan_id))

def streams(self, portfolio_id):
return self.get('/rest/roadmap/1.0/plans/{0}/streams.json'.format(portfolio_id))
def persons(self, plan_id):
return self.get('/rest/roadmap/1.0/plans/{0}/persons.json'.format(plan_id))

def releases(self, portfolio_id):
return self.streams(portfolio_id)
def streams(self, plan_id):
return self.get('/rest/roadmap/1.0/plans/{0}/streams.json'.format(plan_id))

def themes(self, portfolio_id):
return self.get('/rest/roadmap/1.0/plans/{0}/themes.json'.format(portfolio_id))
def releases(self, plan_id):
return self.streams(plan_id)

def state(self, portfolio_id, plan_version):
return self.get('/rest/roadmap/1.0/scheduling/{0}/state.json?planVersion={1}'.format(portfolio_id, plan_version))
def themes(self, plan_id):
return self.get('/rest/roadmap/1.0/plans/{0}/themes.json'.format(plan_id))

def filter(self, portfolio_id, plan_version):
return self.get('/rest/roadmap/1.0/plans/{0}/workitems/filter.json?planVersion={1}'.format(portfolio_id, plan_version))
def state(self, plan_id, plan_version):
return self.get('/rest/roadmap/1.0/scheduling/{0}/state.json?planVersion={1}'.format(plan_id, plan_version))

def stage_name(self, portfolio_id, stage_id):
return [stage['title'] for stage in self.stages(portfolio_id)['collection'] if stage['id'] == str(stage_id)][0]
def filter(self, plan_id, plan_version, limit=500):
url = '/rest/roadmap/1.0/plans/{0}/workitems/filter.json?planVersion={1}'.format(plan_id, plan_version)
return self.post(url, data={'limit': limit})

def estimates_dict(self, portfolio_id, estimates):
return {self.stage_name(portfolio_id, stage['targetId']): stage['value'] for stage in estimates['stages']}
def dependencies(self, workitem_id, plan_version):
url = '/rest/roadmap/1.0/workitems/{0}/dependencies.json?planVersion={1}'.format(workitem_id, plan_version)
return self.get(url)

def stage_name(self, plan_id, stage_id):
return [stage['title'] for stage in self.stages(plan_id)['collection'] if stage['id'] == str(stage_id)][0]

def estimates_dict(self, plan_id, estimates):
return {self.stage_name(plan_id, stage['targetId']): stage['value'] for stage in estimates['stages']}
24 changes: 13 additions & 11 deletions atlassian/stash.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from atlassian import AtlassianRestAPI


log = logging.getLogger("atlassian.stash")
log = logging.getLogger('atlassian.stash')


class Stash(AtlassianRestAPI):
Expand All @@ -11,20 +11,21 @@ def project_list(self):
return self.get('/rest/api/1.0/projects')['values']

def project(self, key):
return self.get('/rest/api/1.0/projects/{}'.format(key))['values']
return self.get('/rest/api/1.0/projects/{0}'.format(key))['values']

def project_users(self, key):
return self.get('/rest/api/1.0/projects/{}/permissions/users?limit=99999'.format(key))['values']
def project_users(self, key, limit=99999):
return self.get('/rest/api/1.0/projects/{0}/permissions/users?limit={1}'.format(key, limit))['values']

def project_users_with_administrator_permissions(self, key):
project_administrators = [user['user'] for user in self.project_users(key) if user['permission'] == 'PROJECT_ADMIN']
project_administrators = [user['user'] for user in self.project_users(key)
if user['permission'] == 'PROJECT_ADMIN']
for group in self.project_groups_with_administrator_permissions(key):
for user in self.group_members(group):
project_administrators.append(user)
return project_administrators

def project_groups(self, key):
return self.get('/rest/api/1.0/projects/{}/permissions/groups?limit=99999'.format(key))['values']
def project_groups(self, key, limit=99999):
return self.get('/rest/api/1.0/projects/{0}/permissions/groups?limit={1}'.format(key, limit))['values']

def project_groups_with_administrator_permissions(self, key):
return [group['group']['name'] for group in self.project_groups(key) if group['permission'] == 'PROJECT_ADMIN']
Expand All @@ -36,13 +37,14 @@ def project_summary(self, key):
'users': self.project_users(key),
'groups': self.project_groups(key)}

def group_members(self, group):
return self.get('/rest/api/1.0/admin/groups/more-members?context={}&limit=99999'.format(group))['values']
def group_members(self, group, limit=99999):
return self.get('/rest/api/1.0/admin/groups/more-members?context={0}&limit={1}'.format(group, limit))['values']

def all_project_administrators(self):
for project in self.project_list():
log.info("Processing project: {0} - {1}".format(project['key'], project['name']))
log.info('Processing project: {0} - {1}'.format(project['key'], project['name']))
yield {
'project_key': project['key'],
'project_name': project['name'],
'project_administrators': [{'email': x['emailAddress'], 'name': x['displayName']} for x in self.project_users_with_administrator_permissions(project['key'])]}
'project_administrators': [{'email': x['emailAddress'], 'name': x['displayName']}
for x in self.project_users_with_administrator_permissions(project['key'])]}
12 changes: 6 additions & 6 deletions examples/confluence-create-page.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@


confluence = Confluence(
url="http://localhost:8090",
username="admin",
password="admin")
url='http://localhost:8090',
username='admin',
password='admin')

status = confluence.create_page(
space="DEMO",
title="This is the title",
body="This is the body")
space='DEMO',
title='This is the title',
body='This is the body')

pprint(status)
10 changes: 5 additions & 5 deletions examples/confluence-update-page.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@


confluence = Confluence(
url="http://localhost:8090",
username="admin",
password="admin")
url='http://localhost:8090',
username='admin',
password='admin')

status = confluence.update_page(
page_id=123456,
title="This is the new title",
body="This is the new body")
title='This is the new title',
body='This is the new body')

pprint(status)
8 changes: 4 additions & 4 deletions examples/jira-jql-query.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
from atlassian import Jira


JQL = "project = DEMO AND status NOT IN (Closed, Resolved) ORDER BY issuekey"
JQL = 'project = DEMO AND status NOT IN (Closed, Resolved) ORDER BY issuekey'

jira = Jira(
url="http://localhost:8080",
username="admin",
password="admin")
url='http://localhost:8080',
username='admin',
password='admin')

data = jira.jql(JQL)
pprint(data)
20 changes: 10 additions & 10 deletions examples/jira-project-administrators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
from atlassian import Jira


logging.basicConfig(level=logging.DEBUG, format="[%(asctime).19s] [%(levelname)s] %(message)s")
logging.getLogger("requests").setLevel(logging.WARNING)
log = logging.getLogger("jira-projects-administrators")
logging.basicConfig(level=logging.DEBUG, format='[%(asctime).19s] [%(levelname)s] %(message)s')
logging.getLogger('requests').setLevel(logging.WARNING)
log = logging.getLogger('jira-projects-administrators')


jira = Jira(
url="http://localhost:8080",
username="admin",
password="admin")
url='http://localhost:8080',
username='admin',
password='admin')

html = "<table><tr><th>Project Key</th><th>Project Name</th><th>Leader</th><th>Email</th></tr>"
html = '<table><tr><th>Project Key</th><th>Project Name</th><th>Leader</th><th>Email</th></tr>'

for data in jira.project_leaders():
log.info("{project_key} leader is {lead_name} <{lead_email}>".format(**data))
html += "<tr><td>{project_key}</td><td>{project_name}<td></td>{lead_name}<td></td><a href='mailto:{lead_email}'>{lead_email}</a></td></tr>".format(**data)
log.info('{project_key} leader is {lead_name} <{lead_email}>'.format(**data))
html += '<tr><td>{project_key}</td><td>{project_name}<td></td>{lead_name}<td></td><a href="mailto:{lead_email}">{lead_email}</a></td></tr>'.format(**data)

html += "</table><p></p><p></p>"
html += '</table><p></p><p></p>'

print(html)
Loading

0 comments on commit b931477

Please sign in to comment.