htmligator 0.1.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.
- htmligator-0.1.0/LICENSE +21 -0
- htmligator-0.1.0/PKG-INFO +86 -0
- htmligator-0.1.0/README.md +65 -0
- htmligator-0.1.0/pyproject.toml +45 -0
- htmligator-0.1.0/src/htmligator/__init__.py +0 -0
- htmligator-0.1.0/src/htmligator/cli.py +5 -0
- htmligator-0.1.0/src/htmligator/htmligator.py +74 -0
- htmligator-0.1.0/src/htmligator/util.py +39 -0
htmligator-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Siak Hooi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: htmligator
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: generate wrapper html files to navigate folder contents
|
|
5
|
+
License: MIT
|
|
6
|
+
Keywords: downloader
|
|
7
|
+
Author: Siak Hooi
|
|
8
|
+
Author-email: siakhooi@gmail.com
|
|
9
|
+
Requires-Python: >=3.12
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Topic :: Utilities
|
|
14
|
+
Requires-Dist: natsort (>=8.4.0,<9.0.0)
|
|
15
|
+
Project-URL: Bug Tracker, https://github.com/siakhooi/python-htmligator/issues
|
|
16
|
+
Project-URL: Documentation, https://github.com/siakhooi/python-htmligator/wiki
|
|
17
|
+
Project-URL: Homepage, https://github.com/siakhooi/python-htmligator
|
|
18
|
+
Project-URL: Repository, https://github.com/siakhooi/python-htmligator
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# python-htmligator
|
|
22
|
+
generate wrapper html files to navigate folder contents
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
```
|
|
26
|
+
pip install htmligator
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
```
|
|
31
|
+
$ htmligator folder
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
## Links
|
|
36
|
+
- https://pypi.org/project/htmligator/
|
|
37
|
+
- https://github.com/siakhooi/python-htmligator
|
|
38
|
+
- https://sonarcloud.io/project/overview?id=siakhooi_python-htmligator
|
|
39
|
+
|
|
40
|
+
## Badges
|
|
41
|
+

|
|
42
|
+

|
|
43
|
+

|
|
44
|
+

|
|
45
|
+

|
|
46
|
+

|
|
47
|
+

|
|
48
|
+

|
|
49
|
+

|
|
50
|
+

|
|
51
|
+

|
|
52
|
+

|
|
53
|
+
|
|
54
|
+

|
|
55
|
+

|
|
56
|
+

|
|
57
|
+
|
|
58
|
+

|
|
59
|
+

|
|
60
|
+

|
|
61
|
+

|
|
62
|
+
|
|
63
|
+

