Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ branch = True
data_file = .coverage
source=
blockstore
tagstore
omit =
blockstore/settings*
blockstore/conf*
Expand Down
25 changes: 25 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Change Log
----------

..
All enhancements and patches to blockstore will be documented
in this file. It adheres to the structure of https://keepachangelog.com/ ,
but in reStructuredText instead of Markdown (for ease of incorporation into
Sphinx documentation and the PyPI description).

This project adheres to Semantic Versioning (https://semver.org/).

.. There should always be an "Unreleased" section for changes pending release.

Unreleased
~~~~~~~~~~

*

[1.0.0] - 2020-11-11
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Added
_____

* First release on PyPI.
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ static: ## Collect static files
${VENV_BIN}/python manage.py collectstatic --noinput

test: clean ## Run tests and generate coverage report
${VENV_BIN}/coverage run ./manage.py test blockstore tagstore --settings=blockstore.settings.test
${VENV_BIN}/coverage run ./manage.py test blockstore --settings=blockstore.settings.test
${VENV_BIN}/coverage html
${VENV_BIN}/coverage xml
${VENV_BIN}/diff-cover coverage.xml --html-report diff-cover.html --compare-branch origin/master
${VENV_BIN}/diff-cover coverage.xml --html-report diff-cover.html --compare-branch=origin/master

easyserver: dev.up dev.provision # Start and provision a Blockstore container and run the server until CTRL-C, then stop it
# Now run blockstore until the user hits CTRL-C:
Expand All @@ -108,9 +108,8 @@ html_coverage: ## Generate HTML coverage report
${VENV_BIN}/coverage html

quality: ## Run quality checks
${VENV_BIN}/pycodestyle --config=pycodestyle blockstore tagstore *.py
${VENV_BIN}/pylint --django-settings-module=blockstore.settings.test --rcfile=pylintrc blockstore tagstore *.py
${VENV_BIN}/mypy --config-file tagstore/mypy.ini tagstore
${VENV_BIN}/pycodestyle --config=pycodestyle blockstore *.py
${VENV_BIN}/pylint --django-settings-module=blockstore.settings.test --rcfile=pylintrc blockstore *.py

validate: test quality ## Run tests and quality checks

Expand Down
5 changes: 5 additions & 0 deletions blockstore/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""
Blockstore is a system for storing educational content.
"""

__version__ = '1.0.0'
55 changes: 55 additions & 0 deletions blockstore/apps/api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""
API Client for Blockstore

This API does not do any caching; consider using BundleCache or (in
openedx.core.djangolib.blockstore_cache) together with these API methods for
improved performance.
"""
from .data import (
CollectionData,
BundleData,
BundleVersionData,
DraftData,
BundleFileData,
DraftFileData,
Dependency,
BundleLinkData,
DraftLinkData,
)
from .methods import (
# Collections:
get_collection,
create_collection,
update_collection,
delete_collection,
# Bundles:
get_bundles,
get_bundle,
create_bundle,
update_bundle,
delete_bundle,
# Drafts:
get_draft,
get_or_create_draft,
write_draft_file,
set_draft_link,
commit_draft,
delete_draft,
# Bundles or drafts:
get_bundle_files,
get_bundle_file_metadata,
get_bundle_file_data,
get_bundle_version,
# Links:
get_bundle_links,
)
from .exceptions import (
BlockstoreException,
CollectionNotFound,
BundleNotFound,
BundleVersionNotFound,
DraftNotFound,
DraftHasNoChangesToCommit,
BundleFileNotFound,
BundleStorageError,
)
9 changes: 9 additions & 0 deletions blockstore/apps/api/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
""" AppConfig for API app. """

from django.apps import AppConfig


class ApiConfig(AppConfig):
name = 'blockstore.apps.api'
label = 'blockstore_apps_api'
verbose_name = "Blockstore API"
104 changes: 104 additions & 0 deletions blockstore/apps/api/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
"""
Data models used for Blockstore API Client
"""

from datetime import datetime
from uuid import UUID

import attr
import six

from blockstore.apps.bundles.links import Dependency


def _convert_to_uuid(value):
if not isinstance(value, UUID):
return UUID(value)
return value


@attr.s(frozen=True)
class CollectionData:
"""
Metadata about a blockstore collection
"""
uuid = attr.ib(type=UUID, converter=_convert_to_uuid)
title = attr.ib(type=six.text_type)


@attr.s(frozen=True)
class BundleData:
"""
Metadata about a blockstore bundle
"""
uuid = attr.ib(type=UUID, converter=_convert_to_uuid)
title = attr.ib(type=six.text_type)
description = attr.ib(type=six.text_type)
slug = attr.ib(type=six.text_type)
drafts = attr.ib(type=dict) # Dict of drafts, where keys are the draft names and values are draft UUIDs
# Note that if latest_version is 0, it means that no versions yet exist
latest_version = attr.ib(type=int, validator=attr.validators.instance_of(int))


@attr.s(frozen=True)
class BundleVersionData:
"""
Metadata about a blockstore bundle version.
"""
bundle_uuid = attr.ib(type=UUID, converter=_convert_to_uuid)
version = attr.ib(type=int, validator=attr.validators.instance_of(int))
change_description = attr.ib(type=six.text_type)
created_at = attr.ib(type=datetime, validator=attr.validators.instance_of(datetime))
files = attr.ib(type=dict)
links = attr.ib(type=dict)


@attr.s(frozen=True)
class DraftData:
"""
Metadata about a blockstore draft
"""
uuid = attr.ib(type=UUID, converter=_convert_to_uuid)
bundle_uuid = attr.ib(type=UUID, converter=_convert_to_uuid)
name = attr.ib(type=six.text_type)
created_at = attr.ib(type=datetime, validator=attr.validators.instance_of(datetime))
updated_at = attr.ib(type=datetime, validator=attr.validators.instance_of(datetime))
files = attr.ib(type=dict)
links = attr.ib(type=dict)


@attr.s(frozen=True)
class BundleFileData:
"""
Metadata about a file in a blockstore bundle or draft.
"""
path = attr.ib(type=six.text_type)
size = attr.ib(type=int)
url = attr.ib(type=six.text_type)
hash_digest = attr.ib(type=six.text_type)


@attr.s(frozen=True)
class DraftFileData(BundleFileData):
"""
Metadata about a file in a blockstore draft.
"""
modified = attr.ib(type=bool) # Was this file modified in the draft?


@attr.s(frozen=True)
class BundleLinkData:
"""
Details about a specific link in a BundleVersion or Draft
"""
name = attr.ib(type=str)
direct_dependency = attr.ib(type=Dependency)
indirect_dependencies = attr.ib(type=list) # List of Dependency objects


@attr.s(frozen=True)
class DraftLinkData(BundleLinkData):
"""
Details about a specific link in a Draft
"""
modified = attr.ib(type=bool)
39 changes: 39 additions & 0 deletions blockstore/apps/api/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
Exceptions that may be raised by the Blockstore API
"""


class BlockstoreException(Exception):
pass


class NotFound(BlockstoreException):
pass


class CollectionNotFound(NotFound):
pass


class BundleNotFound(NotFound):
pass


class BundleVersionNotFound(NotFound):
pass


class DraftNotFound(NotFound):
pass


class DraftHasNoChangesToCommit(Exception):
pass


class BundleFileNotFound(NotFound):
pass


class BundleStorageError(BlockstoreException):
pass
Loading