2022-01-04 16:15:34 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
|
|
|
# add_submodules_gitea.py
|
|
|
|
#
|
|
|
|
# Copyright (C) 2021-2022 Franco Masotti (franco \D\o\T masotti {-A-T-} tutanota \D\o\T com)
|
|
|
|
#
|
|
|
|
# This file is part of python-packages-source.
|
|
|
|
#
|
|
|
|
# python-packages-source is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# python-packages-source 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 General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with python-packages-source. If not, see <http://www.gnu.org/licenses/>.
|
2022-06-26 17:55:46 +02:00
|
|
|
r"""Add git submodules to the repository."""
|
2022-01-04 16:15:34 +01:00
|
|
|
|
|
|
|
import contextlib
|
2022-06-26 17:55:46 +02:00
|
|
|
import os
|
|
|
|
import shlex
|
|
|
|
|
2022-01-04 16:15:34 +01:00
|
|
|
import fpyutils
|
|
|
|
import gitea
|
|
|
|
|
2022-06-26 17:55:46 +02:00
|
|
|
SUBMODULES_DIRECTORY = '../submodules'
|
|
|
|
|
2022-01-04 16:15:34 +01:00
|
|
|
|
|
|
|
# See
|
|
|
|
# https://stackoverflow.com/a/13847807
|
|
|
|
# CC BY-SA 4.0
|
|
|
|
# spiralman, bryant1410
|
|
|
|
@contextlib.contextmanager
|
2022-06-26 17:55:46 +02:00
|
|
|
def _pushd(new_dir):
|
2022-01-04 16:15:34 +01:00
|
|
|
previous_dir = os.getcwd()
|
|
|
|
os.chdir(new_dir)
|
|
|
|
try:
|
|
|
|
yield
|
|
|
|
finally:
|
|
|
|
os.chdir(previous_dir)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
def main():
|
2022-06-26 17:55:46 +02:00
|
|
|
r"""Main."""
|
2022-01-04 16:15:34 +01:00
|
|
|
results = gitea.get_org_repos()
|
|
|
|
|
|
|
|
# Get the original URLs of mirrors only.
|
2022-06-26 17:55:46 +02:00
|
|
|
with _pushd(SUBMODULES_DIRECTORY):
|
2022-01-04 16:15:34 +01:00
|
|
|
for r in results:
|
|
|
|
for rr in r:
|
|
|
|
if rr['mirror'] and not rr['empty']:
|
|
|
|
fpyutils.shell.execute_command_live_output('git submodule add ' + shlex.quote(rr['clone_url']))
|
|
|
|
|
|
|
|
main()
|