-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add scripts for generating package data
- Loading branch information
1 parent
14c629f
commit 8d52346
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env python | ||
|
||
import pathlib | ||
import sys | ||
from random import randint | ||
|
||
rootdir = pathlib.Path(__file__).parent.parent | ||
sys.path.append(str(rootdir)) | ||
|
||
from odp.config import config | ||
from odp.const import ODPArchive | ||
from odp.db.models import Archive | ||
from test.factories import ArchiveResourceFactory, FactorySession, PackageFactory, ProviderFactory, ResourceFactory | ||
|
||
if __name__ == '__main__': | ||
if config.ODP.ENV not in ('development', 'testing'): | ||
raise Exception(f'Fake data not allowed in {config.ODP.ENV} environment.') | ||
|
||
mims_archive = FactorySession.get(Archive, ODPArchive.MIMS_ARCHIVE) | ||
saeon_archive = FactorySession.get(Archive, ODPArchive.SAEON_REPOSITORY) | ||
|
||
for provider in ProviderFactory.create_batch(10): | ||
print(f'Creating packages and resources for {provider.key}...') | ||
|
||
for archive in mims_archive, saeon_archive: | ||
for _ in range(randint(0, 15)): | ||
resources = [] | ||
for _ in range(randint(1, 20)): | ||
archive_resource = ArchiveResourceFactory( | ||
archive=archive, | ||
resource=ResourceFactory( | ||
provider=provider, | ||
) | ||
) | ||
resources += [archive_resource.resource] | ||
|
||
PackageFactory( | ||
provider=provider, | ||
resources=resources, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import os | ||
|
||
from odp.config import config | ||
from odp.const import ODPScope | ||
from odp.lib.client import ODPClient | ||
|
||
|
||
def create_packages_from_records(): | ||
cli = ODPClient( | ||
api_url=config.ODP.API_URL, | ||
hydra_url=config.HYDRA.PUBLIC.URL, | ||
client_id='ODP.Migrate', | ||
client_secret=os.environ['ODP_MIGRATE_CLIENT_SECRET'], | ||
scope=[ | ||
ODPScope.RECORD_READ, | ||
ODPScope.ARCHIVE_READ, | ||
ODPScope.PACKAGE_WRITE, | ||
ODPScope.RESOURCE_WRITE, | ||
], | ||
) | ||
# TODO... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters