diff options
Diffstat (limited to 'scripts/update-aosp-mirror.py')
-rwxr-xr-x | scripts/update-aosp-mirror.py | 64 |
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() |