Skip to content

Commit bde8312

Browse files
authored
Merge pull request #17 from fossology/fix/patent-not-available
Fix: use **kwargs for custom fossology agents
2 parents bb1b6da + be6caaa commit bde8312

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

fossology/__init__.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import requests
77
from datetime import date, timedelta
88

9-
from .obj import Agents, User, SearchTypes
9+
from .obj import Agents, User, TokenScope, SearchTypes
1010
from .folders import Folders
1111
from .uploads import Uploads
1212
from .jobs import Jobs
@@ -18,23 +18,30 @@
1818

1919

2020
def fossology_token(
21-
url, username, password, token_name, token_scope, token_expire=None
21+
url, username, password, token_name, token_scope=TokenScope.READ, token_expire=None
2222
):
2323
"""Generate an API token using username/password
2424
2525
API endpoint: POST /tokens
2626
27+
:Example:
28+
29+
>>> from fossology import fossology_token
30+
>>> from fossology.obj import TokenScope
31+
>>> token = fossology_token("https://fossology.example.com", "Me", "MyPassword", "MyToken")
32+
33+
2734
:param url: the URL of the Fossology server
2835
:param username: name of the user the token will be generated for
2936
:param password: the password of the user
3037
:param name: the name of the token
31-
:param scope: the scope of the token
38+
:param scope: the scope of the token (default: READ)
3239
:param expire: the expire date of the token (default max. 30 days)
3340
:type url: string
3441
:type username: string
3542
:type password: string
3643
:type name: string
37-
:type scope: string
44+
:type scope: TokenScope (default TokenScope.READ)
3845
:type expire: string, e.g. 2019-12-25
3946
:return: the new token
4047
:rtype: string
@@ -70,7 +77,7 @@ class Fossology(Folders, Uploads, Jobs, Report):
7077
7178
:Example:
7279
73-
>>> from fossology.api import Fossology
80+
>>> from fossology import Fossology
7481
>>> foss = Fossology(FOSS_URL, FOSS_TOKEN, username)
7582
7683
.. note::

fossology/jobs.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ def schedule_jobs(self, folder, upload, spec):
8383
>>> "nomos": True,
8484
>>> "ojo": True,
8585
>>> "package": True,
86-
>>> "patent": True,
8786
>>> },
8887
>>> "decider": {
8988
>>> "nomos_monk": True,

fossology/obj.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class Agents(object):
7575
:param nomos: run nomos agent on every upload
7676
:param ojo: run ojo agent on every upload
7777
:param package: run package agent on every upload
78-
:param patent: run patent agent on every upload
78+
:param **kwargs: handle any other agent provided by the fossology instance
7979
:type bucket: boolean
8080
:type copyright_email_author: boolean
8181
:type ecc: boolean
@@ -85,7 +85,7 @@ class Agents(object):
8585
:type nomos: boolean
8686
:type ojo: boolean
8787
:type package: boolean
88-
:type patent: boolean
88+
:type **kwargs: key word argument
8989
"""
9090

9191
def __init__(
@@ -99,7 +99,7 @@ def __init__(
9999
nomos,
100100
ojo,
101101
package,
102-
patent,
102+
**kwargs,
103103
):
104104
self.bucket = bucket
105105
self.copyright_email_author = copyright_email_author
@@ -110,15 +110,16 @@ def __init__(
110110
self.nomos = nomos
111111
self.ojo = ojo
112112
self.package = package
113-
self.patent = patent
113+
for key, value in kwargs.items():
114+
self.additional_agents = {key: value}
114115

115116
def to_dict(self):
116117
"""Get a directory with the agent configuration
117118
118119
:return: the agents configured for the current user
119120
:rtype: dict
120121
"""
121-
agents = {
122+
generic_agents = {
122123
"bucket": self.bucket,
123124
"copyright_email_author": self.copyright_email_author,
124125
"ecc": self.ecc,
@@ -128,8 +129,12 @@ def to_dict(self):
128129
"nomos": self.nomos,
129130
"ojo": self.ojo,
130131
"package": self.package,
131-
"patent": self.patent,
132132
}
133+
try:
134+
agents = {**generic_agents, **self.additional_agents}
135+
except AttributeError:
136+
agents = generic_agents
137+
133138
return agents
134139

135140
@classmethod

0 commit comments

Comments
 (0)