39 lines
1 KiB
Text
39 lines
1 KiB
Text
$ mkdir .datalad/procedures
|
|
$ cat << EOT > .datalad/procedures/example.py
|
|
"""A simple procedure to create a file 'example' and store
|
|
it in Git, and a file 'example2' and annex it. The contents
|
|
of 'example' must be defined with a positional argument."""
|
|
|
|
import sys
|
|
import os.path as op
|
|
from datalad.distribution.dataset import require_dataset
|
|
from datalad.utils import create_tree
|
|
|
|
ds = require_dataset(
|
|
sys.argv[1],
|
|
check_installed=True,
|
|
purpose='showcase an example procedure')
|
|
|
|
# this is the content for file "example"
|
|
content = """\
|
|
This file was created by a custom procedure! Neat, huh?
|
|
"""
|
|
|
|
# create a directory structure template. Write
|
|
tmpl = {
|
|
'somedir': {
|
|
'example': content,
|
|
},
|
|
'example2': sys.argv[2] if sys.argv[2] else "got no input"
|
|
}
|
|
|
|
# actually create the structure in the dataset
|
|
create_tree(ds.path, tmpl)
|
|
|
|
# rule to store 'example' Git
|
|
ds.repo.set_gitattributes([('example', {'annex.largefiles': 'nothing'})])
|
|
|
|
# save the dataset modifications
|
|
ds.save(message="Apply custom procedure")
|
|
|
|
EOT
|