setup.cfg cleanup tool
This commit is contained in:
parent
8b41b7aa73
commit
420e377b3a
@ -5,6 +5,7 @@ import json
|
||||
import pathlib
|
||||
import os
|
||||
import argparse
|
||||
import re
|
||||
|
||||
from github import Auth
|
||||
from github import Github
|
||||
@ -12,7 +13,6 @@ from github import Github
|
||||
|
||||
def get_git_token(args):
|
||||
auth = ''
|
||||
print(args.git_token)
|
||||
if args.git_token:
|
||||
auth = args.git_token
|
||||
elif os.environ('GIT_TOKEN'):
|
||||
@ -24,9 +24,10 @@ def get_git_token(args):
|
||||
|
||||
def fix_repos(args):
|
||||
# get Auth information
|
||||
auth = get_git_token(args)
|
||||
token = get_git_token(args)
|
||||
auth = Auth.Token(token)
|
||||
workdir = pathlib.Path(args.work_dir)
|
||||
branch = "main"
|
||||
branch = args.branch
|
||||
|
||||
if args.target_environment == 'public':
|
||||
g = Github(auth=auth)
|
||||
@ -38,15 +39,47 @@ def fix_repos(args):
|
||||
repos.append(repo.full_name)
|
||||
|
||||
for r in repos:
|
||||
r = 'opentelekomcloud-docs/gaussdb-nosql'
|
||||
repo = g.get_repo(r)
|
||||
print(repo.clone_url)
|
||||
git.Repo.clone_from(repo.clone_url, to_path=workdir + repo.name, branch=branch)
|
||||
break
|
||||
path = workdir.joinpath(repo.name)
|
||||
if path.exists() and path.is_dir():
|
||||
local_repo = git.Repo(path)
|
||||
origin = local_repo.remotes.origin
|
||||
origin.pull(branch)
|
||||
else:
|
||||
git.Repo.clone_from(repo.clone_url, to_path=path, branch=branch)
|
||||
file_absolute_path = path / args.file_name
|
||||
if file_absolute_path.exists():
|
||||
with file_absolute_path.open('r') as file:
|
||||
file_content = file.read()
|
||||
pattern = r"(.*)-(.*)\s*="
|
||||
new_file_content = re.sub(pattern, r'\1_\2=', file_content)
|
||||
break
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Update conf.py file in repositories."
|
||||
description="Fix setup.cfg"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--branch",
|
||||
default="main",
|
||||
help="Branch name to be pulled from"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--commit-description",
|
||||
default=(
|
||||
"Update tox.ini && conf.py file\n\n"
|
||||
"Performed-by: gitea/infra/hc-tools/"
|
||||
"/test.py"
|
||||
),
|
||||
help="Commit description for the commit",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--file-name",
|
||||
default="setup.cfg",
|
||||
help="Relative path to file without starting /.\n"
|
||||
"default: setup.cfg"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--git-token",
|
||||
@ -67,15 +100,7 @@ def main():
|
||||
required=True,
|
||||
help="Working directory to use for repository checkout.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--commit-description",
|
||||
default=(
|
||||
"Update tox.ini && conf.py file\n\n"
|
||||
"Performed-by: gitea/infra/hc-tools/"
|
||||
"/test.py"
|
||||
),
|
||||
help="Commit description for the commit",
|
||||
)
|
||||
|
||||
|
||||
args = parser.parse_args()
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
Loading…
x
Reference in New Issue
Block a user