Package entropy :: Package client :: Package services :: Module interfaces :: Class ClientWebService

Class ClientWebService

source code


Nested Classes
  DocumentError
Generic Document error object.

Inherited from services.client.WebService: AuthenticationFailed, AuthenticationRequired, CacheMiss, MalformedResponse, MethodNotAvailable, MethodResponseError, RequestError, UnsupportedAPILevel, UnsupportedParameters, UnsupportedService, WebServiceException

Instance Methods
 
__init__(self, entropy_client, repository_id)
ClientWebService constructor.
source code
DocumentFactory
document_factory(self)
Return a new DocumentFactory object, used to create new Document objects.
source code
 
get_votes(self, package_names, cache=True, cached=False)
For given package names, return the current vote.
source code
 
get_available_votes(self, cache=True, cached=False)
Return all the available votes for all the available packages.
source code
 
get_downloads(self, package_names, cache=True, cached=False)
For given package names, return the current download counter.
source code
 
get_available_downloads(self, cache=True, cached=False)
Return all the available downloads for all the available packages.
source code
 
add_vote(self, package_name, vote, clear_available_cache=False)
For given package name, add a vote.
source code
 
add_downloads(self, package_names, clear_available_cache=False)
Notify that a list of packages have been downloaded successfully.
source code
 
get_images(self, package_names, offset=0, latest=False, cache=True, cached=False, service_cache=False)
For given package names, return the current Document image object DocumentList.
source code
 
get_icons(self, package_names, offset=0, latest=False, cache=True, cached=False, service_cache=False)
For given package names, return the current Document icon object DocumentList.
source code
 
get_comments(self, package_names, offset=0, latest=False, cache=True, cached=False, service_cache=False)
For given package names, return the current Document Comment object DocumentList.
source code
 
get_documents(self, package_names, document_type_filter=None, offset=0, latest=False, cache=True, cached=False, service_cache=False)
For given package names, return the current Document object DocumentList.
source code
 
get_documents_by_id(self, document_ids, cache=True, cached=False)
For given Document object identifiers, return the respective Document object.
source code
 
add_document(self, package_name, document)
Send a new Document object to the service.
source code
string
get_document_url(self, document, cache=True)
Download (to Document.local_document() path, if available) the document data pointed at Document.document_url().
source code
 
remove_document(self, document_id)
Remove a Document (through its id) from the service repository.
source code
 
report_error(self, error_params)
Entropy Client Error reporting method.
source code

Inherited from services.client.WebService: add_credentials, credentials_available, data_send_available, enable_cache_aging, get_credentials, remove_credentials, service_available, validate_credentials

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Methods

Inherited from services.client.WebService: config

Class Variables
  MAX_VOTE = 5.0
  MIN_VOTE = 0.0
  VALID_VOTES = (1, 2, 3, 4, 5)

Inherited from services.client.WebService: CACHE_DIR, PKG_ICON_IDENTIFIER, SUPPORTED_API_LEVEL, SUPPORTED_URL_SCHEMAS, WEB_SERVICE_INVALID_CREDENTIALS_CODE, WEB_SERVICE_INVALID_REQUEST_CODE, WEB_SERVICE_NOT_FOUND_CODE, WEB_SERVICE_RESPONSE_CODE_OK, WEB_SERVICE_RESPONSE_ERROR_CODE

Properties

Inherited from object: __class__

Method Details

__init__(self, entropy_client, repository_id)
(Constructor)

source code 

ClientWebService constructor.

Parameters:
  • entropy_client - Entropy Client interface
  • repository_id - repository identifier
Overrides: object.__init__

document_factory(self)

source code 

Return a new DocumentFactory object, used to create new Document objects.

Returns: DocumentFactory
a DocumentFactory object

get_votes(self, package_names, cache=True, cached=False)

source code 
For given package names, return the current vote. For missing votes
or invalid package_name, None is assigned.

@param package_names: list of package names, either atoms or keys
@type package_names: list
@keyword cache: True means use on-disk cache if available?
@type cache: bool
@keyword cache: True means use on-disk cache if available?
@type cache: bool
@keyword cached: if True, it will only use the on-disk cached call
    result and raise WebService.CacheMiss if not found.
@type cached: bool
@return: mapping composed by package name as key and value as vote
    (float)
@rtype: dict

@raise WebService.UnsupportedParameters: if input parameters are
    invalid
@raise WebService.RequestError: if request cannot be satisfied
@raise WebService.MethodNotAvailable: if API method is not
    available remotely and an error occurred (error code passed as
    exception argument)
