Skip to content

Commit

Permalink
Merge pull request #100 from fossology/2.0.0-release
Browse files Browse the repository at this point in the history
2.0.0 release
  • Loading branch information
deveaud-m authored Sep 22, 2022
2 parents 86ba9bd + 5b4b4f2 commit 7f525b1
Show file tree
Hide file tree
Showing 22 changed files with 989 additions and 607 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/doc-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
doc-deploy:
name: Deploy document pages
runs-on: ubuntu-latest
container: 'python:3.9-slim'
container: 'python:3.10-slim'
steps:
- name: Install host dependencies
run: |
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/foss_cli_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest

container:
image: python:3.9-slim
image: python:3.10-slim
volumes:
- /tmp:/tmp

Expand Down Expand Up @@ -46,19 +46,20 @@ jobs:
run: |
poetry run coverage run --source=fossology -m pytest tests/test_foss_cli*.py
poetry run coverage report -m
continue-on-error: true

test-last_release:
name: foss_cli tests (Fossology 3.10.0)
name: foss_cli tests (Fossology 4.1.0)
runs-on: ubuntu-latest

container:
image: python:3.9-slim
image: python:3.10-slim
volumes:
- /tmp:/tmp

services:
fossology:
image: fossology/fossology:3.10.0
image: fossology/fossology:4.1.0
ports:
- 8081:80
volumes:
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/fossologytests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest

container:
image: python:3.9-slim
image: python:3.10-slim
volumes:
- /tmp:/tmp

Expand Down Expand Up @@ -47,23 +47,24 @@ jobs:
export API_LATEST=true
poetry run coverage run --source=fossology -m pytest
poetry run coverage report -m
continue-on-error: true
- name: upload codecoverage results only if we are on the repository fossology/fossology-python
if: ${{ github.repository == 'fossology/fossology-python' }}
run: poetry run codecov -t ${{ secrets.CODECOV_TOKEN }}


test-last-release:
name: Integration Tests (Fossology 4.0.0)
name: Integration Tests (Fossology 4.1.0)
runs-on: ubuntu-latest

container:
image: python:3.9-slim
image: python:3.10-slim
volumes:
- /tmp:/tmp

services:
fossology:
image: fossology/fossology:4.0.0
image: fossology/fossology:4.1.0
ports:
- 8081:80
volumes:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/staticchecks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
- 'python:3.7-slim'
- 'python:3.8-slim'
- 'python:3.9-slim'
- 'python:3.10-slim'

container: ${{ matrix.container }}

