Skip to content

Commit

Permalink
Merge pull request #17 from galaxy-genome-annotation/ggasync
Browse files Browse the repository at this point in the history
Move here some code from galaxy tool
  • Loading branch information
abretaud authored Nov 4, 2019
2 parents 04cccf2 + d38b6dc commit a0d392b
Show file tree
Hide file tree
Showing 54 changed files with 4,325 additions and 82 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ docs/_build

# test harness
test_harness.py

apollo_shared_dir
54 changes: 39 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,49 @@
language: python
os: linux

python:
- '2.7'
- '3.5'
- '2.7'
- '3.6'

jobs:
include:
- stage: lint
install:
- pip install -U pip flake8
script:
- flake8 apollo --ignore=E501,W503 --exclude=arrow/commands/,scripts/

- stage: deploy
install: skip
script: echo "Deploying to Pypi"
deploy:
provider: pypi
username: erasche
password:
secure: odHEB/SR+BddRI0qFJU3d57w0J3OjIHLLmoxv5rH46/R6WDBJ1Dqp85rbIEfjTsLEG6bd04kdNSUh/kFB1O8TAOjthixHYNij5qgAfIXYpCTCfoFd/+sqtLl2UddlkO/d895+QV3nEDWSSZuAbys3kBvzVBqlcZ1fpcBr7dyynUJ2hzjD/rq2F475ClKNAA6ICarYZErSu6RHprLieQpUYWKfielXjhMBtWwrJcrwYsdi2bIhdirGpddB5Qi8MZ8BtSpDojpSWBu5O59LLpJhO9JLktO/TfdOSRzZwCAthqbxGvGgpp9x4D5IpTL19uiY5D2jF13nvhYs5Vf2i75FoAGplJ9snOkYE52JJ3/XtqOv22no9P7wSIUJkA/P3DabzqfxlcTdjLtS2v53YehNHL/1ZtrI95y3d37aw9UUKv9KZzz3ostGoAoCIV9YMzK9NrOPeBRRYFzqsrZcOy2yugAawuH/78w9dproeoO/9gFakoLzbObq1gLX10cdnHW4K1qLBE+tasTrXjE5OCa+svBhIMgvk8c+vX/ISvci/pvc1St+prek40vxZi7dIfoqK+iyoACn9RsrdwjSm4Woe058L99wd0FnLaMiLrQNe3h/AHZDQJ5EXGXI0l5egAlJHX/CfxcFekEZS66merlvFUtqsuetd+XIWmAroZq9g0=
on:
tags: true
distributions: "sdist bdist_wheel"
repo: galaxy-genome-annotation/python-apollo

install:
- pip install -U pip setuptools nose

script:
- pip install -U pip setuptools
- pip install -U flake8
- flake8 apollo --ignore=E501,W504 --exclude=arrow/commands/,scripts/
- python setup.py install
deploy:
provider: pypi
user: erasche
password:
secure: odHEB/SR+BddRI0qFJU3d57w0J3OjIHLLmoxv5rH46/R6WDBJ1Dqp85rbIEfjTsLEG6bd04kdNSUh/kFB1O8TAOjthixHYNij5qgAfIXYpCTCfoFd/+sqtLl2UddlkO/d895+QV3nEDWSSZuAbys3kBvzVBqlcZ1fpcBr7dyynUJ2hzjD/rq2F475ClKNAA6ICarYZErSu6RHprLieQpUYWKfielXjhMBtWwrJcrwYsdi2bIhdirGpddB5Qi8MZ8BtSpDojpSWBu5O59LLpJhO9JLktO/TfdOSRzZwCAthqbxGvGgpp9x4D5IpTL19uiY5D2jF13nvhYs5Vf2i75FoAGplJ9snOkYE52JJ3/XtqOv22no9P7wSIUJkA/P3DabzqfxlcTdjLtS2v53YehNHL/1ZtrI95y3d37aw9UUKv9KZzz3ostGoAoCIV9YMzK9NrOPeBRRYFzqsrZcOy2yugAawuH/78w9dproeoO/9gFakoLzbObq1gLX10cdnHW4K1qLBE+tasTrXjE5OCa+svBhIMgvk8c+vX/ISvci/pvc1St+prek40vxZi7dIfoqK+iyoACn9RsrdwjSm4Woe058L99wd0FnLaMiLrQNe3h/AHZDQJ5EXGXI0l5egAlJHX/CfxcFekEZS66merlvFUtqsuetd+XIWmAroZq9g0=
on:
tags: true
distributions: sdist bdist_wheel
repo: galaxy-genome-annotation/python-apollo
- python setup.py install
- export ARROW_GLOBAL_CONFIG_PATH=`pwd`/test-data/arrow.yml
- ./bootstrap_apollo.sh
- python setup.py nosetests

