treescript-builder 0.1.7__tar.gz → 0.1.8__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.
- {treescript_builder-0.1.7/treescript_builder.egg-info → treescript_builder-0.1.8}/PKG-INFO +1 -1
- {treescript_builder-0.1.7 → treescript_builder-0.1.8}/setup.py +1 -1
- {treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder/data/path_stack.py +1 -15
- {treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder/data/tree_state.py +9 -9
- {treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder/input/line_reader.py +49 -23
- {treescript_builder-0.1.7 → treescript_builder-0.1.8/treescript_builder.egg-info}/PKG-INFO +1 -1
- {treescript_builder-0.1.7 → treescript_builder-0.1.8}/LICENSE +0 -0
- {treescript_builder-0.1.7 → treescript_builder-0.1.8}/README.md +0 -0
- {treescript_builder-0.1.7 → treescript_builder-0.1.8}/setup.cfg +0 -0
- {treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder/__init__.py +0 -0
- {treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder/__main__.py +0 -0
- {treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder/data/__init__.py +0 -0
- {treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder/data/data_directory.py +0 -0
- {treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder/data/instruction_data.py +0 -0
- {treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder/data/tree_data.py +0 -0
- {treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder/input/__init__.py +0 -0
- {treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder/input/argument_data.py +0 -0
- {treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder/input/argument_parser.py +0 -0
- {treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder/input/file_validation.py +0 -0
- {treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder/input/input_data.py +0 -0
- {treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder/input/string_validation.py +0 -0
- {treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder/tree/__init__.py +0 -0
- {treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder/tree/build_validation.py +0 -0
- {treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder/tree/tree_builder.py +0 -0
- {treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder/tree/tree_trimmer.py +0 -0
- {treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder/tree/trim_validation.py +0 -0
- {treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder.egg-info/SOURCES.txt +0 -0
- {treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder.egg-info/dependency_links.txt +0 -0
- {treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder.egg-info/entry_points.txt +0 -0
- {treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: treescript-builder
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.8
|
4
4
|
Summary: Builds File Trees from TreeScript. If DataLabels are present in TreeScript, a DataDirectory argument is required.
|
5
5
|
Home-page: https://github.com/DK96-OS/treescript-builder
|
6
6
|
Author: DK96-OS
|
@@ -5,7 +5,7 @@ from setuptools import find_packages, setup
|
|
5
5
|
|
6
6
|
setup(
|
7
7
|
name="treescript-builder",
|
8
|
-
version="0.1.
|
8
|
+
version="0.1.8",
|
9
9
|
description='Builds File Trees from TreeScript. If DataLabels are present in TreeScript, a DataDirectory argument is required.',
|
10
10
|
long_description=open('README.md').read(),
|
11
11
|
long_description_content_type='text/markdown',
|
@@ -11,7 +11,6 @@ class PathStack:
|
|
11
11
|
- push(str)
|
12
12
|
- pop: str?
|
13
13
|
- join_stack: Path
|
14
|
-
- create_path(str): Path
|
15
14
|
- reduce_depth(int): bool
|
16
15
|
- get_depth: int
|
17
16
|
"""
|
@@ -47,19 +46,6 @@ class PathStack:
|
|
47
46
|
return Path("./")
|
48
47
|
return Path(f"./{'/'.join(self._stack)}/")
|
49
48
|
|
50
|
-
def create_path(self, filename: str) -> Path:
|
51
|
-
""" Combines all Elements in the Stack and appends a File name.
|
52
|
-
|
53
|
-
**Parameters:**
|
54
|
-
- filename (str): The name of the file to append to the end of the path.
|
55
|
-
|
56
|
-
**Returns:**
|
57
|
-
Path - The Path to the file.
|
58
|
-
"""
|
59
|
-
if type(filename) is not str or len(filename) < 1:
|
60
|
-
return self.join_stack()
|
61
|
-
return self.join_stack() / filename
|
62
|
-
|
63
49
|
def reduce_depth(self, depth: int) -> bool:
|
64
50
|
""" Reduce the Depth of the Path Stack.
|
65
51
|
|
@@ -84,4 +70,4 @@ class PathStack:
|
|
84
70
|
**Returns:**
|
85
71
|
int - The number of elements in the Path Stack.
|
86
72
|
"""
|
87
|
-
return len(self._stack)
|
73
|
+
return len(self._stack)
|
@@ -102,18 +102,19 @@ class TreeState:
|
|
102
102
|
|
103
103
|
def process_stack(self, depth: int) -> Generator[Path, None, None]:
|
104
104
|
""" Pop the Stack to the Desired Depth.
|
105
|
+
- Combines all Elements in the Stack into a Directory Path.
|
105
106
|
|
106
|
-
Parameters
|
107
|
+
**Parameters:**
|
107
108
|
- depth (int): The depth to process the stack to.
|
108
109
|
|
109
|
-
|
110
|
-
|
110
|
+
**Yields:**
|
111
|
+
Path - A Path for every Directory in the Stack, from top to bottom.
|
111
112
|
"""
|
112
113
|
if depth < 0:
|
113
|
-
|
114
|
+
raise ValueError('Negative Depth.')
|
114
115
|
while depth < self._stack.get_depth():
|
115
116
|
if (entry := self._stack.pop()) is not None:
|
116
|
-
yield self._stack.
|
117
|
+
yield self._stack.join_stack() / entry
|
117
118
|
|
118
119
|
def reduce_depth(self, depth: int) -> bool:
|
119
120
|
""" Pop an element from the stack.
|
@@ -135,7 +136,6 @@ class TreeState:
|
|
135
136
|
Raises:
|
136
137
|
SystemExit - When the Line Number does not increase.
|
137
138
|
"""
|
138
|
-
if self._prev_line_number
|
139
|
-
|
140
|
-
|
141
|
-
exit("Invalid Tree Data Sequence")
|
139
|
+
if self._prev_line_number >= line_number:
|
140
|
+
exit("Invalid Tree Data Sequence")
|
141
|
+
self._prev_line_number = line_number
|
{treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder/input/line_reader.py
RENAMED
@@ -1,10 +1,12 @@
|
|
1
|
-
""" Line Reader.
|
1
|
+
""" Line Reader Module for Processing TreeScript.
|
2
2
|
|
3
3
|
The Default Input Reader.
|
4
4
|
- Processes a single line at a time, and determines its key properties.
|
5
5
|
- The Depth is the Integer number of directories between the current line and the root.
|
6
6
|
- The Directory Boolean indicates whether the line represents a Directory.
|
7
7
|
- The Name String is the name of the line.
|
8
|
+
- DataLabel is the first word after the Name, and it has a strict set of validation criteria.
|
9
|
+
- Comments are filtered out by starting a line with the # character. A comment after a file name is also filtered.
|
8
10
|
Author: DK96-OS 2024 - 2025
|
9
11
|
"""
|
10
12
|
from itertools import groupby, takewhile
|
@@ -12,13 +14,22 @@ from sys import exit
|
|
12
14
|
from typing import Generator
|
13
15
|
|
14
16
|
from treescript_builder.data.tree_data import TreeData
|
15
|
-
from treescript_builder.input.string_validation import validate_dir_name, validate_name
|
17
|
+
from treescript_builder.input.string_validation import validate_dir_name, validate_name, validate_data_label
|
16
18
|
|
17
19
|
|
18
20
|
SPACE_CHARS = (' ', ' ')
|
19
21
|
|
20
22
|
|
21
|
-
|
23
|
+
_INVALID_DEPTH_ERROR_MSG = "Invalid Depth (Number of Spaces) in Line: "
|
24
|
+
|
25
|
+
_INVALID_NODE_NAME_ERROR_MSG = "Invalid Name in Line: "
|
26
|
+
_INVALID_DATALABEL_ERROR_MSG = "Invalid DataLabel in Line: "
|
27
|
+
_MISSING_DATADIR_ERROR_MSG = "Missing DataDirectory for DataLabel in Line: "
|
28
|
+
|
29
|
+
|
30
|
+
def read_input_tree(
|
31
|
+
input_tree_data: str,
|
32
|
+
) -> Generator[TreeData, None, None]:
|
22
33
|
""" Generate structured Tree Data from the Input Data String.
|
23
34
|
|
24
35
|
**Parameters:**
|
@@ -51,44 +62,59 @@ def _process_line(
|
|
51
62
|
**Parameters:**
|
52
63
|
- line_number (int): The line-number in the input tree structure, starting from 1.
|
53
64
|
- line (str): A line from the input tree structure.
|
65
|
+
- is_data_label_enabled (bool): Whether DataLabels are enabled. If the DataDirectory argument is not provided, DataLabels are disabled.
|
54
66
|
|
55
67
|
**Returns:**
|
56
|
-
|
68
|
+
TreeData - A Tree Node Data object.
|
57
69
|
|
58
70
|
**Raises:**
|
59
71
|
SystemExit - When Line cannot be read successfully.
|
60
72
|
"""
|
73
|
+
# Depth Depends on Leading Spaces
|
61
74
|
if (depth := _calculate_depth(line)) < 0:
|
62
|
-
exit(
|
63
|
-
#
|
75
|
+
exit(_INVALID_DEPTH_ERROR_MSG + str(line_number))
|
76
|
+
# Now remove Leading Spaces (and trailing)
|
64
77
|
args = line.strip()
|
65
|
-
# Try to split line into multiple arguments
|
78
|
+
# Try to split line into multiple arguments, on one of the SpaceChars.
|
66
79
|
for space_char in SPACE_CHARS:
|
67
80
|
if space_char in args:
|
68
81
|
args = args.split(space_char)
|
69
82
|
break
|
70
83
|
# Check whether line was split or not
|
71
84
|
if isinstance(args, str):
|
72
|
-
name = args
|
73
|
-
data_label =
|
85
|
+
name = args # Was Not Split
|
86
|
+
data_label = ''
|
74
87
|
elif isinstance(args, list) and len(args) >= 2:
|
75
|
-
name = args[0]
|
76
|
-
|
88
|
+
name = args[0] # First Word is the Tree Node Name.
|
89
|
+
# Second Word is the DataLabel.
|
90
|
+
data_label = _validate_data_label_argument(line_number, args[1])
|
91
|
+
# Additional Words are ignored. Comments after the DataLabel are possible, for now.
|
92
|
+
# Alternate LineReader Modules are likely to expand in this area:
|
77
93
|
else:
|
78
94
|
exit(f"Invalid Line: {line_number}")
|
79
|
-
# Validate the Node Name and Type.
|
95
|
+
# Validate the Node Name and Type (is_dir). The tuple is bool first, then node name.
|
80
96
|
if (node_info := _validate_node_name(name)) is None:
|
81
|
-
exit(
|
82
|
-
(is_dir, name) = node_info
|
97
|
+
exit(_INVALID_NODE_NAME_ERROR_MSG + str(line_number))
|
83
98
|
return TreeData(
|
84
|
-
line_number,
|
85
|
-
depth,
|
86
|
-
is_dir,
|
87
|
-
name,
|
88
|
-
data_label
|
99
|
+
line_number=line_number,
|
100
|
+
depth=depth,
|
101
|
+
is_dir=node_info[0],
|
102
|
+
name=node_info[1],
|
103
|
+
data_label=data_label,
|
89
104
|
)
|
90
105
|
|
91
106
|
|
107
|
+
def _validate_data_label_argument(
|
108
|
+
line_number: int,
|
109
|
+
argument: str,
|
110
|
+
) -> str:
|
111
|
+
if argument.startswith('#'): # Comment should be ignored.
|
112
|
+
return ''
|
113
|
+
elif not validate_data_label(argument):
|
114
|
+
exit(_INVALID_DATALABEL_ERROR_MSG + str(line_number))
|
115
|
+
return argument
|
116
|
+
|
117
|
+
|
92
118
|
def _validate_node_name(node_name: str) -> tuple[bool, str] | None:
|
93
119
|
""" Determine whether this Tree Node is a Directory, and validate the name.
|
94
120
|
|
@@ -96,7 +122,7 @@ def _validate_node_name(node_name: str) -> tuple[bool, str] | None:
|
|
96
122
|
- node_name (str): The argument received for the node name.
|
97
123
|
|
98
124
|
**Returns:**
|
99
|
-
tuple[bool, str] - Node information, first whether it is a directory, then the valid name of the node.
|
125
|
+
tuple[bool, str]? - Node information, first whether it is a directory, then the valid name of the node.
|
100
126
|
|
101
127
|
**Raises:**
|
102
128
|
SystemExit - When the directory name is invalid.
|
@@ -104,14 +130,14 @@ def _validate_node_name(node_name: str) -> tuple[bool, str] | None:
|
|
104
130
|
try:
|
105
131
|
# Check if the line contains any slash characters
|
106
132
|
if (dir_name := validate_dir_name(node_name)) is not None:
|
107
|
-
return
|
133
|
+
return True, dir_name
|
108
134
|
# Fall-Through to File Node
|
109
135
|
except ValueError:
|
110
136
|
# An error in the dir name, such that it cannot be a file either
|
111
137
|
return None
|
112
138
|
# Is a File
|
113
139
|
if validate_name(node_name):
|
114
|
-
return
|
140
|
+
return False, node_name
|
115
141
|
return None
|
116
142
|
|
117
143
|
|
@@ -122,7 +148,7 @@ def _calculate_depth(line: str) -> int:
|
|
122
148
|
- line (str): A line from the tree command output.
|
123
149
|
|
124
150
|
**Returns:**
|
125
|
-
int
|
151
|
+
int - The depth of the line in the tree structure, or -1 if space count is invalid.
|
126
152
|
"""
|
127
153
|
space_count = len(list(
|
128
154
|
takewhile(lambda c: c in SPACE_CHARS, line)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: treescript-builder
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.8
|
4
4
|
Summary: Builds File Trees from TreeScript. If DataLabels are present in TreeScript, a DataDirectory argument is required.
|
5
5
|
Home-page: https://github.com/DK96-OS/treescript-builder
|
6
6
|
Author: DK96-OS
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder/data/data_directory.py
RENAMED
File without changes
|
{treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder/data/instruction_data.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder/input/argument_data.py
RENAMED
File without changes
|
{treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder/input/argument_parser.py
RENAMED
File without changes
|
{treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder/input/file_validation.py
RENAMED
File without changes
|
{treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder/input/input_data.py
RENAMED
File without changes
|
{treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder/input/string_validation.py
RENAMED
File without changes
|
File without changes
|
{treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder/tree/build_validation.py
RENAMED
File without changes
|
{treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder/tree/tree_builder.py
RENAMED
File without changes
|
{treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder/tree/tree_trimmer.py
RENAMED
File without changes
|
{treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder/tree/trim_validation.py
RENAMED
File without changes
|
{treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder.egg-info/SOURCES.txt
RENAMED
File without changes
|
File without changes
|
{treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder.egg-info/entry_points.txt
RENAMED
File without changes
|
{treescript_builder-0.1.7 → treescript_builder-0.1.8}/treescript_builder.egg-info/top_level.txt
RENAMED
File without changes
|