How to use the datalad.interface.base.Interface function in datalad

To help you get started, we’ve selected a few datalad examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github datalad / datalad / datalad / interface / utils.py View on Github external
# far as I'm aware.
        mod = sys.modules[wrapped.__module__]
        if PY2:
            # we rely on:
            # - decorated function is method of a subclass of Interface
            # - the name of the class matches the last part of the module's name
            #   if converted to lower
            # for example:
            # ..../where/ever/mycommand.py:
            # class MyCommand(Interface):
            #     @eval_results
            #     def __call__(..)
            command_class_names = \
                [i for i in mod.__dict__
                 if type(mod.__dict__[i]) == type and
                 issubclass(mod.__dict__[i], Interface) and
                 i.lower().startswith(wrapped.__module__.split('.')[-1].replace('datalad_', '').replace('_', ''))]
            assert len(command_class_names) == 1, (command_class_names, mod.__name__)
            command_class_name = command_class_names[0]
        else:
            command_class_name = wrapped.__qualname__.split('.')[-2]
        _func_class = mod.__dict__[command_class_name]
        lgr.debug("Determined class of decorated function: %s", _func_class)

        # retrieve common options from kwargs, and fall back on the command
        # class attributes, or general defaults if needed
        kwargs = kwargs.copy()  # we will pop, which might cause side-effect
        common_params = {
            p_name: kwargs.pop(
                p_name,
                getattr(_func_class, p_name, eval_defaults[p_name]))
            for p_name in eval_params}
github datalad / datalad / datalad / interface / import_metadata.py View on Github external
URIRef, Literal, DLNS, \
    EMP, RDF, PAV, PROV, FOAF, DCTERMS
from ..cmdline.helpers import get_repo_instance
from ..log import lgr
from ..consts import HANDLE_META_DIR, REPO_STD_META_FILE
from datalad.cmdline.helpers import get_datalad_master

from six.moves.urllib.parse import urlparse


# TODO: Move elsewhere, may be even create it automatically from known
# importers
ImporterDict = {"plain-text": PlainTextImporter}


class ImportMetadata(Interface):
    """Import metadata to the repository in cwd.

    Make metadata available to datalad. This may involve metadata, that is
    available from within the repository but not yet known to datalad or
    metadata that comes from any outside location.
    There are different importers, that can be used to read that metadata
    depending on its format.

    Example:

    ~/MyHandle$ datalad import-metadata plain-text /path/to/my/textfiles

    ~/MyCollection$ datalad import-metadata plain-text /path/to/my/textfiles \
            MyHandle
    """
    # TODO: Check and doc sub entities
github datalad / datalad / datalad / distributed / create_sibling_gitlab.py View on Github external
)
from ..dochelpers import exc_str

# bound methods
from ..distribution.siblings import Siblings
from ..local.subdatasets import Subdatasets


lgr = logging.getLogger('datalad.distributed.create_sibling_gitlab')

known_layout_labels = ('hierarchy', 'collection', 'flat')
known_access_labels = ('http', 'ssh', 'ssh+http')


@build_doc
class CreateSiblingGitlab(Interface):
    """Create dataset sibling at a GitLab site

    A Git repository can be created at any location/path a given user has
    appropriate permissions for. API access and authentication are implemented
    via python-gitlab, and all its features are supported. A particular GitLab
    site must be configured in a named section of a python-gitlab.cfg file
    (see https://python-gitlab.readthedocs.io/en/stable/cli.html#configuration
    for details), such as::

      [mygit]
      url = https://git.example.com
      api_version = 4
      private_token = abcdefghijklmnopqrst

    Subsequently, this site is identified by its name ('mygit' in the example
    above).
github datalad / datalad / datalad / plugin / export_to_figshare.py View on Github external
self.ui.message(' {id} {url} - {title}'.format(**item))
            ids.append(item['id'])
        return ids

    def create_article(self, title):
        data = {
            'title': title
        }
        # we could prefill more fields interactively if desired
        result = self.post('account/articles', data=data)
        result = self.get(result['location'])
        return result


@build_doc
class ExportToFigshare(Interface):
    """Export the content of a dataset as a ZIP archive to figshare

    Very quick and dirty approach.  Ideally figshare should be supported as
    a proper git annex special remote.  Unfortunately, figshare does not support
    having directories, and can store only a flat list of files.  That makes
    it impossible for any sensible publishing of complete datasets.

    The only workaround is to publish dataset as a zip-ball, where the entire
    content is wrapped into a .zip archive for which figshare would provide a
    navigator.
    """

    from datalad.support.param import Parameter
    from datalad.distribution.dataset import datasetmethod
    from datalad.interface.utils import eval_results
    from datalad.distribution.dataset import EnsureDataset
github datalad / datalad / datalad / metadata / search.py View on Github external
from datalad.distribution.utils import get_git_dir
from ..support.param import Parameter
from ..support.constraints import EnsureNone
from ..support.constraints import EnsureChoice
from ..log import lgr
from . import get_metadata, flatten_metadata_graph, pickle

from datalad.consts import LOCAL_CENTRAL_PATH
from datalad.utils import assure_list
from datalad.utils import get_path_prefix
from datalad.support.exceptions import NoDatasetArgumentFound
from datalad.support import ansi_colors
from datalad.ui import ui


class Search(Interface):
    """Search within available in datasets' meta data

    Yields
    ------
    location : str
        (relative) path to the dataset
    report : dict
        fields which were requested by `report` option

    """

    _params_ = dict(
        dataset=Parameter(
            args=("-d", "--dataset"),
            doc="""specify the dataset to perform the query operation on. If
            no dataset is given, an attempt is made to identify the dataset
