diff --git a/docs/index.rst b/docs/index.rst --- a/docs/index.rst +++ b/docs/index.rst @@ -10,4 +10,5 @@ cli configuration Design notes + Tutorial API reference diff --git a/docs/tutorial.md b/docs/tutorial.md new file mode 100644 --- /dev/null +++ b/docs/tutorial.md @@ -0,0 +1,82 @@ +# Software Heritage virtual filesystem (SwhFS) --- Tutorial + + +## Installation + +The Software Heritage virtual filesystem (SwhFS) is available from PyPI +as [swh.fuse](https://pypi.org/project/swh.fuse/). It can be installed from +there with `pip`: + + $ pip install swh.fuse + + +## Mount + +SwhFS is controlled by the `swh fuse` command-line interface (CLI). + +To mount the [Software Heritage][swh] [archive][archive], use the `swh fuse +mount` sub-command: + + $ mkdir swhfs + $ swh fuse mount swhfs/ + $ ls -1F swhfs/ + archive/ + meta/ + $ + +[swh]: https://www.softwareheritage.org/ +[archive]: https://archive.softwareheritage.org/ + +Once done, you can unmount SwhFS using `swh fuse umount PATH`. + + +## Object loading + +Once mounted, the archive can be navigated as if it were locally available +on-disk. Archived objects are referenced +by [Software Heritage persistent identifiers][swhid] (SWHIDs). They are loaded +on-demand from the archive and populate lazily the `archive/` directory of the +SwhFS mount point. + +[swhid]: https://docs.softwareheritage.org/devel/swh-model/persistent-identifiers.html + +For instance, `swh:1:cnt:c839dea9e8e6f0528b468214348fee8669b305b2` is the SWHID +of a well-known tiny C program, hence: + + $ cd swhfs/ + $ ls -l archive/ + total 0 + + $ cat archive/swh:1:cnt:c839dea9e8e6f0528b468214348fee8669b305b2 + #include + + int main(void) { + printf("Hello, World!\n"); + } + + $ ls -l archive/ + total 0 + -r--r--r-- 1 zack zack 67 Oct 18 09:26 swh:1:cnt:c839dea9e8e6f0528b468214348fee8669b305b2 + +There is now a (virtual) regular file under `archive/`, whose content is a C +source file. The `meta/` directory under the SwhFS mount point contain metadata +about all retrieved objects, corresponding to what +the [Software Heritage Web API][webapi] will return: + + $ cat meta/swh:1:cnt:c839dea9e8e6f0528b468214348fee8669b305b2.json | jq + { + "length": 67, + "status": "visible", + "checksums": { + "sha256": "06dfb5d936f50b3cb80152aa053724e4a18417c35f745b66ab9571c25afd0f79", + "sha1": "459ee8545e5ba6cb819ba41e6ea2f0011cedd728", + "blake2s256": "87e6ab9c92681e9a022a8f4679dcd9d9b841fe4146edcbc15329fc66d8c82b4f", + "sha1_git": "c839dea9e8e6f0528b468214348fee8669b305b2" + }, + "data_url": "https://archive.softwareheritage.org/api/1/content/sha1_git:c839dea9e8e6f0528b468214348fee8669b305b2/raw/", + "filetype_url": "https://archive.softwareheritage.org/api/1/content/sha1_git:c839dea9e8e6f0528b468214348fee8669b305b2/filetype/", + "language_url": "https://archive.softwareheritage.org/api/1/content/sha1_git:c839dea9e8e6f0528b468214348fee8669b305b2/language/", + "license_url": "https://archive.softwareheritage.org/api/1/content/sha1_git:c839dea9e8e6f0528b468214348fee8669b305b2/license/" + } + +[webapi]: https://archive.softwareheritage.org/api/