@raise WebService.AuthenticationRequired: if require_credentials
    is True and credentials are required.
@raise WebService.AuthenticationFailed: if credentials are
    not valid
@raise WebService.MalformedResponse: if JSON response cannot be
    converted back to dict.
@raise WebService.UnsupportedAPILevel: if client API and Web
    Service API do not match
@raise WebService.MethodResponseError; if method execution failed
@raise WebService.CacheMiss: if cached=True and cached object is not
    available

get_available_votes(self, cache=True, cached=False)

source code 
Return all the available votes for all the available packages.

@keyword cache: True means use on-disk cache if available?
@type cache: bool
@keyword cached: if True, it will only use the on-disk cached call
    result and raise WebService.CacheMiss if not found.
@type cached: bool
@return: mapping composed by package name as key and value as vote
    (float)
@rtype: dict

@raise WebService.UnsupportedParameters: if input parameters are
    invalid
@raise WebService.RequestError: if request cannot be satisfied
@raise WebService.MethodNotAvailable: if API method is not
    available remotely and an error occurred (error code passed as
    exception argument)
@raise WebService.AuthenticationRequired: if require_credentials
    is True and credentials are required.
@raise WebService.AuthenticationFailed: if credentials are
    not valid
@raise WebService.MalformedResponse: if JSON response cannot be
    converted back to dict.
@raise WebService.UnsupportedAPILevel: if client API and Web
    Service API do not match
@raise WebService.MethodResponseError; if method execution failed
@raise WebService.CacheMiss: if cached=True and cached object is not
    available

get_downloads(self, package_names, cache=True, cached=False)

source code 
For given package names, return the current download counter.
Packages having no download info will get None instead of int.

@param package_names: list of package names, either atoms or keys
@type package_names: list
@keyword cache: True means use on-disk cache if available?
@type cache: bool
@keyword cached: if True, it will only use the on-disk cached call
    result and raise WebService.CacheMiss if not found.
@type cached: bool
@return: mapping composed by package name as key and downloads as value
@rtype: dict

@raise WebService.UnsupportedParameters: if input parameters are
    invalid
@raise WebService.RequestError: if request cannot be satisfied
@raise WebService.MethodNotAvailable: if API method is not
    available remotely and an error occurred (error code passed as
    exception argument)
@raise WebService.AuthenticationRequired: if require_credentials
    is True and credentials are required.
@raise WebService.AuthenticationFailed: if credentials are
    not valid
@raise WebService.MalformedResponse: if JSON response cannot be
    converted back to dict.
@raise WebService.UnsupportedAPILevel: if client API and Web
    Service API do not match
@raise WebService.MethodResponseError; if method execution failed
@raise WebService.CacheMiss: if cached=True and cached object is not
    available

get_available_downloads(self, cache=True, cached=False)

source code 
Return all the available downloads for all the available packages.

@param package_names: list of package names, either atoms or keys
@type package_names: list
@keyword cache: True means use on-disk cache if available?
@type cache: bool
@keyword cached: if True, it will only use the on-disk cached call
    result and raise WebService.CacheMiss if not found.
@type cached: bool
@return: mapping composed by package name as key and downloads as value
@rtype: dict

@raise WebService.UnsupportedParameters: if input parameters are
    invalid
@raise WebService.RequestError: if request cannot be satisfied
@raise WebService.MethodNotAvailable: if API method is not
    available remotely and an error occurred (error code passed as
    exception argument)
@raise WebService.AuthenticationRequired: if require_credentials
    is True and credentials are required.
@raise WebService.AuthenticationFailed: if credentials are
    not valid
@raise WebService.MalformedResponse: if JSON response cannot be
    converted back to dict.
@raise WebService.UnsupportedAPILevel: if client API and Web
    Service API do not match
@raise WebService.MethodResponseError; if method execution failed
@raise WebService.CacheMiss: if cached=True and cached object is not
    available

add_vote(self, package_name, vote, clear_available_cache=False)

source code 
For given package name, add a vote.

@param package_name: package name, either atom or key
@type package_name: string
@keyword clear_available_cache: if True, even the
    "get_available_votes" on-disk cache gets cleared. Usually,
    this is not a very good thing (even if the cache contains outdated
    information) given the nature of the whole vote info.
    This is usually a push-only information.
    Please note that the "get_votes" cache is always cleared.
@type clear_available_cache: bool
@return: True, if vote was recorded, False otherwise
@rtype: bool

@raise WebService.UnsupportedParameters: if input parameters are
    invalid