notifications:
webhooks:
urls:
- https://webhooks.gitter.im/e/dd56606ea08bece475e7
on_success: change
on_failure: always
on_start: never

stages:
- lint
- test
- deploy
23 changes: 21 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@ Apollo API Library
Apollo is a Python library for interacting with
`Apollo <https://github.com/gmod/apollo/>`__

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

.. code-block:: shell
pip install apollo
Examples
--------

Example code to create a new organism and add yourself in the permission list:

.. code:: python
from apollo import ApolloInstance
Expand All @@ -39,7 +48,15 @@ Examples
read=True,
)
Or with the new Arrow client:
If you have already created an Arrow config file (with command `arrow init`),
you can also get an ApolloInstance without writing credentials explicitely:

.. code:: python
from arrow.apollo import get_apollo_instance
wa = get_apollo_instance()
Or with the Arrow client:

.. code-block:: shell
Expand All @@ -64,8 +81,10 @@ Or with the new Arrow client:
History
-------

- 3.2
- 4.0
- Added support for remote creation/update/deletion of organisms/tracks
- Added support for adding GFF3 in the annotation track
- Added tests
- 3.1
- Added user activate/inactivate
- Added get_creator for user, group and organisms
Expand Down
41 changes: 24 additions & 17 deletions apollo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import os
import logging

from cachetools import TTLCache
from apollo.util import AssertUser
from apollo.exceptions import UnknownUserException
import os

from apollo import (annotations, cannedcomments, cannedkeys,
cannedvalues, groups, io, metrics, organisms,
status, users, remote)
remote, status, users)
from apollo.exceptions import UnknownUserException
from apollo.util import AssertUser

from cachetools import TTLCache

cache = TTLCache(
100, # Up to 100 items
Expand Down Expand Up @@ -57,31 +56,39 @@ def require_user(wa, email):
# If we hit a key error above, indicating that
# we couldn't find the key, we'll simply re-request
# the data
data = wa.users.loadUsers()
data = wa.users.get_users()
userCache[cache_key] = data

return AssertUser([x for x in data if x.username == email])


def accessible_organisms(user, orgs):
def accessible_organisms(user, orgs, permission=None):
"""Get the list of organisms accessible to a user, filtered by `orgs`"""
permission_map = {
x['organism']: x['permissions']
for x in user.organismPermissions
if 'WRITE' in x['permissions'] or
'READ' in x['permissions'] or
'ADMINISTRATE' in x['permissions'] or
user.role == 'ADMIN'
if (permission is not None and permission in x['permissions'])
or (permission is None and ('WRITE' in x['permissions']
or 'READ' in x['permissions']
or 'ADMINISTRATE' in x['permissions']))
or user.role == 'ADMIN'
}

if 'error' in orgs:
if orgs['error'] == "Not authorized for any organisms":
return []
raise Exception("Error received from Apollo server: \"%s\"" % orgs['error'])

return [
(org['commonName'], org['id'], False)
for org in sorted(orgs, key=lambda x: x['commonName'])
if org['commonName'] in permission_map
]
if len(orgs) > 0 and isinstance(orgs[0], dict):
# Received complete org json
return [
org
for org in sorted(orgs, key=lambda x: x['commonName'])
if org['commonName'] in permission_map
]
else:
# Received only a list of commonnames
return [org for org in sorted(orgs) if org in permission_map]


def galaxy_list_groups(trans, *args, **kwargs):
Expand Down
Loading

0 comments on commit a0d392b

Please sign in to comment.