Skip to content

Commit ecb5724

Browse files
committed
Feat: support recursive indexing for index function
1 parent 8ae1861 commit ecb5724

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

charon/cmd/cmd_index.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@
4242
""",
4343
required=True
4444
)
45+
@option(
46+
"--recursive",
47+
"-r",
48+
help="If do indexing recursively under $path",
49+
is_flag=True,
50+
default=False
51+
)
4552
@option(
4653
"--config",
4754
"-c",
@@ -69,6 +76,7 @@
6976
def index(
7077
path: str,
7178
target: str,
79+
recursive: bool = False,
7280
config: str = None,
7381
debug: bool = False,
7482
quiet: bool = False,
@@ -120,7 +128,15 @@ def index(
120128
if not aws_bucket:
121129
logger.error("No bucket specified for target %s!", target)
122130
else:
123-
re_index(b, path, package_type, aws_profile, dryrun)
131+
args = {
132+
"target": b,
133+
"path": path,
134+
"package_type": package_type,
135+
"aws_profile": aws_profile,
136+
"recursive": recursive,
137+
"dry_run": dryrun
138+
}
139+
re_index(**args) # type: ignore
124140

125141
except Exception:
126142
print(traceback.format_exc())

charon/pkgs/indexing.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def re_index(
266266
path: str,
267267
package_type: str,
268268
aws_profile: str = None,
269-
# cf_enable: bool = False,
269+
recursive: bool = False,
270270
dry_run: bool = False
271271
):
272272
"""Refresh the index.html for the specified folder in the bucket.
@@ -306,17 +306,31 @@ def re_index(
306306
logger.debug("The re-indexed page content: %s", index_content)
307307
if not dry_run:
308308
index_path = os.path.join(path, "index.html")
309+
logger.info("Start re-indexing %s in bucket %s", index_path, bucket_name)
309310
if path == "/":
310311
index_path = "index.html"
311312
s3_client.simple_delete_file(index_path, (bucket_name, real_prefix))
312313
s3_client.simple_upload_file(
313314
index_path, index_content, (bucket_name, real_prefix),
314315
"text/html", digest_content(index_content)
315316
)
316-
# We will not invalidate index.html per cost consideration
317-
# if cf_enable:
318-
# cf_client = CFClient(aws_profile=aws_profile)
319-
# invalidate_cf_paths(cf_client, bucket, [index_path])
317+
logger.info("%s re-indexing finished", index_path)
318+
if recursive:
319+
for c in contents:
320+
if c.endswith("/"):
321+
sub_path = c.removeprefix(real_prefix).strip()
322+
if sub_path.startswith("/"):
323+
sub_path = sub_path.removeprefix("/")
324+
logger.debug("subpath: %s", sub_path)
325+
args = {
326+
"target": target,
327+
"path": sub_path,
328+
"package_type": package_type,
329+
"aws_profile": aws_profile,
330+
"recursive": recursive,
331+
"dry_run": dry_run
332+
}
333+
re_index(**args) # type: ignore
320334
else:
321335
logger.warning(
322336
"The path %s does not contain any contents in bucket %s. "

0 commit comments

Comments
 (0)