github datalad / datalad / datalad / metadata / aggregate.py View on Github external
# base path in which aggregate.json and objects is located
    agginfo_path, agg_base_path = get_ds_aggregate_db_locations(ds)
    # make DB paths on disk always relative
    json_py.dump(
        {
            op.relpath(p, start=ds.path):
            {k: op.relpath(v, start=agg_base_path) if k in location_keys else v
             for k, v in props.items()}
            for p, props in db.items()
        },
        agginfo_path
    )


@build_doc
class AggregateMetaData(Interface):
    """Aggregate metadata of one or more datasets for later query.

    Metadata aggregation refers to a procedure that extracts metadata present
    in a dataset into a portable representation that is stored a single
    standardized format. Moreover, metadata aggregation can also extract
    metadata in this format from one dataset and store it in another
    (super)dataset. Based on such collections of aggregated metadata it is
    possible to discover particular datasets and specific parts of their
    content, without having to obtain the target datasets first (see the
    DataLad 'search' command).

    To enable aggregation of metadata that are contained in files of a dataset,
    one has to enable one or more metadata extractor for a dataset. DataLad
    supports a number of common metadata standards, such as the Exchangeable
    Image File Format (EXIF), Adobe's Extensible Metadata Platform (XMP), and
    various audio file metadata systems like ID3. DataLad extension packages
github datalad / datalad / datalad / metadata / aggregate.py View on Github external
def __call__(
            path=None,
            dataset=None,
            recursive=False,
            recursion_limit=None,
            update_mode='target',
            incremental=False,
            force_extraction=False,
            save=True):
        refds_path = Interface.get_refds_path(dataset)

        # it really doesn't work without a dataset
        ds = require_dataset(
            dataset, check_installed=True, purpose='metadata aggregation')
        path = assure_list(path)
        if not path:
            # then current/reference dataset is "aggregated"
            # We should not add ds.path always since then --recursive would
            # also recurse current even if paths are given
            path.append(ds.path)

        agginfo_db_location, agg_base_path = get_ds_aggregate_db_locations(ds)
        agginfo_db = load_ds_aggregate_db(ds, abspath=True)

        to_save = []
        to_aggregate = set()
github datalad / datalad / datalad / interface / update.py View on Github external
from os import curdir
from os.path import exists, join as opj
from .base import Interface
from ..support.param import Parameter
from ..support.constraints import EnsureStr, EnsureBool, EnsureNone
from ..support.collectionrepo import CollectionRepo
from datalad.support.collection_backends import CollectionRepoBackend
from datalad.support.handle_backends import CollectionRepoHandleBackend
from ..support.handlerepo import HandleRepo
from ..cmdline.helpers import get_repo_instance
from ..log import lgr
from datalad.cmdline.helpers import get_datalad_master


class Update(Interface):
    """Update information from a remote repository.

    Gets information about changes from remote repositories. These are
    registered collections or the original source repositories of your
    installed handles, for example.

    Examples:

    Updating registered collections
      $ datalad update

    Updating a local handle
      ~/MyHandle/$ datalad update
    or
      $ datalad update MyHandle
github datalad / datalad / datalad / distribution / get.py View on Github external
for r in results_from_annex_noinfo(
            ds,
            content,
            respath_by_status,
            dir_fail_msg='could not get some content in %s %s',
            noinfo_dir_msg='nothing to get from %s',
            noinfo_file_msg='already present',
            action='get',
            logger=lgr,
            refds=refds_path):
        yield r


@build_doc
class Get(Interface):
    """Get any dataset content (files/directories/subdatasets).

    This command only operates on dataset content. To obtain a new independent
    dataset from some source use the `install` command.

    By default this command operates recursively within a dataset, but not
    across potential subdatasets, i.e. if a directory is provided, all files in
    the directory are obtained. Recursion into subdatasets is supported too. If
    enabled, relevant subdatasets are detected and installed in order to
    fulfill a request.

    Known data locations for each requested file are evaluated and data are
    obtained from some available location (according to git-annex configuration
    and possibly assigned remote priorities), unless a specific source is
    specified.
github datalad / datalad / datalad / interface / sparql_query.py View on Github external
from os.path import join as opj

from appdirs import AppDirs
from six import string_types

from .base import Interface
from datalad.support.param import Parameter
from datalad.support.constraints import EnsureStr, EnsureNone, EnsureListOf
from datalad.support.collectionrepo import CollectionRepo
from datalad.support.collection import MetaCollection
from datalad.cmdline.helpers import get_datalad_master


class SPARQLQuery(Interface):
    """Query metadata by a SPARQL query string."""

    _params_ = dict(
        query=Parameter(
            doc="string containing the SPARQL query",
            constraints=EnsureStr()),
        collections=Parameter(
            args=('collections',),
            nargs='*',
            doc="collections to query; if no collection is given the query is"
                "performed on all known collections",
            constraints=EnsureListOf(string_types) | EnsureNone()))

    @staticmethod
    def __call__(query, collections=None):
        """