okdir
安装
pip install okdir
使用
以下以我们需要建立一个物种描述文件夹为例来说明okdir的使用,该文件夹的结构为:
.
├── metadata.json // 物种元数据,包含物种名、异名、分类等
├── thumbnail.png // 物种缩略图
├── morphology.txt // 物种描述
├── synonyms.txt // 物种异名
├── taxons.txt // 物种分类信息
├── pictures // 物种图片文件夹
│ ├── lossless // 无损图片文件夹
│ └── thumbnails // 缩略图文件夹
├── sequences // 序列文件夹
├── references.txt // 参考文献
├── distributions.txt // 分布地文件
└── collections.txt // 采集地文件
定义文件夹
from okdir import File, Dir
class PicturesDir(Dir):
lossless_dir = Dir('lossless')
thumbnails_dir = Dir('thumbnails')
class SpeciesDir(Dir):
metadata_file = File('metadata.json')
thumbnail_file = File('thumbnail.png')
morphology_file = File('morphology.txt')
synonyms_file = File('synonyms.txt')
taxons_file = File('taxons.txt')
pictures_dir = PicturesDir('pictures')
sequences_dir = Dir('sequences')
references_file = File('references.txt')
distributions_file = File('distributions.txt')
collections_file = File('collections.txt')
使用文件夹
1 实例化SpeciesDir
species_dir = SpeciesDir('/Users/dev/Tests/24120901', True)
(1)第一个参数:/Users/dev/Tests/24120901代表SpeciesDir根目录
(2)第二个参数True代表将此根目录应用到其所有的子目录、子文件中
2 检查子目录、子文件是否存在
try:
species_dir.check()
except FileNotFoundError:
print('有子目录或子文件不存在')
3 创建子目录
species_dir.mkdir()
4 创建子文件
species_dir.touch()
5 获取文件夹路径
任何File、Dir的实例都有一个path属性,为一个pathlib.Path的实例:
print(species_dir.pictures_dir.lossless_dir.path)
print(species_dir.pictures_dir.lossless_dir.path / 'foo.png')
Metadata
Release files for okdir 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| okdir-1.0.1.tar.gz | 3.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| okdir-1.0.1-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 6.1 kB
Release files / okdir-1.0.1.tar.gz
| Download URL | okdir-1.0.1.tar.gz |
|---|---|
| Size | 3.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2d6c01fc21a9bb48960814ab0e01aaa7bc1c946725dcf2d7e3bae2fd02cbc711
|
|
BLAKE2b-256 checksum How to use checksums |
6139b7b2b1683aef68356341a6170775bf10fde4c4ab15b63061b7e3cbb07a66
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.9.6
|
Release files / okdir-1.0.1-py2.py3-none-any.whl
| Download URL | okdir-1.0.1-py2.py3-none-any.whl |
|---|---|
| Size | 2.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
16404bc777ef854c408833038338aee89fadf80aaf29003533f75e769040296b
|
|
BLAKE2b-256 checksum How to use checksums |
45550a79d9556683b565ca52fdce12b5e02b764289d719f0244906a60fcfdae2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.9.6
|