feat(distgit): added script that run request branch on specific package list #12922
1 changed files with 121 additions and 0 deletions
121
scripts/distgit/request_branch_for_listed_packages.py
Normal file
121
scripts/distgit/request_branch_for_listed_packages.py
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
import subprocess
|
||||
|
||||
import requests
|
||||
|
||||
def read_packages(filename):
|
||||
"""Read packages from file and return as list"""
|
||||
try:
|
||||
with open(filename, 'r') as file:
|
||||
packages = [line.strip() for line in file if line.strip()]
|
||||
return packages
|
||||
except FileNotFoundError:
|
||||
print(f"Error: {filename} not found!")
|
||||
return []
|
||||
except Exception as e:
|
||||
print(f"Error reading {filename}: {e}")
|
||||
return []
|
||||
|
||||
|
||||
def write_packages(filename, data_list):
|
||||
"""
|
||||
Write a list to a file, with each element on a new line.
|
||||
|
||||
Args:
|
||||
filename (str): The name of the file to write to
|
||||
data_list (list): The list of items to write to the file
|
||||
"""
|
||||
try:
|
||||
with open(filename, 'w') as file:
|
||||
for item in data_list:
|
||||
file.write(f"{item}\n")
|
||||
print(f"Successfully wrote {len(data_list)} items to {filename}")
|
||||
except Exception as e:
|
||||
print(f"Error writing to file: {e}")
|
||||
|
||||
def does_package_has_branch(package, branch):
|
||||
"""
|
||||
Check if a package has a branch.
|
||||
"""
|
||||
endpoint = f"https://src.fedoraproject.org/api/0/rpms/{package}/git/branches"
|
||||
response = requests.get(endpoint)
|
||||
if response.status_code != 200:
|
||||
raise Exception(f"Error getting branch {package}: {response.status_code}")
|
||||
try:
|
||||
branches = response.json()["branches"]
|
||||
except Exception as e:
|
||||
raise Exception(f"Error getting branches of {package}: {e}")
|
||||
|
||||
if branch in branches:
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_owner_of_package(package):
|
||||
"""
|
||||
Gets maintainer of a package.
|
||||
"""
|
||||
endpoint = f"https://src.fedoraproject.org/api/0/rpms/{package}"
|
||||
response = requests.get(endpoint)
|
||||
if response.status_code != 200:
|
||||
raise Exception(f"Error getting pacakge {package}: {response.status_code}")
|
||||
try:
|
||||
owner = response.json()["access_users"]["owner"][0]
|
||||
except Exception as e:
|
||||
raise Exception(f"Error getting owner of {package}: {e}")
|
||||
return owner
|
||||
|
||||
def does_package_retired(package):
|
||||
"""
|
||||
Check if a package is retired.
|
||||
"""
|
||||
endpoint = f"https://src.fedoraproject.org/api/0/rpms/{package}/tree"
|
||||
response = requests.get(endpoint)
|
||||
|
||||
if response.status_code != 200:
|
||||
raise Exception(f"Error getting package {package}: {response.status_code}")
|
||||
try:
|
||||
content = response.json()["content"]
|
||||
content_count = len(content)
|
||||
if content_count == 1:
|
||||
file = content[0]["name"]
|
||||
if file == "dead.package":
|
||||
return True
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"Error getting package {package} data: {e}")
|
||||
|
||||
def request_branch(packages, branch):
|
||||
"""
|
||||
Running cmd command that requests branch for listed packages.
|
||||
"""
|
||||
for package in packages:
|
||||
cmd = ["fedpkg", "request-branch", "--repo", package, branch]
|
||||
print(f"Executing {cmd}")
|
||||
subprocess.run(cmd)
|
||||
|
||||
|
||||
def main():
|
||||
branch = "f42" # Your branch name
|
||||
filename_source = "package_list.txt" # Create a file with your packages list
|
||||
filename_result = f"result_package_list_{branch}.txt"
|
||||
package_list = read_packages(filename_source)
|
||||
result_package_list = []
|
||||
package_list_for_processing = []
|
||||
|
||||
for package in package_list:
|
||||
if not does_package_has_branch(package, branch):
|
||||
owner = get_owner_of_package(package)
|
||||
is_retired = does_package_retired(package)
|
||||
package_status = "retired" if is_retired else "unretired"
|
||||
package_with_owner_and_status = f"{package} - {owner} - {package_status}"
|
||||
result_package_list.append(package_with_owner_and_status)
|
||||
|
||||
if not is_retired:
|
||||
package_list_for_processing.append(package)
|
||||
|
||||
request_branch(package_list_for_processing, branch)
|
||||
|
||||
write_packages(filename_result, result_package_list)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue