Skip to content

Commit

Permalink
Break out the 'projects' property into 'all_projects', 'active_projec…
Browse files Browse the repository at this point in the history
…ts' and 'closed_projects'.
  • Loading branch information
leonidessaguisagjr committed Jan 25, 2020
1 parent 79a6038 commit 15a8c82
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
46 changes: 37 additions & 9 deletions memoq/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
This code is released under the MIT License.
"""
from collections.abc import Mapping
from datetime import datetime, timezone

from .webservice import MemoQLightResourceService, MemoQLiveDocsService, MemoQTBService, MemoQTMService, \
MemoQSecurityService, MemoQServerProjectService
Expand Down Expand Up @@ -73,6 +74,7 @@ def __init__(self, base_url: str):
:param base_url: Base URL for the memoQ server. For example, 'http://localhost:8080'
"""
self.base_url = base_url
self._all_projects = None
self._api_endpoints = {}
self._light_resources = None

Expand Down Expand Up @@ -146,6 +148,30 @@ def _tm_service(self):
self._api_endpoints[tm_service_key] = MemoQTMService(self.base_url)
return self._api_endpoints[tm_service_key]

@property
def active_projects(self) -> list:
"""
Method for retrieving the list of active projects on the memoQ server.
:returns: A list of active projects on the memoQ server.
"""
return [proj
for proj in self.all_projects
if proj.TimeClosed.replace(tzinfo=timezone.utc) > datetime.now(timezone.utc)]

@property
def all_projects(self) -> list:
"""
Method for retrieving the list of all projects (both active and closed) on the memoQ server.
:returns: A list of all projects (both active and closed) on the memoQ server.
"""
# https://docs.memoq.com/current/api-docs/wsapi/api/serverprojectservice/MemoQServices.ServerProjectListFilter.html#MemoQServices_SP_ServerProjectListFilter_TimeClosed
if self._all_projects is None:
self._all_projects = self._server_project_service.ListProjects(
{'TimeClosed': datetime(year=1900, month=1, day=1)})
return self._all_projects

@property
def api_version(self) -> str:
"""
Expand All @@ -155,6 +181,17 @@ def api_version(self) -> str:
"""
return self._server_project_service.GetApiVersion()

@property
def closed_projects(self) -> list:
"""
Method for retrieving the list of closed projects on the memoQ server.
:returns: A list of closed projects on the memoQ server.
"""
return [proj
for proj in self.all_projects
if proj.TimeClosed.replace(tzinfo=timezone.utc) < datetime.now(timezone.utc)]

@property
def corpora(self) -> list:
"""
Expand Down Expand Up @@ -184,15 +221,6 @@ def light_resources(self) -> LightResources:
self._light_resources = LightResources(self._light_resource_service)
return self._light_resources

@property
def projects(self) -> list:
"""
Method for retrieving the list of projects on the memoQ server.
:returns: A list of projects on the memoQ server.
"""
return self._server_project_service.ListProjects()

@property
def tbs(self) -> list:
"""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
long_description = f.read()

setup(name='pymemoq',
version='0.2.dev3',
version='0.2.dev6',
description='Python module to facilitate accessing the memoQ API.',
long_description=long_description,
long_description_content_type='text/x-rst',
Expand Down

0 comments on commit 15a8c82

Please sign in to comment.