Skip to content

Commit

Permalink
Add scripts for generating package data
Browse files Browse the repository at this point in the history
  • Loading branch information
marksparkza committed May 3, 2024
1 parent 14c629f commit 8d52346
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
40 changes: 40 additions & 0 deletions bin/create_fake_package_data
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,
)
21 changes: 21 additions & 0 deletions migrate/onceoff/generate_packages.py
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...
2 changes: 2 additions & 0 deletions migrate/onceoff/link_parent_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@


def set_parent_ids():
raise Exception('Function retained for historical reference. Not for re-use.')

for record in Session.execute(
select(Record)
).scalars().all():
Expand Down

0 comments on commit 8d52346

Please sign in to comment.