@raise WebService.RequestError: if request cannot be satisfied
@raise WebService.MethodNotAvailable: if API method is not
    available remotely and an error occurred (error code passed as
    exception argument)
@raise WebService.AuthenticationRequired: if require_credentials
    is True and credentials are required.
@raise WebService.AuthenticationFailed: if credentials are
    not valid
@raise WebService.MalformedResponse: if JSON response cannot be
    converted back to dict.
@raise WebService.UnsupportedAPILevel: if client API and Web
    Service API do not match
@raise WebService.MethodResponseError; if method execution failed
@raise WebService.RequestError: if vote is invalid.
@raise WebService.AuthenticationRequired: if login information are
    not available (user interface should raise a login form, validate
    the credentials and retry the function call here)

add_downloads(self, package_names, clear_available_cache=False)

source code 
Notify that a list of packages have been downloaded successfully.

@param package_names: list of package names, either atoms or keys
@type package_names: list
@keyword clear_available_cache: if True, even the
    "get_available_downloads" on-disk cache gets cleared. Usually,
    this is not a very good thing (even if the cache contains outdated
    information) given the nature of the whole downloads info.
    This is usually a push-only information.
    Please note that the "get_downloads" cache is always cleared.
@type clear_available_cache: bool
@return: True, if download information was recorded, False otherwise
@rtype: bool

@raise WebService.UnsupportedParameters: if input parameters are
    invalid
@raise WebService.RequestError: if request cannot be satisfied
@raise WebService.MethodNotAvailable: if API method is not
    available remotely and an error occurred (error code passed as
    exception argument)
@raise WebService.AuthenticationRequired: if require_credentials
    is True and credentials are required.
@raise WebService.AuthenticationFailed: if credentials are
    not valid
@raise WebService.MalformedResponse: if JSON response cannot be
    converted back to dict.
@raise WebService.UnsupportedAPILevel: if client API and Web
    Service API do not match
@raise WebService.MethodResponseError; if method execution failed
@raise WebService.AuthenticationRequired: if login information are
    not available (user interface should raise a login form, validate
    the credentials and retry the function call here)

get_images(self, package_names, offset=0, latest=False, cache=True, cached=False, service_cache=False)

source code 
For given package names, return the current Document image object
DocumentList.
Packages having no images will get empty DocumentList as value.

Results are paged, if offset is 0, the first page is returned.
For gathering information regarding pages (total documents,
offset provided, etc), see DocumentList API.

@param package_names: list of names of the packages to query,
    either atom or key
@type package_names: list
@keyword offset: specify the offset document from where to start
    for each package_name
@type offset: int
@keyword latest: get documents in inverse order, from latest to oldest
@type latest: bool
@keyword cache: True means use on-disk cache if available?
@type cache: bool
@keyword cached: if True, it will only use the on-disk cached call
    result and raise WebService.CacheMiss if not found.
@type cached: bool
@keyword service_cache: explicitly allow service to use its cache to
    satisfy the request
@type service_cache: bool
@return: mapping composed by package name as key and DocumentList
    as value
@rtype: dict

@raise WebService.UnsupportedParameters: if input parameters are
    invalid
@raise WebService.RequestError: if request cannot be satisfied
@raise WebService.MethodNotAvailable: if API method is not
    available remotely and an error occurred (error code passed as
    exception argument)
@raise WebService.AuthenticationRequired: if require_credentials
    is True and credentials are required.
@raise WebService.AuthenticationFailed: if credentials are
    not valid
@raise WebService.MalformedResponse: if JSON response cannot be
    converted back to dict.
@raise WebService.UnsupportedAPILevel: if client API and Web
    Service API do not match
@raise WebService.MethodResponseError; if method execution failed
@raise WebService.CacheMiss: if cached=True and cached object is not
    available

get_icons(self, package_names, offset=0, latest=False, cache=True, cached=False, service_cache=False)

source code 
For given package names, return the current Document icon object
DocumentList.
Packages having no icon will get empty DocumentList as value.

Results are paged, if offset is 0, the first page is returned.
For gathering information regarding pages (total documents,
offset provided, etc), see DocumentList API.

@param package_names: list of names of the packages to query,
    either atom or key
@type package_names: list
@keyword offset: specify the offset document from where to start
    for each package_name
@type offset: int
@keyword latest: get documents in inverse order, from latest to oldest
@type latest: bool
@keyword cache: True means use on-disk cache if available?
@type cache: bool
@keyword cached: if True, it will only use the on-disk cached call
    result and raise WebService.CacheMiss if not found.
