treejson-cli 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- treejson_cli-1.0.0/PKG-INFO +81 -0
- treejson_cli-1.0.0/README.md +61 -0
- treejson_cli-1.0.0/pyproject.toml +33 -0
- treejson_cli-1.0.0/setup.cfg +4 -0
- treejson_cli-1.0.0/src/main.py +100 -0
- treejson_cli-1.0.0/src/treejson_cli.egg-info/PKG-INFO +81 -0
- treejson_cli-1.0.0/src/treejson_cli.egg-info/SOURCES.txt +10 -0
- treejson_cli-1.0.0/src/treejson_cli.egg-info/dependency_links.txt +1 -0
- treejson_cli-1.0.0/src/treejson_cli.egg-info/entry_points.txt +2 -0
- treejson_cli-1.0.0/src/treejson_cli.egg-info/requires.txt +1 -0
- treejson_cli-1.0.0/src/treejson_cli.egg-info/top_level.txt +1 -0
- treejson_cli-1.0.0/tests/test_dirjson.py +15 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: treejson-cli
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: It shows the nested directory structure in JSON or YAML.
|
|
5
|
+
Author-email: masaniki <masaniki.software@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Repository, https://github.com/masaniki/python-treejson-cli
|
|
8
|
+
Project-URL: Document, https://github.com/masaniki/python-treejson-cli/blob/master/README.md
|
|
9
|
+
Project-URL: Issues, https://github.com/masaniki/python-treejson-cli/issues
|
|
10
|
+
Classifier: Development Status :: 1 - Planning
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Topic :: Terminals
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Natural Language :: English
|
|
16
|
+
Classifier: Natural Language :: Japanese
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
Requires-Dist: PyYAML
|
|
20
|
+
|
|
21
|
+
# Abstract
|
|
22
|
+
It shows the nested directory structure in JSON or YAML.
|
|
23
|
+
|
|
24
|
+
Japanse document is [here](docs/README_JP.md).
|
|
25
|
+
|
|
26
|
+
# How to install
|
|
27
|
+
`pip install treejson-cli`
|
|
28
|
+
|
|
29
|
+
## Package Dependencies
|
|
30
|
+
|
|
31
|
+
The following packages may not work properly if they are not installed:
|
|
32
|
+
|
|
33
|
+
- [PyYAML](https://pypi.org/project/PyYAML/): Most popular YAML parser for Python.
|
|
34
|
+
|
|
35
|
+
# How to run
|
|
36
|
+
`treejson <directory>`
|
|
37
|
+
|
|
38
|
+
The directory structure is compiled into JSON and output to standard output.
|
|
39
|
+
|
|
40
|
+
## Options
|
|
41
|
+
|
|
42
|
+
Detail document is [here](docs/formal_document.md).
|
|
43
|
+
|
|
44
|
+
`[-h|--help]`
|
|
45
|
+
|
|
46
|
+
Shows help message.
|
|
47
|
+
|
|
48
|
+
`[-v|--version]`
|
|
49
|
+
|
|
50
|
+
Shows version message.
|
|
51
|
+
|
|
52
|
+
`[-y|--yaml]`
|
|
53
|
+
|
|
54
|
+
Outputs as a YAML format.
|
|
55
|
+
|
|
56
|
+
`[-a|-all]`
|
|
57
|
+
|
|
58
|
+
Visits hidden file.
|
|
59
|
+
|
|
60
|
+
`[-d|--depth] <depth>`
|
|
61
|
+
|
|
62
|
+
Specifies the depth of tree oftraversal.
|
|
63
|
+
|
|
64
|
+
If depth=0, it shows current directory.
|
|
65
|
+
|
|
66
|
+
`[-f|--file] <output_file>`
|
|
67
|
+
|
|
68
|
+
Outputs as a JSON or YAML file.
|
|
69
|
+
|
|
70
|
+
## Examples
|
|
71
|
+
- `treejson tests/sample`
|
|
72
|
+
```
|
|
73
|
+
{'sample': [{'parent01': [{'child01_01': ['grandchild01.txt']}, {'child01_02': ['grandchild02.txt']}, 'child01_03.txt']}, {'parent02': [{'child02_01': ['grandchild02_01.txt']}]}]}
|
|
74
|
+
```
|
|
75
|
+
- `treejson tests/sample -f tests/output.json`
|
|
76
|
+
|
|
77
|
+
[tests/output.json](tests/output.json)
|
|
78
|
+
|
|
79
|
+
- `treejson tests/sample -yf tests/output.yaml`
|
|
80
|
+
|
|
81
|
+
[tests/output.yaml](tests/output.yaml)
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Abstract
|
|
2
|
+
It shows the nested directory structure in JSON or YAML.
|
|
3
|
+
|
|
4
|
+
Japanse document is [here](docs/README_JP.md).
|
|
5
|
+
|
|
6
|
+
# How to install
|
|
7
|
+
`pip install treejson-cli`
|
|
8
|
+
|
|
9
|
+
## Package Dependencies
|
|
10
|
+
|
|
11
|
+
The following packages may not work properly if they are not installed:
|
|
12
|
+
|
|
13
|
+
- [PyYAML](https://pypi.org/project/PyYAML/): Most popular YAML parser for Python.
|
|
14
|
+
|
|
15
|
+
# How to run
|
|
16
|
+
`treejson <directory>`
|
|
17
|
+
|
|
18
|
+
The directory structure is compiled into JSON and output to standard output.
|
|
19
|
+
|
|
20
|
+
## Options
|
|
21
|
+
|
|
22
|
+
Detail document is [here](docs/formal_document.md).
|
|
23
|
+
|
|
24
|
+
`[-h|--help]`
|
|
25
|
+
|
|
26
|
+
Shows help message.
|
|
27
|
+
|
|
28
|
+
`[-v|--version]`
|
|
29
|
+
|
|
30
|
+
Shows version message.
|
|
31
|
+
|
|
32
|
+
`[-y|--yaml]`
|
|
33
|
+
|
|
34
|
+
Outputs as a YAML format.
|
|
35
|
+
|
|
36
|
+
`[-a|-all]`
|
|
37
|
+
|
|
38
|
+
Visits hidden file.
|
|
39
|
+
|
|
40
|
+
`[-d|--depth] <depth>`
|
|
41
|
+
|
|
42
|
+
Specifies the depth of tree oftraversal.
|
|
43
|
+
|
|
44
|
+
If depth=0, it shows current directory.
|
|
45
|
+
|
|
46
|
+
`[-f|--file] <output_file>`
|
|
47
|
+
|
|
48
|
+
Outputs as a JSON or YAML file.
|
|
49
|
+
|
|
50
|
+
## Examples
|
|
51
|
+
- `treejson tests/sample`
|
|
52
|
+
```
|
|
53
|
+
{'sample': [{'parent01': [{'child01_01': ['grandchild01.txt']}, {'child01_02': ['grandchild02.txt']}, 'child01_03.txt']}, {'parent02': [{'child02_01': ['grandchild02_01.txt']}]}]}
|
|
54
|
+
```
|
|
55
|
+
- `treejson tests/sample -f tests/output.json`
|
|
56
|
+
|
|
57
|
+
[tests/output.json](tests/output.json)
|
|
58
|
+
|
|
59
|
+
- `treejson tests/sample -yf tests/output.yaml`
|
|
60
|
+
|
|
61
|
+
[tests/output.yaml](tests/output.yaml)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools >= 77.0.3"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "treejson-cli"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name="masaniki", email="masaniki.software@gmail.com" },
|
|
10
|
+
]
|
|
11
|
+
description = "It shows the nested directory structure in JSON or YAML."
|
|
12
|
+
dependencies = ["PyYAML"]
|
|
13
|
+
readme = "README.md"
|
|
14
|
+
requires-python = ">=3.9"
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 1 - Planning",
|
|
17
|
+
"Environment :: Console",
|
|
18
|
+
"Topic :: Terminals",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Natural Language :: English",
|
|
22
|
+
"Natural Language :: Japanese"
|
|
23
|
+
]
|
|
24
|
+
license = "MIT"
|
|
25
|
+
license-files = ["LICENCSE.txt"]
|
|
26
|
+
|
|
27
|
+
[project.scripts]
|
|
28
|
+
treejson = "main:mainCLI"
|
|
29
|
+
|
|
30
|
+
[project.urls]
|
|
31
|
+
Repository = "https://github.com/masaniki/python-treejson-cli"
|
|
32
|
+
Document = "https://github.com/masaniki/python-treejson-cli/blob/master/README.md"
|
|
33
|
+
Issues = "https://github.com/masaniki/python-treejson-cli/issues"
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
import argparse
|
|
4
|
+
import yaml
|
|
5
|
+
import json
|
|
6
|
+
|
|
7
|
+
VERSION="v1.0.0"
|
|
8
|
+
|
|
9
|
+
def mainCLI():
|
|
10
|
+
"""
|
|
11
|
+
Smry: CLIを処理する関数。
|
|
12
|
+
|
|
13
|
+
Returns:
|
|
14
|
+
Type: dict
|
|
15
|
+
Smry: {directory名(str):[i(int):i番目の子directory名(str)]}という木構造。
|
|
16
|
+
"""
|
|
17
|
+
parser=argparse.ArgumentParser(prog="PROG")
|
|
18
|
+
parser.add_argument("dirName",type=str,default=None,help="put in directory name. Both absolute and relative is OK.")
|
|
19
|
+
parser.add_argument("-v","--version",action="version",version=f"treejson {VERSION}")
|
|
20
|
+
parser.add_argument("-y","--yaml",action="store_true",help="output as a YAML format.")
|
|
21
|
+
parser.add_argument("-a","--all",action="store_true",help="visit hidden file.")
|
|
22
|
+
parser.add_argument("-f","--file",type=str,help="output as a file.")
|
|
23
|
+
parser.add_argument("-d","--depth",type=int,help="specify maximum depth.")
|
|
24
|
+
args=parser.parse_args()
|
|
25
|
+
dirname=Path(args.dirName)
|
|
26
|
+
outDict=directoryBFS(dirname.resolve(),maxDepth=args.depth,isAll=args.all)
|
|
27
|
+
if(args.yaml):
|
|
28
|
+
if(args.file is None):
|
|
29
|
+
yaml.safe_dump(outDict,sys.stdout)
|
|
30
|
+
else:
|
|
31
|
+
with open(args.file,mode="w",encoding="utf-8") as f:
|
|
32
|
+
yaml.safe_dump(outDict,f)
|
|
33
|
+
else:
|
|
34
|
+
if(args.file is None):
|
|
35
|
+
print(outDict)
|
|
36
|
+
else:
|
|
37
|
+
with open(args.file,mode="w",encoding="utf-8") as f:
|
|
38
|
+
json.dump(outDict,f)
|
|
39
|
+
|
|
40
|
+
def directoryBFS(startDir:Path,maxDepth:int=None,isAll:bool=None):
|
|
41
|
+
"""
|
|
42
|
+
Smry: directory構造を幅優先探索する関数。
|
|
43
|
+
|
|
44
|
+
Args:
|
|
45
|
+
startDir:
|
|
46
|
+
Type: Path.
|
|
47
|
+
Smry: 探索を開始するdirectory名。
|
|
48
|
+
maxDepth:
|
|
49
|
+
Type: Int.
|
|
50
|
+
Smry: 探索の最大の深さ。
|
|
51
|
+
Expl:
|
|
52
|
+
- current directoryは深さ0。
|
|
53
|
+
- 「maxDepth<現在の深さ」の時に探索打ち切り。
|
|
54
|
+
Default: 255.
|
|
55
|
+
isAll:
|
|
56
|
+
Type: Bool.
|
|
57
|
+
Smry: {True⇒隠しfileも探索, False⇒隠しfileを通過。}
|
|
58
|
+
Default: false.
|
|
59
|
+
Returns:
|
|
60
|
+
Type: dict
|
|
61
|
+
Smry: {directory名(str):[i(int):i番目の子directory名(str)]}という木構造。
|
|
62
|
+
Expl:
|
|
63
|
+
- {directory名(str):[i(int):i番目の子directory名|file名(str)]}。
|
|
64
|
+
- file名の時は、終端nodeになる。
|
|
65
|
+
"""
|
|
66
|
+
if(maxDepth is None):
|
|
67
|
+
maxDepth=255
|
|
68
|
+
if(isAll is None):
|
|
69
|
+
isAll=False
|
|
70
|
+
outDict={startDir.name:[]}
|
|
71
|
+
visitQueue=[startDir] #訪れるdirectory(Path型)を格納する。
|
|
72
|
+
listQueue=[outDict[startDir.name]] #訪れるdirectoryの子要素のlist型を格納する。
|
|
73
|
+
depthQueue=[0] #訪れるdiectoryの深さ(int型)を格納する。
|
|
74
|
+
while(True):
|
|
75
|
+
if(visitQueue==[]):
|
|
76
|
+
break
|
|
77
|
+
curDir=visitQueue.pop(0)
|
|
78
|
+
curList=listQueue.pop(0)
|
|
79
|
+
curDepth=depthQueue.pop(0)
|
|
80
|
+
nextDepth=curDepth+1
|
|
81
|
+
if(maxDepth<nextDepth):
|
|
82
|
+
continue
|
|
83
|
+
for childPath in curDir.iterdir():
|
|
84
|
+
childName=childPath.name
|
|
85
|
+
firstChr=childName[0]
|
|
86
|
+
if((not isAll) and firstChr=='.'):
|
|
87
|
+
continue
|
|
88
|
+
if(childPath.is_file()):
|
|
89
|
+
curList.append(childName)
|
|
90
|
+
else:
|
|
91
|
+
childDict={childName:[]}
|
|
92
|
+
curList.append(childDict)
|
|
93
|
+
visitQueue.append(childPath)
|
|
94
|
+
listQueue.append(childDict[childName])
|
|
95
|
+
depthQueue.append(nextDepth)
|
|
96
|
+
return outDict
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
if(__name__=="__main__"):
|
|
100
|
+
mainCLI()
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: treejson-cli
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: It shows the nested directory structure in JSON or YAML.
|
|
5
|
+
Author-email: masaniki <masaniki.software@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Repository, https://github.com/masaniki/python-treejson-cli
|
|
8
|
+
Project-URL: Document, https://github.com/masaniki/python-treejson-cli/blob/master/README.md
|
|
9
|
+
Project-URL: Issues, https://github.com/masaniki/python-treejson-cli/issues
|
|
10
|
+
Classifier: Development Status :: 1 - Planning
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Topic :: Terminals
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Natural Language :: English
|
|
16
|
+
Classifier: Natural Language :: Japanese
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
Requires-Dist: PyYAML
|
|
20
|
+
|
|
21
|
+
# Abstract
|
|
22
|
+
It shows the nested directory structure in JSON or YAML.
|
|
23
|
+
|
|
24
|
+
Japanse document is [here](docs/README_JP.md).
|
|
25
|
+
|
|
26
|
+
# How to install
|
|
27
|
+
`pip install treejson-cli`
|
|
28
|
+
|
|
29
|
+
## Package Dependencies
|
|
30
|
+
|
|
31
|
+
The following packages may not work properly if they are not installed:
|
|
32
|
+
|
|
33
|
+
- [PyYAML](https://pypi.org/project/PyYAML/): Most popular YAML parser for Python.
|
|
34
|
+
|
|
35
|
+
# How to run
|
|
36
|
+
`treejson <directory>`
|
|
37
|
+
|
|
38
|
+
The directory structure is compiled into JSON and output to standard output.
|
|
39
|
+
|
|
40
|
+
## Options
|
|
41
|
+
|
|
42
|
+
Detail document is [here](docs/formal_document.md).
|
|
43
|
+
|
|
44
|
+
`[-h|--help]`
|
|
45
|
+
|
|
46
|
+
Shows help message.
|
|
47
|
+
|
|
48
|
+
`[-v|--version]`
|
|
49
|
+
|
|
50
|
+
Shows version message.
|
|
51
|
+
|
|
52
|
+
`[-y|--yaml]`
|
|
53
|
+
|
|
54
|
+
Outputs as a YAML format.
|
|
55
|
+
|
|
56
|
+
`[-a|-all]`
|
|
57
|
+
|
|
58
|
+
Visits hidden file.
|
|
59
|
+
|
|
60
|
+
`[-d|--depth] <depth>`
|
|
61
|
+
|
|
62
|
+
Specifies the depth of tree oftraversal.
|
|
63
|
+
|
|
64
|
+
If depth=0, it shows current directory.
|
|
65
|
+
|
|
66
|
+
`[-f|--file] <output_file>`
|
|
67
|
+
|
|
68
|
+
Outputs as a JSON or YAML file.
|
|
69
|
+
|
|
70
|
+
## Examples
|
|
71
|
+
- `treejson tests/sample`
|
|
72
|
+
```
|
|
73
|
+
{'sample': [{'parent01': [{'child01_01': ['grandchild01.txt']}, {'child01_02': ['grandchild02.txt']}, 'child01_03.txt']}, {'parent02': [{'child02_01': ['grandchild02_01.txt']}]}]}
|
|
74
|
+
```
|
|
75
|
+
- `treejson tests/sample -f tests/output.json`
|
|
76
|
+
|
|
77
|
+
[tests/output.json](tests/output.json)
|
|
78
|
+
|
|
79
|
+
- `treejson tests/sample -yf tests/output.yaml`
|
|
80
|
+
|
|
81
|
+
[tests/output.yaml](tests/output.yaml)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
src/main.py
|
|
4
|
+
src/treejson_cli.egg-info/PKG-INFO
|
|
5
|
+
src/treejson_cli.egg-info/SOURCES.txt
|
|
6
|
+
src/treejson_cli.egg-info/dependency_links.txt
|
|
7
|
+
src/treejson_cli.egg-info/entry_points.txt
|
|
8
|
+
src/treejson_cli.egg-info/requires.txt
|
|
9
|
+
src/treejson_cli.egg-info/top_level.txt
|
|
10
|
+
tests/test_dirjson.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
PyYAML
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
main
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
import json
|
|
3
|
+
|
|
4
|
+
if(__name__=="__main__"):
|
|
5
|
+
parentDirectory=Path(__file__).parent
|
|
6
|
+
outputFile=parentDirectory/"output.json"
|
|
7
|
+
expectedFile=parentDirectory/"expected.json"
|
|
8
|
+
with open(outputFile,mode="r",encoding="utf-8") as f:
|
|
9
|
+
outDict=json.load(f)
|
|
10
|
+
with open(expectedFile,mode="r",encoding="utf-8") as f:
|
|
11
|
+
expDict=json.load(f)
|
|
12
|
+
if(outDict==expDict):
|
|
13
|
+
assert True
|
|
14
|
+
else:
|
|
15
|
+
assert False
|