heliport.version_control package
Subpackages
- heliport.version_control.migrations package
- Submodules
- heliport.version_control.migrations.0001_initial module
- heliport.version_control.migrations.0002_remove_versioncontrol_link module
- heliport.version_control.migrations.0003_dbgithubfile module
- heliport.version_control.migrations.0004_versioncontrolfile_delete_dbgithubfile module
- Module contents
Submodules
heliport.version_control.admin module
Registers Django admin pages.
See django.contrib.admin.ModelAdmin
from Django documentation.
heliport.version_control.apps module
Django app configuration.
Some HELIPORT hooks can be registered in app config django.apps.AppConfig.ready()
.
See also Django documentation
heliport.version_control.conf module
Additional settings for this app.
See also django appconf
- class heliport.version_control.conf.VersionControlAppConf(**kwargs)
Bases:
AppConf
Settings of the
heliport.version_control
app.All settings in this class can be overwritten in settings.py
- API_MAPPING = {re.compile('https://codebase\\.helmholtz\\.cloud/(?P<project>[^/]+(/[^/]*[^-/][^/]*)*)/-/tree/(?P<branch>[^/]+)/(?P<path>.*)'): ('GitLab', 'https://codebase.helmholtz.cloud/api/v4'), re.compile('https://codebase\\.helmholtz\\.cloud/(?P<project>[^/]+(/[^/]*[^-/][^/]*)*)/?'): ('GitLab', 'https://codebase.helmholtz.cloud/api/v4'), re.compile('https://github\\.com/(?P<group>[^/]+)/(?P<project>[^/]+)/?'): ('GitHub', 'https://api.github.com'), re.compile('https://github\\.com/(?P<group>[^/]+)/(?P<project>[^/]+)/tree/(?P<branch>[^/]+)/(?P<path>.*)'): ('GitHub', 'https://api.github.com'), re.compile('https://gitlab\\.com/(?P<project>[^/]+(/[^/]*[^-/][^/]*)*)/-/tree/(?P<branch>[^/]+)/(?P<path>.*)'): ('GitLab', 'https://gitlab.com/api/v4'), re.compile('https://gitlab\\.com/(?P<project>[^/]+(/[^/]*[^-/][^/]*)*)/?'): ('GitLab', 'https://gitlab.com/api/v4'), re.compile('https://gitlab\\.hzdr\\.de/(?P<project>[^/]+(/[^/]*[^-/][^/]*)*)/-/tree/(?P<branch>[^/]+)/(?P<path>.*)'): ('GitLab', 'https://codebase.helmholtz.cloud/api/v4'), re.compile('https://gitlab\\.hzdr\\.de/(?P<project>[^/]+(/[^/]*[^-/][^/]*)*)/?'): ('GitLab', 'https://codebase.helmholtz.cloud/api/v4')}
- gitlab_path_pattern = '(?P<project>[^/]+(/[^/]*[^-/][^/]*)*)/-/tree/(?P<branch>[^/]+)/(?P<path>.*)'
- gitlab_project_pattern = '(?P<project>[^/]+(/[^/]*[^-/][^/]*)*)'
- path_pattern = '(?P<branch>[^/]+)/(?P<path>.*)'
heliport.version_control.interface module
Module with special name “interface” hooks into HELIPORT.
Some functions and heliport.core.app_interaction.Module
subclasses are detected
by HELIPORT and control how HELIPORT uses this app.
Note that this module must be imported in __init__.py of the django app.
- class heliport.version_control.interface.VersionControlModule
Bases:
DigitalObjectModule
Show version controls in HELIPORT project graph.
- get_url(project)
Return the URL for the entry point of this module.
- icon = 'fa-brands fa-git-alt'
- module_id = 'version_control'
- name = 'Version Control'
- property object_class
VersionControl.
- heliport.version_control.interface.get_search_url()
Return the search URL for this app.
This URL is used to implement the global HELIPORT string search.
heliport.version_control.models module
Contains django.db.models.Model
classes for Django ORM.
See Quick example from Django documentation.
In HELIPORT the heliport.core.models.DigitalObject
can be subclassed for models
containing metadata in a project.
- class heliport.version_control.models.BaseVersionControlObj(link, label=None, description=None)
Bases:
ABC
,GeneralDigitalObject
Base class for files and directories inside version control systems.
- as_digital_object(context: Context)
Transform the current object into a digital object in the database; reuse existing.
- as_rdf() RootedRDFGraph
Transform to rdf by link.
- as_text() str
Use label if it exists, link otherwise.
- classmethod build_instance(params, **kwargs)
Get a new instance of this type, from identifying parameters.
See
heliport.core.digital_object_resolution
for reason.See
get_identifying_params()
for where the params come from.
- get_identifying_params() Dict[str, str]
Parameters which can be used to resolve this object.
- abstract property get_model_class: Type[DigitalObject]
Get the digital object subclass where this type can be stored in the database.
- get_new(context, **kwargs)
Get a new database object for the current instance.
- classmethod resolve(params: Dict[str, str], context: Context) GeneralDigitalObject | None
Resolve from identifying parameters.
- class heliport.version_control.models.GitHubDirectory(regex_match: Match, api_url: str, context: Context)
Bases:
Directory
GitHub specific directory object.
- get_file_info() Dict[str, str]
No file info available.
- get_parts() Iterable[FileObj | DirectoryObj]
Get files and directories inside this directory via api.
- class heliport.version_control.models.GitHubFile(link, context)
Bases:
StreamOrSmallFile
,File
GitHub specific readable file.
- get_file_info() Dict[str, str]
Include the size for the user to see.
- link: str
The GitHub API link where the file metadata can be downloaded
- property metadata
Get cached or new
VersionControlFileMetadata
.
- mimetype() str
Guess mimetype from file name; default to text/plain.
- open()
Open file; use cached content for small files or make a streaming request.
- size() int | None
Get file size in bytes.
- class heliport.version_control.models.GitLabDirectory(regex_match: Match, api_url: str, context: Context)
Bases:
Directory
gitlab specific directory implementation.
- get_file_info() Dict[str, str]
No useful file info available.
- get_parts() Iterable[FileObj | DirectoryObj]
Retrieve files and directories inside this directory from gitlab.
- class heliport.version_control.models.GitLabFile(link, context)
Bases:
StreamOrSmallFile
,File
gitlab specific readable file.
- get_file_info() Dict[str, str]
Size is not included in file info because it is slow (many requests).
- property metadata
Get metadata json from gitlab or use cached one.
- mimetype() str
Guess mimetype from file name; default is text/plain.
- open()
Open cached content or make a streaming request.
- size() int | None
File size in bytes.
- url_in_api: str
The GitLab API url where file can be downloaded. This must contain “…/raw?ref=…” because the metadata url is obtained by removing “/raw” from before the query part of the url
- class heliport.version_control.models.StreamOrSmallFile
Bases:
File
,ABC
Base class for files that can be streamed if large or can use cached content.
- close()
Close streams and set back to
None
.
- read(number_of_bytes=None) bytes
Read bytes from the stream or cached content.
- class heliport.version_control.models.TokenInfo(system: str, user: HeliportUser)
Bases:
object
to cache the correct GitLab or GitHub token.
- system: str
e.g. “GitHub” or “GitLab”
- user: HeliportUser
the user
- class heliport.version_control.models.VersionControl(*args, **kwargs)
Bases:
DigitalObject
,DirectoryObj
Represent a version control project in the database as digital object.
- exception DoesNotExist
Bases:
DoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- digitalobject_ptr
Accessor to the related object on the forward side of a one-to-one relation.
In the example:
class Restaurant(Model): place = OneToOneField(Place, related_name='restaurant')
Restaurant.place
is aForwardOneToOneDescriptor
instance.
- digitalobject_ptr_id
- property icon
The icon of the system where this version control resides in.
- property is_subdir: bool | None
Determine if this is a version control project itself or a directory inside another version control project.
- link
Defines a python descriptor for metadata properties.
This descriptor should be used on
DigitalObject
subclasses.In principle most properties of subclasses of
DigitalObject
can be considered “Metadata Properties” however usingMetadataFiled
has the added convenience that metadata serialization is automatically taken care of just by specifying the metadata property in the class definition. On top of that Storage if the property is public and can be shown on the landing page to everybody is handled without extra code.Use it for example like this:
class MyClass(DigitalObject): link = MetadataField(Vocabulary.primary_topic, url_normalizer)
The first argument comes from
Vocabulary
and defines the metadata property to use for serialization. The second argument is optional and is just a function that is called before setting the value.heliport.core.utils.normalization.url_normalizer()
is used in the example.The values are stored as
DigitalObjectAttributes
and identified by thir property as well as an additional identification string that is by default “attribute”. This means if you have multiple properties with the same metadata property you need to set therole_name_in_db
parameter uniquely for each. Also if you change the metadata attribute or therole_name_in_db
you need to write a database migration.
- property unsupported
- version_control_id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- class heliport.version_control.models.VersionControlFile(*args, **kwargs)
Bases:
DigitalObject
,FileObj
represent a file of a version control system inside the database.
- exception DoesNotExist
Bases:
DoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- digitalobject_ptr
Accessor to the related object on the forward side of a one-to-one relation.
In the example:
class Restaurant(Model): place = OneToOneField(Place, related_name='restaurant')
Restaurant.place
is aForwardOneToOneDescriptor
instance.
- digitalobject_ptr_id
- git_hub_file_id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- link
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- system
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- class heliport.version_control.models.VersionControlFileMetadata(user: HeliportUser, link: str, system: str)
Bases:
object
implement
heliport.core.utils.context.Description
.- generate(context)
Fetch json from link.
- link: str
- system: str
- user: HeliportUser
- class heliport.version_control.models.VersionControlFileObj(link: str, system: str, label=None, description=None)
Bases:
FileObj
,BaseVersionControlObj
represent a file from version control not stored in the database.
- classmethod build_instance(params, **kwargs)
Use also system to resolve files; see also base implementation.
- static get_existing(link, context)
Define how to get an existing equivalent existing file from the database.
- get_identifying_params() Dict[str, str]
Use also system to resolve files; see also base implementation.
- property get_model_class: Type[DigitalObject]
Version control file objects can be stored in the database as
VersionControlFile
.
- get_new(context, **kwargs)
Include system and link in new instances; see also base implementation.
- static type_id() str
Represent type as “VersionControlFile” in urls.
- class heliport.version_control.models.VersionControlObj(link, label=None, description=None)
Bases:
BaseVersionControlObj
,DirectoryObj
Represent a version control or version control directory not stored in the database.
- static get_existing(link, context)
Implement how to get existing equivalent object from database if it exists.
- property get_model_class: Type[DigitalObject]
Define what django model class should be used to store this object in DB.
- get_new(context, **kwargs)
Also use link as parameter; see also base class implementation.
- static type_id() str
Use this string to represent the version control type in URLs.
- heliport.version_control.models.build_directory(link: str, context: Context) Directory
Build an instance of the appropriate type of browsable directory for the given link.
- heliport.version_control.models.fetch_json(url, system, obj_for_error: str = 'version control', only_list=False, context=None, user: HeliportUser | None = None) Any
Fetch json including error handling.
- heliport.version_control.models.get_with_token(system: str, url: str, user: HeliportUser, context: Context | None = None)
Make an API GET request to the url and return the result. Try to find a matching token; use context for caching it.
- heliport.version_control.models.make_token_request(url, login)
Make a GET request to the url using authorization header from token login.
heliport.version_control.serializers module
This module is for serialization into Datacite, RDF and JSON.
The JSON format is used for API endpoints via Django rest framework. Using this, it is typical to put the serializer classes into a “serializers.py” file.
For the serialization into RDF, attributes are described.
See heliport.core.attribute_description.BaseAttribute
for more detail.
- class heliport.version_control.serializers.RepoDATACITESerializer
Bases:
DigitalObjectDATACITESerializer
- resource_type(repo)
heliport.version_control.tests module
Test the behaviour of this app.
This follows the Writing tests guide in Django.
- class heliport.version_control.tests.SearchAndAPITest(methodName='runTest')
Bases:
TestCase
Test search including via API.
- setUp()
Set up project and logged-in heliport user.
- test_access_search()
Test that search URL is accessible.
- test_api()
Test api.
- test_version_control_findable()
Test that version control project metadata is findable.
heliport.version_control.urls module
Map django views to urls.
See this Example including explanation from the Django documentation.
heliport.version_control.views module
Contains Django View classes to handle HTTP requests.
See Using class-based views from Django
documentation.
In HELIPORT heliport.core.mixins
are used to create uniform views. Also
heliport.core.views.generic.HeliportObjectListView
is used to quicly create a
typical HELIPORT list view.
- class heliport.version_control.views.SearchView(**kwargs)
Bases:
HeliportLoginRequiredMixin
,TemplateView
Get and render search results.
- get_context_data(**kwargs)
Add extra context for rendering template (Called by django base view).
The extra context includes the search results.
- template_name = 'version_control/search.html'
- class heliport.version_control.views.VersionControlUpdateView(**kwargs)
Bases:
HeliportObjectMixin
,UpdateView
Show list of version control projects linked to a HELIPORT project and edit one.
See also
VersionControlView
which contains overlapping functionality.- fields = ['label']
- form_valid(form)
Set link, which must be set after save.
The link is a
heliport.core.models.MetadataField
.Called by Django after form is valid.
- get_context_data(**kwargs)
Add extra context for rendering template (Called by django base view).
- get_success_url()
Go back to list. Called by Django.
- model
alias of
VersionControl
- template_name = 'version_control/version_control.html'
- class heliport.version_control.views.VersionControlView(**kwargs)
Bases:
HeliportProjectMixin
,CreateView
Show list of version control projects linked to a HELIPORT project.
See also
VersionControlUpdateView
which contains overlapping functionality.- download_projects(page, search=None, starred=False)
Get version control projects of user via API.
- fields = ['label']
- form_valid(form)
Set additional info for newly created version control project metadata.
Called by Django after form is valid.
- get_context_data(**kwargs)
Add extra context for rendering template (Called by django base view).
The extra context includes the users projects that are queried via API from version control.
- get_success_url()
Reload the list. Called by Django.
- static insert_import_info(project)
Add info to VC project that can be used to import it to HELIPORT.
- model
alias of
VersionControl
- post(request, *args, **kwargs)
Handle post request.
Handle addition or removal of Version control projects to HELIPORT.
- projects_per_page = 30
- template_name = 'version_control/version_control.html'
- class heliport.version_control.views.VersionControlViewSet(**kwargs)
Bases:
HeliportModelViewSet
Version Control.
- filter_backends = [<class 'rest_framework.filters.SearchFilter'>, <class 'django_filters.rest_framework.backends.DjangoFilterBackend'>]
- filterset_fields = ['version_control_id', 'label']
- get_queryset()
Get version controls that current user has access to.
- search_fields = ['attributes__value']
- serializer_class
alias of
VersionControlSerializer
Module contents
App to store metadata about and allow access to git repositories.
The interface
module is imported to the top level of the package for HELIPORT app
interface discovery (see heliport.core.app_interaction.get_heliport_apps()
).