magpie.cli.sync_resources
¶
Synchronize local and remote resources.
To implement a new service, see magpie.cli.sync_services.SyncServiceInterface
.
See also
Module Contents¶
Functions¶
|
Main function to sync resources with remote server. |
|
Merge resources_local and resources_remote, adding the following keys to the output: |
|
Sorts a resource dictionary of the type validated by ‘sync_services.is_valid_resource_schema’ by using an |
|
Make sure the RemoteResourcesSyncInfo entry exists in the database. |
|
Request remote resources, depending on service type. |
|
Delete all RemoteResource based on a Service.resource_id. |
|
Creates a main resource for a service, whether one currently exists or not. |
|
Writes remote resources to database. |
|
|
|
Reads remote resources from the RemoteResources table. No external request is made. |
|
|
|
Get remote resources for all services of a certain type. |
|
Get remote resources for a single service. |
|
Main function to get all remote resources for each service and write to database. |
|
|
|
|
|
Main entry point for cron service. |
-
magpie.cli.sync_resources.
merge_local_and_remote_resources
(resources_local, service_sync_type, service_id, session)[source]¶ Main function to sync resources with remote server.
-
magpie.cli.sync_resources.
_merge_resources
(resources_local, resources_remote, max_depth=None)[source]¶ Merge resources_local and resources_remote, adding the following keys to the output:
remote_id: id of the RemoteResource
matches_remote: True or False depending if the resource is present on the remote server
- Returns
dictionary of the form validated by magpie.cli.sync_services.is_valid_resource_schema.
-
magpie.cli.sync_resources.
_sort_resources
(resources)[source]¶ Sorts a resource dictionary of the type validated by ‘sync_services.is_valid_resource_schema’ by using an OrderedDict.
- Returns
None
-
magpie.cli.sync_resources.
_ensure_sync_info_exists
(service_resource_id, session)[source]¶ Make sure the RemoteResourcesSyncInfo entry exists in the database.
- Parameters
service_resource_id –
session –
-
magpie.cli.sync_resources.
_get_remote_resources
(service)[source]¶ Request remote resources, depending on service type.
- Parameters
service – (models.Service)
- Returns
-
magpie.cli.sync_resources.
_delete_records
(service_id, session)[source]¶ Delete all RemoteResource based on a Service.resource_id.
- Parameters
service_id –
session –
-
magpie.cli.sync_resources.
_create_main_resource
(service_id, session)[source]¶ Creates a main resource for a service, whether one currently exists or not.
Each RemoteResourcesSyncInfo has a main RemoteResource of the same name as the service. This is similar to the Service and Resource relationship.
- Parameters
service_id –
session –
-
magpie.cli.sync_resources.
_update_db
(remote_resources, service_id, session)[source]¶ Writes remote resources to database.
- Parameters
remote_resources –
service_id –
session –
-
magpie.cli.sync_resources.
_query_remote_resources_in_database
(service_id, session)[source]¶ Reads remote resources from the RemoteResources table. No external request is made.
- Returns
a dictionary of the form defined in ‘sync_services.is_valid_resource_schema’
-
magpie.cli.sync_resources.
get_last_sync
(service_id: int, session: sqlalchemy.orm.session.Session) → Optional[datetime.datetime][source]¶
-
magpie.cli.sync_resources.
fetch_all_services_by_type
(service_type, session)[source]¶ Get remote resources for all services of a certain type.
- Parameters
service_type –
session –
-
magpie.cli.sync_resources.
fetch_single_service
(service, session)[source]¶ Get remote resources for a single service.
- Parameters
service – (models.Service) or service_id
session –
-
magpie.cli.sync_resources.
fetch
(settings=None)[source]¶ Main function to get all remote resources for each service and write to database.