diff --git a/autodist-git b/autodist-git index 38a361b..bf0221b 100755 --- a/autodist-git +++ b/autodist-git @@ -42,6 +42,14 @@ def giteaGetRepository(repo_name): except NotFoundException: return None +def giteaGetRepositories(page, limit): + try: + path = f'/orgs/{cfg["GITEA_ORGANIZATION"]}/repos?page={page}&limit={limit}' + results = gitea.requests_get(path) + return [Repository.parse_response(gitea, result) for result in results] + except NotFoundException: + return None + def findOrCreateRepo(pkg_name, pkg_description=None, create=True): # Replace '+' for repository name as it is not allowed repo_name = pkg_name.replace('+','Plus') @@ -70,7 +78,7 @@ def findOrCreateRepo(pkg_name, pkg_description=None, create=True): gitea_repo = giteaGetRepository(repo_name) return gitea_repo -def archivePkg(pkg_name): +def archiveRepo(pkg_name): # Replace '+' for repository name as it is not allowed repo_name = pkg_name.replace('+','Plus') @@ -79,7 +87,7 @@ def archivePkg(pkg_name): # gitea_repo = org.get_repository(repo_name) gitea_repo = giteaGetRepository(repo_name) - if gitea_repo == None: + if gitea_repo is None: print(f'archiveRepo: repository {repo_name} not found') return @@ -314,7 +322,7 @@ def main(): parser_syncpkg.add_argument('-d', '--delete', action='store_true', help="delete and recreate existing repository", required=False) - parser_archiverepo = subparsers.add_parser('archivepkg', help="archive a specified repository package on git server") + parser_archiverepo = subparsers.add_parser('archiverepo', help="archive a specified repository package on git server") parser_archiverepo.add_argument('pkgname', help="name of package") parser_syncrepo = subparsers.add_parser('syncrepo', help="sync base repository with git server") @@ -340,11 +348,16 @@ def main(): gitea_repo.delete() findAndCommitPackageReleases(options, options.pkgname, options.pkgver) - elif options.mode == 'archivepkg': - archivePkg(options.pkgname) + elif options.mode == 'archiverepo': + print(f'Archiving repository for {options.pkgname}...') + archiveRepo(options.pkgname) elif options.mode == 'syncrepo': + # Get list for packages from SRPMS dir dir_list = sorted(filter(os.path.isfile, glob.glob(f'{cfg["SRPMS_DIR"]}/*.src.rpm'))) + + # Check for package updates to sync with git repositories + print("Checking for package updates to sync with git repositories...") for dir_file in dir_list: parts = re.split('.*/([^/]*)-([^-]*)-([^-]*).src.rpm$', dir_file) pkg_name = parts[1] @@ -385,6 +398,24 @@ def main(): if found_newer: if options.verbose: print(f'{pkg_name} ({pkg_vr}): found_equal={found_equal} found_newer={found_newer} found_older={found_older}') + + # Check for git repositories to archive + print("Checking for git repositories to archive...") + pkg_names = [] + for dir_file in dir_list: + parts = re.split('.*/([^/]*)-([^-]*)-([^-]*).src.rpm$', dir_file) + pkg_names.append(parts[1]) + page = 1 + while True: + gitea_repos = giteaGetRepositories(page, 50) + for gitea_repo in gitea_repos: + if not getattr(gitea_repo, "archived") and not gitea_repo.name.replace('Plus','+') in pkg_names: + print(f'Archiving repository {gitea_repo.name}') + archiveRepo(gitea_repo.name) + if len(gitea_repos) < 50: + break + page += 1 + else: parser.print_help()