aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/update-aosp-mirror.py
diff options
context:
space:
mode:
authorDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2021-11-29 16:42:30 +0100
committerDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2021-11-29 16:43:00 +0100
commitb244dbd82d9fad9c1c0766d59f6c38e6404e27a1 (patch)
tree143545f991af8437e1cb8abd8d391839f507ac37 /scripts/update-aosp-mirror.py
parent3951e3d417cbb2432570e2d9eafcbf2ee64a8365 (diff)
downloadetc_apache2-b244dbd82d9fad9c1c0766d59f6c38e6404e27a1.tar.gz
etc_apache2-b244dbd82d9fad9c1c0766d59f6c38e6404e27a1.tar.bz2
etc_apache2-b244dbd82d9fad9c1c0766d59f6c38e6404e27a1.zip
Add quick and dirty script to help updating aosp-mirror.conf
The aosp-mirror files grew a lot. And updating it by hand start being problematic for updates with a lot additions. So even if the script and method are far from perfect, I'm adding them as it could help people make big updates to the aosp-mirror.conf file. I used this script and method for the 3951e3d417cbb2432570e2d9eafcbf2ee64a8365 commit (Add Replicant 11 redirects). Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
Diffstat (limited to 'scripts/update-aosp-mirror.py')
-rwxr-xr-xscripts/update-aosp-mirror.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/scripts/update-aosp-mirror.py b/scripts/update-aosp-mirror.py
new file mode 100755
index 0000000..5b839a1
--- /dev/null
+++ b/scripts/update-aosp-mirror.py
@@ -0,0 +1,64 @@
+#!/usr/bin/env python3
+# Copyright (C) 2021 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+import re
+import sys
+
+class Apache2MirrorFile(object):
+ def __init__(self, path):
+ self.path = path
+ self._file = open(path, 'r')
+
+ def test(self):
+ max_aosp_len = 0
+ for line in self._file:
+ valid_line = re.sub('^Redirect ', '',line).split(" ")
+ aosp_path = valid_line[0]
+
+ asop_len = len(aosp_path)
+ if asop_len > max_aosp_len:
+ max_aosp_len = asop_len
+ self._file.close()
+
+ self._file = open(self.path, 'r')
+ for line in self._file:
+ valid_line = re.sub('^Redirect ', '',line).split(" ")
+ aosp_path = valid_line[0]
+ vm_path = valid_line[1]
+
+ nr_tabs = 1 + int((max_aosp_len - len(aosp_path)) / 8)
+ if int((max_aosp_len - len(aosp_path)) % 8) > 0:
+ nr_tabs += 1
+
+ print("Redirect {}{}{}".format(
+ aosp_path,
+ '\t' * nr_tabs,
+ vm_path), end='')
+
+
+def usage(progname):
+ print ('Usage:')
+ print ('\t{} <path/to/mirror.conf>'.format(progname))
+ print ('\tExample: {} ./aosp-mirror.conf'.format(progname))
+ sys.exit(1)
+
+if __name__ == '__main__':
+ if len(sys.argv) != 2:
+ usage(sys.argv[0])
+
+ mirror_config_path = sys.argv[1]
+ m = Apache2MirrorFile(mirror_config_path)
+ m.test()