Expand Down
7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ See `the OpenAPI specification <https://raw.githubusercontent.com/fossology/foss
- 1.2.1 (Fossology 3.10.0)
- 1.3.2 (Fossology 3.11.0)
- 1.4.0 (Fossology 4.0.0)
- 1.4.3 (Fossology 4.1.0)

**NOTE**

Version 2.0.0 of `fossology-python` only supports Fossology API version 1.4.3 onwards because of a breaking change in
the version format returned by the API. Other earlier version of the wrapper support a wider range of API versions,
e.g. 1.5.0 supports Fossology API 1.2.1 to 1.4.0.

Documentation
=============
Expand Down
2 changes: 1 addition & 1 deletion docs-source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
copyright = "2021, Siemens AG"

# The full version, including major/minor/patch tags
release = "1.5.0"
release = "2.0.0"


# -- General configuration ---------------------------------------------------
Expand Down
25 changes: 22 additions & 3 deletions docs-source/sample_workflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ group named clearing is created

Upload File
===========
We first get an example file from our github repository testenvironment and then
upload it to the server.
We first get an example file from our github repository test environment and then
upload it to the server.


>>> filename = "my_base-files_11.tar.xz"
Expand All @@ -124,7 +124,7 @@ upload it to the server.
... description="Test upload via fossology-python lib",
... group=group_name,
... access_level=AccessLevel.PUBLIC,
... )
... )


Start default scan jobs
Expand Down Expand Up @@ -199,3 +199,22 @@ report downloaded...
>>> print(f"report was written to file {name}.") # doctest: +ELLIPSIS
report was written to file...


Delete folder
=============

Cleanup existing folder and all included data.

>>> foss.delete_folder(test_folder)
>>> print(f"Folder {test_folder.name} has been deleted")
Folder AwesomeFossFolder has been deleted


Clean up
========

Cleanup created report and token files

>>> os.unlink(name)
>>> os.unlink(path_to_upload_file)
>>> os.unlink(path_to_token_file)
54 changes: 53 additions & 1 deletion fossology/foss_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def check_get_access_level(level: str):


def needs_later_initialization_of_foss_instance(ctx):
"""Check if lateron a Fossology Instance will be created.
"""Check if later on a Fossology Instance will be created.
:param ctx: click context
:type ctx: click.core.Context
Expand Down Expand Up @@ -580,6 +580,7 @@ def upload_file(
file=upload_file,
description=description if description else "upload via foss-cli",
access_level=the_access_level,
wait_time=10,
)

ctx.obj["UPLOAD"] = the_upload
Expand All @@ -602,6 +603,56 @@ def upload_file(
)


@cli.command("delete_folder")
@click.argument("folder_name")
@click.pass_context
def delete_folder(
ctx: click.core.Context,
folder_name: str,
):
"""The foss_cli delete_folder command."""

logger.debug(f"Try to delete folder {folder_name}")
foss = ctx.obj["FOSS"]

folder = None
for f in foss.list_folders():
if f.name == folder_name:
folder = f
logger.debug(f"Found folder to delete: {folder}")
break

if not folder:
logger.fatal(f"Unable to find folder {folder_name}.")
ctx.exit(1)

foss.delete_folder(folder)
logger.debug(f"Delete command was send to {foss.host} for folder {folder}")


@cli.command("delete_upload")
@click.argument("upload_name")
@click.pass_context
def delete_upload(
ctx: click.core.Context,
upload_name: str,
):
"""The foss_cli folder_id command."""

logger.debug(f"Try to delete upload {upload_name}")
foss = ctx.obj["FOSS"]

upload = None
for u in foss.list_uploads(all_pages=True)[0]:
if u.uploadname == upload_name:
upload = u
logger.debug(f"Found upload to delete: {upload}")
break

foss.delete_upload(upload)
logger.debug(f"Delete command was send to {foss.host} for upload {upload}")


@cli.command("start_workflow")
@click.argument(
"file_name",
Expand Down Expand Up @@ -695,6 +746,7 @@ def start_workflow( # noqa: C901
file=file_name,
description=file_description,
access_level=the_access_level,
wait_time=10,
)
logger.debug(f"Finished upload for {file_name}")

Expand Down
12 changes: 8 additions & 4 deletions fossology/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
class Jobs:
"""Class dedicated to all "jobs" related endpoints"""

def list_jobs(self, upload=None, page_size=100, page=1, all_pages=False):
def list_jobs(
self, upload=None, page_size=100, page=1, all_pages=False
) -> tuple[list, int]:
"""Get all available jobs
API Endpoint: GET /jobs
Expand Down Expand Up @@ -66,8 +68,8 @@ def list_jobs(self, upload=None, page_size=100, page=1, all_pages=False):
logger.info(f"Retrieved all {x_total_pages} pages of jobs")
return jobs_list, x_total_pages

def detail_job(self, job_id, wait=False, timeout=30):
"""Get detailled information about a job
def detail_job(self, job_id, wait=False, timeout=30) -> Job:
"""Get detailed information about a job
API Endpoint: GET /jobs/{id}
Expand Down Expand Up @@ -102,7 +104,9 @@ def detail_job(self, job_id, wait=False, timeout=30):
description = f"Error while getting details for job {job_id}"
raise FossologyApiError(description, response)

def schedule_jobs(self, folder, upload, spec, group=None, wait=False, timeout=30):
def schedule_jobs(
self, folder, upload, spec, group=None, wait=False, timeout=30
) -> Job:
"""Schedule jobs for a specific upload
API Endpoint: POST /jobs
Expand Down
62 changes: 60 additions & 2 deletions fossology/obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,22 @@ class ClearingStatus(Enum):
REJECTED = "Rejected"


class JobStatus(Enum):
"""Job statuses:
COMPLETED
FAILED
QUEUED
PROCESSING
"""

COMPLETED = "Completed"
FAILED = "Failed"
QUEUED = "Queued"
PROCESSING = "Processing"


class LicenseType(Enum):
"""License types:
Expand Down Expand Up @@ -793,6 +809,37 @@ def from_json(cls, json_dict):
return cls(**json_dict)


class FossologyServer(object):

"""FOSSology server info.
:param version: version of the FOSSology server (e.g. 4.0.0)
:param branchName: branch deployed on the FOSSology server
:param commitHash: hash of commit deployed on the FOSSology server
:param commitDate: date of commit deployed on the FOSSology server in ISO8601 format
:param buildDate: date on which packages were built in ISO8601 format
:type version: string
:type branchName: string
:type commitHash: string
:type commitDate: string
:type buildDate: string
"""

def __init__(self, version, branchName, commitHash, commitDate, buildDate):
self.version = version
self.branchName = branchName
self.commitHash = commitHash
self.commitDate = commitDate
self.buildDate = buildDate

def __str__(self):
return f"Fossology server version {self.version} (branch {self.branchName} - {self.commitHash})"

@classmethod
def from_json(cls, json_dict):
return cls(**json_dict)


class ApiInfo(object):

"""FOSSology API info.
Expand All @@ -805,28 +852,39 @@ class ApiInfo(object):
:param security: security methods allowed
:param contact: email contact from the API documentation
:param license: licensing of the API
:param fossology: information about FOSSology server
:type name: string
:type description: string
:type version: string
:type security: list
:type contact: string
:type license: ApiLicense object
:type fossology: FossologyServer object
:type kwargs: key word argument
"""

def __init__(
self, name, description, version, security, contact, license, **kwargs
self,
name,
description,
version,
security,
contact,
license,
fossology,
**kwargs,
):
self.name = name
self.description = description
self.version = version
self.security = security
self.contact = contact
self.license = ApiLicense.from_json(license)
self.fossology = FossologyServer.from_json(fossology)
self.additional_info = kwargs

def __str__(self):
return f"FOSSology API {self.name} is deployed with version {self.version}"
return f"{self.name} is deployed with version {self.version}"

@classmethod
def from_json(cls, json_dict):
Expand Down
Loading

0 comments on commit 7f525b1

Please sign in to comment.