Skip to content

Commit 39534a3

Browse files
committed
added support for .py4web_ignore, thanks tclerckx
1 parent 707fbf2 commit 39534a3

File tree

6 files changed

+71
-26
lines changed

6 files changed

+71
-26
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ uv:
2424
which uv || curl -LsSf https://astral.sh/uv/install.sh | sh
2525

2626
lock: uv
27-
uv lock
27+
uv lock --refresh
2828

2929
docs: uv
3030
docs/updateDocs.sh html

apps/_dashboard/__init__.py

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
import traceback
1313
import uuid
1414
import zipfile
15+
import pathlib
1516

17+
import pathspec
1618
import requests
19+
1720
from pydal.restapi import Policy, RestAPI
1821
from pydal.validators import CRYPT
1922

@@ -43,6 +46,7 @@
4346
APP_FOLDER = os.path.dirname(__file__)
4447
T_FOLDER = os.path.join(APP_FOLDER, "translations")
4548
T = Translator(T_FOLDER)
49+
PY4WEB_IGNORE = ".py4web_ignore"
4650

4751
session = Session()
4852

@@ -322,31 +326,46 @@ def new_file(name, file_name):
322326
def walk(path):
323327
"""Returns a nested folder structure as a tree"""
324328
top = os.path.join(FOLDER, path)
329+
filter = None
330+
filter_file = os.path.join(top, PY4WEB_IGNORE)
331+
if os.path.exists(filter_file):
332+
with open(filter_file, "r") as stream:
333+
patterns = stream.readlines()
334+
try:
335+
filter = pathspec.PathSpec.from_lines("gitwildmatch", patterns)
336+
except Exception:
337+
print(traceback.format_exc())
338+
339+
def visible(root, name, filter=filter):
340+
if filter:
341+
return not filter.match_file(os.path.join(root, name))
342+
return not (
343+
name.startswith(".")
344+
or name.startswith("#")
345+
or name.endswith("~")
346+
or name[-4:] in (".pyc", "pyo")
347+
or name == "__pycache__"
348+
or root == "uploads"
349+
)
350+
325351
if not os.path.exists(top) or not os.path.isdir(top):
326352
return {"status": "error", "message": "folder does not exist"}
327353
store = {}
328354
for root, dirs, files in os.walk(top, topdown=False, followlinks=True):
329-
store[root] = {
330-
"dirs": list(
331-
sorted(
332-
[
333-
{"name": dir, "content": store[os.path.join(root, dir)]}
334-
for dir in dirs
335-
if dir[0] != "." and dir[:2] != "__"
336-
],
337-
key=lambda item: item["name"],
338-
)
339-
),
340-
"files": list(
341-
sorted(
342-
[
343-
f
344-
for f in files
345-
if f[0] != "." and f[-1] != "~" and f[-4:] != ".pyc"
346-
]
347-
)
348-
),
349-
}
355+
if visible(*os.path.split(root)):
356+
store[root] = {
357+
"dirs": list(
358+
sorted(
359+
[
360+
{"name": d, "content": store[os.path.join(root, d)]}
361+
for d in dirs
362+
if visible(root, d)
363+
],
364+
key=lambda item: item["name"],
365+
)
366+
),
367+
"files": list(sorted([f for f in files if visible(root, f)])),
368+
}
350369
return {"payload": store[top], "status": "success"}
351370

352371
@action("load/<path:path>")

apps/_scaffold/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*~
2+
.*
3+
#*
4+
*.pyc
5+
*.pyo
6+
__pycache__
7+
uploads/**

apps/_scaffold/.web2py_gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*~
2+
.*
3+
#*
4+
*.pyc
5+
*.pyo
6+
__pycache__
7+
uploads/**

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ dependencies = [
1616
"click",
1717
"colorama",
1818
"cryptography",
19+
"pathspec",
1920
"portalocker",
2021
"tornado",
2122
"renoir >= 1.4.0",

uv.lock

Lines changed: 15 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)