@type cached: bool
@keyword service_cache: explicitly allow service to use its cache to
    satisfy the request
@type service_cache: bool
@return: mapping composed by package name as key and DocumentList
    as value
@rtype: dict

@raise WebService.UnsupportedParameters: if input parameters are
    invalid
@raise WebService.RequestError: if request cannot be satisfied
@raise WebService.MethodNotAvailable: if API method is not
    available remotely and an error occurred (error code passed as
    exception argument)
@raise WebService.AuthenticationRequired: if require_credentials
    is True and credentials are required.
@raise WebService.AuthenticationFailed: if credentials are
    not valid
@raise WebService.MalformedResponse: if JSON response cannot be
    converted back to dict.
@raise WebService.UnsupportedAPILevel: if client API and Web
    Service API do not match
@raise WebService.MethodResponseError; if method execution failed
@raise WebService.CacheMiss: if cached=True and cached object is not
    available

get_comments(self, package_names, offset=0, latest=False, cache=True, cached=False, service_cache=False)

source code 
For given package names, return the current Document Comment object
DocumentList.
Packages having no comments will get empty DocumentList as value.

Results are paged, if offset is 0, the first page is returned.
For gathering information regarding pages (total documents,
offset provided, etc), see DocumentList API.

@param package_names: list of names of the packages to query,
    either atom or key
@type package_names: list
@keyword offset: specify the offset document from where to start
    for each package_name
@type offset: int
@keyword latest: get documents in inverse order, from latest to oldest
@type latest: bool
@keyword cache: True means use on-disk cache if available?
@type cache: bool
@keyword cached: if True, it will only use the on-disk cached call
    result and raise WebService.CacheMiss if not found.
@type cached: bool
@keyword service_cache: explicitly allow service to use its cache to
    satisfy the request
@type service_cache: bool
@return: mapping composed by package name as key and DocumentList
    as value
@rtype: dict

@raise WebService.UnsupportedParameters: if input parameters are
    invalid
@raise WebService.RequestError: if request cannot be satisfied
@raise WebService.MethodNotAvailable: if API method is not
    available remotely and an error occurred (error code passed as
    exception argument)
@raise WebService.AuthenticationRequired: if require_credentials
    is True and credentials are required.
@raise WebService.AuthenticationFailed: if credentials are
    not valid
@raise WebService.MalformedResponse: if JSON response cannot be
    converted back to dict.
@raise WebService.UnsupportedAPILevel: if client API and Web
    Service API do not match
@raise WebService.MethodResponseError; if method execution failed
@raise WebService.CacheMiss: if cached=True and cached object is not
    available

get_documents(self, package_names, document_type_filter=None, offset=0, latest=False, cache=True, cached=False, service_cache=False)

source code 
For given package names, return the current Document object
DocumentList.
Packages having no documents will get empty DocumentList as value.

Results are paged, if offset is 0, the first page is returned.
For gathering information regarding pages (total documents,
offset provided, etc), see DocumentList API.

@param package_names: list of names of the packages to query,
    either atom or key
@type package_names: list
@keyword document_type_filter: list of document type identifiers (
    see Document class) that are required.
@type document_type_filter: list
@keyword offset: specify the offset document from where to start
    for each package_name
@type offset: int
@keyword latest: get documents in inverse order, from latest to oldest
@type latest: bool
@keyword cache: True means use on-disk cache if available?
@type cache: bool
@keyword cached: if True, it will only use the on-disk cached call
    result and raise WebService.CacheMiss if not found.
@type cached: bool
@keyword service_cache: explicitly allow service to use its cache to
    satisfy the request
@type service_cache: bool
@return: mapping composed by package name as key and DocumentList as
    value
@rtype: dict

@raise WebService.UnsupportedParameters: if input parameters are
    invalid
@raise WebService.RequestError: if request cannot be satisfied
@raise WebService.MethodNotAvailable: if API method is not
    available remotely and an error occurred (error code passed as
    exception argument)
@raise WebService.AuthenticationRequired: if require_credentials
    is True and credentials are required.
@raise WebService.AuthenticationFailed: if credentials are
    not valid
@raise WebService.MalformedResponse: if JSON response cannot be
    converted back to dict.
@raise WebService.UnsupportedAPILevel: if client API and Web
    Service API do not match
@raise WebService.MethodResponseError; if method execution failed
@raise WebService.CacheMiss: if cached=True and cached object is not
    available

get_documents_by_id(self, document_ids, cache=True, cached=False)

