Skip to content

Commit

Permalink
Create python script for fix_index step
Browse files Browse the repository at this point in the history
  • Loading branch information
christophfroehlich committed May 13, 2024
1 parent 6835d0a commit 75b77a2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
15 changes: 3 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,7 @@ multiversion: Makefile
@echo Step 3: Deleting temporary commits
./make_help_scripts/delete_tmp_commits.py
@echo Step 4: Create correct index + legacy master version
@echo "<html><head><meta http-equiv=\"refresh\" content=\"0; url=rolling/index.html\" /></head></html>" > "$(BUILDDIR)"/html/index.html
# legacy, renamed Rolling version from "master" to "rolling"
@cp -r "$(BUILDDIR)"/html/rolling/ "$(BUILDDIR)"/html/master
@echo "<html><head><meta http-equiv=\"refresh\" content=\"0; url=../rolling/index.html\" /></head></html>" > "$(BUILDDIR)"/html/master/index.html
./make_help_scripts/fix_index.py --builddir $(BUILDDIR)

multiversion-with-errors: Makefile
@echo Building multi version documentation without API
Expand All @@ -95,10 +92,7 @@ multiversion-with-errors: Makefile
@echo Step 3: Deleting temporary commits
./make_help_scripts/delete_tmp_commits.py
@echo Step 4: Create correct index + legacy master version
@echo "<html><head><meta http-equiv=\"refresh\" content=\"0; url=rolling/index.html\" /></head></html>" > "$(BUILDDIR)"/html/index.html
# legacy, renamed Rolling version from "master" to "rolling"
@cp -r "$(BUILDDIR)"/html/rolling/ "$(BUILDDIR)"/html/master
@echo "<html><head><meta http-equiv=\"refresh\" content=\"0; url=../rolling/index.html\" /></head></html>" > "$(BUILDDIR)"/html/master/index.html
./make_help_scripts/fix_index.py --builddir $(BUILDDIR)

multiversion-with-api: Makefile
@echo Building multi version documentation with API
Expand All @@ -113,10 +107,7 @@ multiversion-with-api: Makefile
@echo Step 5: Building multiversion API
./make_help_scripts/create_api_multi_version.py
@echo Step 6: Create correct index + legacy master version
@echo "<html><head><meta http-equiv=\"refresh\" content=\"0; url=rolling/index.html\" /></head></html>" > "$(BUILDDIR)"/html/index.html
# legacy, renamed Rolling version from "master" to "rolling"
@cp -r "$(BUILDDIR)"/html/rolling/ "$(BUILDDIR)"/html/master
@echo "<html><head><meta http-equiv=\"refresh\" content=\"0; url=../rolling/index.html\" /></head></html>" > "$(BUILDDIR)"/html/master/index.html
./make_help_scripts/fix_index.py --builddir $(BUILDDIR)

.PHONY: help Makefile html-with-errors html-with-api multiversion multiversion-with-api multiversion-with-errors html-all-subrepos html-all-subrepos-with-api html-all-subrepos-with-errors linkcheck-all-subrepos-with-api

Expand Down
39 changes: 39 additions & 0 deletions make_help_scripts/fix_index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python3
# Copyright (c) 2023 ros2_control maintainers
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse
import os
import shutil
import deploy_defines

def fix_index(base_branch, builddir):

# Create the index.html file in the html directory
with open(os.path.join(builddir, 'html', 'index.html'), 'w') as f:
f.write(f'<html><head><meta http-equiv="refresh" content="0; url={base_branch}/index.html" /></head></html>')

# Copy the contents of the base_branch directory to the master directory
shutil.copytree(os.path.join(builddir, 'html', base_branch), os.path.join(builddir, 'html', 'master'), dirs_exist_ok=True)

# Patch the index.html file in the master directory
with open(os.path.join(builddir, 'html', 'master', 'index.html'), 'w') as f:
f.write(f'<html><head><meta http-equiv="refresh" content="0; url=../{base_branch}/index.html" /></head></html>')

if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Fix index.')
parser.add_argument('--builddir', required=True, help='Build directory.')

args = parser.parse_args()
fix_index(deploy_defines.base_branch, args.builddir)

0 comments on commit 75b77a2

Please sign in to comment.