-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Resource Feature #44
base: main
Are you sure you want to change the base?
Conversation
The message bus in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool how this all came together. I'm leaving some comments and will follow up separately. Looking forward to discussing.
.gitignore
Outdated
features/scratch/ | ||
tests/test_storage/ | ||
tests/test_descriptor_generator/ | ||
tests/test_workspaces/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests/test_workspaces/ |
test_descriptor_generator
took the places of test_workspaces
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out I was wrong! tests/test_workspaces
is used by test_translocator.py
. .gitignore
eventually.
|
||
from dor.providers.models import PackageResource, StructMapType | ||
|
||
### IGNORE THIS FILE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this comment be removed?
incoming_resource.data_files, | ||
) | ||
|
||
if incoming_resource.struct_maps and incoming_resource.struct_maps[0].type == StructMapType.PHYSICAL: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will the physical struct map always be first?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, yes.
class MinterProvider(ABC): | ||
@abstractmethod | ||
def mint(self) -> str: | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: I'd probably have just called it Minter
. It's not providing a minter, it's providing an ID, right?
def _( | ||
path_data: PathData, unit_of_work: AbstractUnitOfWork, message_bus: MemoryMessageBus | ||
): | ||
"""a package containing all the scanned pages, OCR, and metadata.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this comment be the same as what's in the given
?
@abstractmethod | ||
def log(self, id: str, reversed: bool = True) -> list[VersionInfo]: | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know the underlying command is log
, but I'd like to see this method be named something more specific, like get_versions
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't look like reversed
is actually used anywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dislike the re-using versions
, because it's not versions. It's a log of versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I see your point, that's fine. I just wish the method said something about how it has something to do with version data. Maybe that's implied by logging an object, but feels vague at this point.
class VersionInfo: | ||
version: int | ||
author: str | ||
date: datetime |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd opt for datetime
or timestamp
. I find it confusing when only date
is used for both date and time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks as if you're using the data straight from ROCFL, so maybe this would be some work to change...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. We can't (readily) translate from the rocfl
log back into discrete agent/contact, and we only care about the version
number at the moment.
def log(self, id: str, reversed: bool = True) -> list[VersionInfo]: | ||
version_log = [] | ||
args: list[str | Path] = ["rocfl", "-r", self.storage_path, "log", "-r", id] | ||
info = {} | ||
try: | ||
result = subprocess.run(args, check=True, capture_output=True) | ||
for line in result.stdout.decode("utf-8").split("\n"): | ||
if not line.strip(): | ||
if info: | ||
version_log.append(VersionInfo(**info)) | ||
continue | ||
|
||
if line.startswith("Version "): | ||
info = {} | ||
info['version'] = int(line.split(" ")[-1]) | ||
else: | ||
key, value = [ v.strip() for v in line.strip().split(":", 1) ] | ||
info[key.lower()] = value | ||
|
||
return version_log | ||
except CalledProcessError as e: | ||
staged_version_not_found_message = ( | ||
f"Not found: {id} does not have a staged version." | ||
) | ||
if staged_version_not_found_message in e.stderr.decode(): | ||
return False | ||
raise RepositoryGatewayError() from e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see tests for this and (less importantly) the FakeRepositoryGateway.log
. Happy to chip in with a PR if you want me to.
|
||
def log(self, id: str, reversed: bool = True) -> list[VersionInfo]: | ||
return reversed([ | ||
VersionInfo(version=v.number, author=v.contributor, message=v.message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work if you don't provide date
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. We'll have to fake something in the fake logging.
tests/test_workspaces/ Co-authored-by: Sam Sciolla <[email protected]>
Update resource feature with two scenarios: update everything (data and metadata) and update metadata only.