|
|
64
|
+
[](https://sonarcloud.io/summary/new_code?id=siakhooi_python-htmligator)
|
|
65
|
+
[](https://sonarcloud.io/summary/new_code?id=siakhooi_python-htmligator)
|
|
66
|
+
[](https://sonarcloud.io/summary/new_code?id=siakhooi_python-htmligator)
|
|
67
|
+
[](https://sonarcloud.io/summary/new_code?id=siakhooi_python-htmligator)
|
|
68
|
+
[](https://sonarcloud.io/summary/new_code?id=siakhooi_python-htmligator)
|
|
69
|
+
[](https://sonarcloud.io/summary/new_code?id=siakhooi_python-htmligator)
|
|
70
|
+
[](https://sonarcloud.io/summary/new_code?id=siakhooi_python-htmligator)
|
|
71
|
+
[](https://sonarcloud.io/summary/new_code?id=siakhooi_python-htmligator)
|
|
72
|
+
[](https://sonarcloud.io/summary/new_code?id=siakhooi_python-htmligator)
|
|
73
|
+
[](https://sonarcloud.io/summary/new_code?id=siakhooi_python-htmligator)
|
|
74
|
+
[](https://sonarcloud.io/summary/new_code?id=siakhooi_python-htmligator)
|
|
75
|
+

|
|
76
|
+

|
|
77
|
+

|
|
78
|
+

|
|
79
|
+

|
|
80
|
+

|
|
81
|
+

|
|
82
|
+
|
|
83
|
+
[](https://www.buymeacoffee.com/siakhooi)
|
|
84
|
+
[](https://ko-fi.com/siakhooi)
|
|
85
|
+
|
|
86
|
+
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# python-htmligator
|
|
2
|
+
generate wrapper html files to navigate folder contents
|
|
3
|
+
|
|
4
|
+
## Installation
|
|
5
|
+
```
|
|
6
|
+
pip install htmligator
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
```
|
|
11
|
+
$ htmligator folder
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## Links
|
|
16
|
+
- https://pypi.org/project/htmligator/
|
|
17
|
+
- https://github.com/siakhooi/python-htmligator
|
|
18
|
+
- https://sonarcloud.io/project/overview?id=siakhooi_python-htmligator
|
|
19
|
+
|
|
20
|
+
## Badges
|
|
21
|
+

|
|
22
|
+

|
|
23
|
+

|
|
24
|
+

|
|
25
|
+

|
|
26
|
+

|
|
27
|
+

|
|
28
|
+

|
|
29
|
+

|
|
30
|
+

|
|
31
|
+

|
|
32
|
+

|
|
33
|
+
|
|
34
|
+

|
|
35
|
+

|
|
36
|
+

|
|
37
|
+
|
|
38
|
+

|
|
39
|
+

|
|
40
|
+

|
|
41
|
+

|
|
42
|
+
|
|
43
|
+

|
|
44
|
+
[](https://sonarcloud.io/summary/new_code?id=siakhooi_python-htmligator)
|
|
45
|
+
[](https://sonarcloud.io/summary/new_code?id=siakhooi_python-htmligator)
|
|
46
|
+
[](https://sonarcloud.io/summary/new_code?id=siakhooi_python-htmligator)
|
|
47
|
+
[](https://sonarcloud.io/summary/new_code?id=siakhooi_python-htmligator)
|
|
48
|
+
[](https://sonarcloud.io/summary/new_code?id=siakhooi_python-htmligator)
|
|
49
|
+
[](https://sonarcloud.io/summary/new_code?id=siakhooi_python-htmligator)
|
|
50
|
+
[](https://sonarcloud.io/summary/new_code?id=siakhooi_python-htmligator)
|
|
51
|
+
[](https://sonarcloud.io/summary/new_code?id=siakhooi_python-htmligator)
|
|
52
|
+
[](https://sonarcloud.io/summary/new_code?id=siakhooi_python-htmligator)
|
|
53
|
+
[](https://sonarcloud.io/summary/new_code?id=siakhooi_python-htmligator)
|
|
54
|
+
[](https://sonarcloud.io/summary/new_code?id=siakhooi_python-htmligator)
|
|
55
|
+

|
|
56
|
+

|
|
57
|
+

|
|
58
|
+

|
|
59
|
+

|
|
60
|
+

|
|
61
|
+

|
|
62
|
+
|
|
63
|
+
[](https://www.buymeacoffee.com/siakhooi)
|
|
64
|
+
[](https://ko-fi.com/siakhooi)
|
|
65
|
+
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "htmligator"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "generate wrapper html files to navigate folder contents"
|
|
5
|
+
authors = [
|
|
6
|
+
{name = "Siak Hooi",email = "siakhooi@gmail.com"}
|
|
7
|
+
]
|
|
8
|
+
keywords = [ "downloader" ]
|
|
9
|
+
classifiers = [
|
|
10
|
+
"Development Status :: 4 - Beta",
|
|
11
|
+
"Environment :: Console",
|
|
12
|
+
"License :: OSI Approved :: MIT License",
|
|
13
|
+
"Topic :: Utilities"
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
license = {text = "MIT"}
|
|
17
|
+
readme = "README.md"
|
|
18
|
+
requires-python = ">=3.12"
|
|
19
|
+
dependencies = [
|
|
20
|
+
"natsort (>=8.4.0,<9.0.0)"
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[project.urls]
|
|
24
|
+
homepage = "https://github.com/siakhooi/python-htmligator"
|
|
25
|
+
repository = "https://github.com/siakhooi/python-htmligator"
|
|
26
|
+
documentation = "https://github.com/siakhooi/python-htmligator/wiki"
|
|
27
|
+
"Bug Tracker" = "https://github.com/siakhooi/python-htmligator/issues"
|
|
28
|
+
|
|
29
|
+
[project.scripts]
|
|
30
|
+
htmligator = 'htmligator.cli:run'
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
[tool.poetry]
|
|
34
|
+
packages = [{include = "htmligator", from = "src"}]
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
[tool.poetry.group.dev.dependencies]
|
|
38
|
+
pytest = "^8.3.5"
|
|
39
|
+
pytest-cov = "^6.1.1"
|
|
40
|
+
flake8 = "^7.2.0"
|
|
41
|
+
pytest-responses = "^0.5.1"
|
|
42
|
+
|
|
43
|
+
[build-system]
|
|
44
|
+
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
|
45
|
+
build-backend = "poetry.core.masonry.api"
|
|
File without changes
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
import zipfile
|
|
4
|
+
from htmligator.util import get_folder_from_arguments, folder_to_list
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def get_html_for_file(name, folder):
|
|
8
|
+
return f'<li><a href="{folder}/{name}">{name}</a></li>'
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def get_html_for_folder(name, folder):
|
|
12
|
+
return f'<li><a href="{folder}/{name}.html">{name}</a></li>'
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def create_html(file_list, parent_path, folder_name):
|
|
16
|
+
html_file_name = os.path.join(parent_path, f"{folder_name}.html")
|
|
17
|
+
with open(html_file_name, "w") as html_file:
|
|
18
|
+
html_file.write("<html><body>")
|
|
19
|
+
html_file.write(f"<h1>{folder_name}</h1>")
|
|
20
|
+
html_file.write("<ul>")
|
|
21
|
+
|
|
22
|
+
for item in file_list:
|
|
23
|
+
if item["type"] == "file":
|
|
24
|
+
html_file.write(get_html_for_file(item["name"], folder_name))
|
|
25
|
+
else:
|
|
26
|
+
html_file.write(get_html_for_folder(item["name"], folder_name))
|
|
27
|
+
create_html(
|
|
28
|
+
item["children"],
|
|
29
|
+
os.path.join(parent_path, folder_name),
|
|
30
|
+
item["name"],
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
html_file.write("</ul>")
|
|
34
|
+
html_file.write(f"<h1>{folder_name}</h1>")
|
|
35
|
+
html_file.write("</body></html>")
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def zip_folder(parent_path, list_of_files, zip_file):
|
|
39
|
+
|
|
40
|
+
zip_path = os.path.join(parent_path, zip_file)
|
|
41
|
+
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zipf:
|
|
42
|
+
for file in list_of_files:
|
|
43
|
+
file_path = os.path.join(parent_path, file)
|
|
44
|
+
|
|
45
|
+
if os.path.isfile(file_path):
|
|
46
|
+
zipf.write(file_path, os.path.basename(file_path))
|
|
47
|
+
|
|
48
|
+
elif os.path.isdir(file_path):
|
|
49
|
+
for root, _, files in os.walk(file_path):
|
|
50
|
+
for file in files:
|
|
51
|
+
file_path = os.path.join(root, file)
|
|
52
|
+
relative_path = os.path.relpath(file_path, parent_path)
|
|
53
|
+
zipf.write(file_path, relative_path)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def htmligator():
|
|
57
|
+
folder = get_folder_from_arguments()
|
|
58
|
+
if not os.path.exists(folder):
|
|
59
|
+
print(f"Error: {folder} does not exist")
|
|
60
|
+
sys.exit(1)
|
|
61
|
+
if not os.path.isdir(folder):
|
|
62
|
+
print(f"Error: {folder} is not a folder")
|
|
63
|
+
sys.exit(2)
|
|
64
|
+
|
|
65
|
+
folder_path = os.path.abspath(folder)
|
|
66
|
+
|
|
67
|
+
folder_name = os.path.basename(folder_path)
|
|
68
|
+
parent_path = os.path.dirname(folder_path)
|
|
69
|
+
|
|
70
|
+
file_list = folder_to_list(folder_path, folder_name)
|
|
71
|
+
|
|
72
|
+
create_html(file_list, parent_path, folder_name)
|
|
73
|
+
zip_contents = [folder_name, f"{folder_name}.html"]
|
|
74
|
+
zip_folder(parent_path, zip_contents, f"{folder_name}.zip")
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
from natsort import natsorted
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def get_folder_from_arguments():
|
|
7
|
+
if len(sys.argv) == 2:
|
|
8
|
+
return sys.argv[1]
|
|
9
|
+
else:
|
|
10
|
+
print("Usage: htmligators folder_name", file=sys.stderr)
|
|
11
|
+
sys.exit(1)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def get_file_object(name, path):
|
|
15
|
+
return {"name": name, "path": path, "type": "file"}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def get_folder_object(name, path, children):
|
|
19
|
+
return {"name": name, "path": path, "type": "folder", "children": children}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def folder_to_list(root_path, relative_root):
|
|
23
|
+
file_list = []
|
|
24
|
+
|
|
25
|
+
items = os.listdir(root_path)
|
|
26
|
+
for item in items:
|
|
27
|
+
absolute_path = os.path.join(root_path, item)
|
|
28
|
+
relative_path = os.path.join(relative_root, item)
|
|
29
|
+
if os.path.isfile(absolute_path):
|
|
30
|
+
file_list.append(get_file_object(item, relative_path))
|
|
31
|
+
elif os.path.isdir(absolute_path):
|
|
32
|
+
file_list.append(
|
|
33
|
+
get_folder_object(
|
|
34
|
+
item,
|
|
35
|
+
relative_path,
|
|
36
|
+
folder_to_list(absolute_path, relative_path),
|
|
37
|
+
)
|
|
38
|
+
)
|
|
39
|
+
return natsorted(file_list, key=lambda x: x["name"])
|