source code 
For given Document object identifiers, return the respective Document
object.
Unavailable Document object identifiers will have None as dict value.

@param document_ids: list of document identifiers (int)
    either atom or key
@type document_ids: list
@keyword cache: True means use on-disk cache if available?
@type cache: bool
@keyword cached: if True, it will only use the on-disk cached call
    result and raise WebService.CacheMiss if not found.
@type cached: bool
@return: mapping composed by Document identifier as key and
    Document as value
@rtype: dict

@raise WebService.UnsupportedParameters: if input parameters are
    invalid
@raise WebService.RequestError: if request cannot be satisfied
@raise WebService.MethodNotAvailable: if API method is not
    available remotely and an error occurred (error code passed as
    exception argument)
@raise WebService.AuthenticationRequired: if require_credentials
    is True and credentials are required.
@raise WebService.AuthenticationFailed: if credentials are
    not valid
@raise WebService.MalformedResponse: if JSON response cannot be
    converted back to dict.
@raise WebService.UnsupportedAPILevel: if client API and Web
    Service API do not match
@raise WebService.MethodResponseError; if method execution failed
@raise WebService.CacheMiss: if cached=True and cached object is not
    available

add_document(self, package_name, document)

source code 
Send a new Document object to the service.
This method will return the newly created remote document object, or
raise exceptions in case the operation failed.

@param package_name: package name, either atom or key
@type package_name: string
@return: the newly created remote Document object
@rtype: Document

@raise WebService.UnsupportedParameters: if input parameters are
    invalid
@raise WebService.RequestError: if request cannot be satisfied
@raise WebService.MethodNotAvailable: if API method is not
    available remotely and an error occurred (error code passed as
    exception argument)
@raise WebService.AuthenticationRequired: if require_credentials
    is True and credentials are required.
@raise WebService.AuthenticationFailed: if credentials are
    not valid
@raise WebService.MalformedResponse: if JSON response cannot be
    converted back to dict.
@raise WebService.UnsupportedAPILevel: if client API and Web
    Service API do not match
@raise WebService.MethodResponseError; if method execution failed
@raise WebService.AuthenticationRequired: if login information are
    not available (user interface should raise a login form, validate
    the credentials and retry the function call here)
@raise ClientWebService.DocumentError: if document submitted is
    invalid (contains invalid fields)

get_document_url(self, document, cache=True)

source code 

Download (to Document.local_document() path, if available) the document data pointed at Document.document_url(). Document data path is returned in case of success, but an exception is always raised in case of failure.

Parameters:
  • document (Document) - the Document object
  • cache (bool) - use on-disk cache
Returns: string
document data file path
Raises:

remove_document(self, document_id)

source code 
Remove a Document (through its id) from the service repository.

@param document_id: Entropy Document identifier
@type document_id: int
@return: True if document has been removed, False if Document doesn't
    exist
@rtype: bool

@raise WebService.UnsupportedParameters: if input parameters are
    invalid
@raise WebService.RequestError: if request cannot be satisfied
@raise WebService.MethodNotAvailable: if API method is not
    available remotely and an error occurred (error code passed as
    exception argument)
@raise WebService.AuthenticationRequired: if require_credentials
    is True and credentials are required.
@raise WebService.AuthenticationFailed: if credentials are
    not valid
@raise WebService.MalformedResponse: if JSON response cannot be
    converted back to dict.
@raise WebService.UnsupportedAPILevel: if client API and Web
    Service API do not match
@raise WebService.MethodResponseError; if method execution failed
@raise WebService.AuthenticationRequired: if login information are
    not available (user interface should raise a login form, validate
    the credentials and retry the function call here)

report_error(self, error_params)

source code 
Entropy Client Error reporting method. This is mainly used by
Entropy internal code in order to submit a stacktrace and other data
to Entropy developers. "error_params" consinsts in a dictionary
containing error data in string format as values.

@param error_params: dictionary containing error report data
@type error_params: dict

@raise WebService.UnsupportedParameters: if input parameters are
    invalid
@raise WebService.RequestError: if request cannot be satisfied
@raise WebService.MethodNotAvailable: if API method is not
    available remotely and an error occurred (error code passed as
    exception argument)
@raise WebService.AuthenticationRequired: if require_credentials
    is True and credentials are required.
@raise WebService.AuthenticationFailed: if credentials are
    not valid
@raise WebService.MalformedResponse: if JSON response cannot be
    converted back to dict.
@raise WebService.UnsupportedAPILevel: if client API and Web
    Service API do not match
@raise WebService.MethodResponseError; if method execution failed