Read about our upcoming Code of Conduct on this issue

Commit 6b359346 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

Python scripts: renamed with additional symlink

This is nicer for editors and linters
parent f9f57ff0695b
#!/usr/bin/env python3
import argparse
import logging
import os
import shutil
import sys
from subprocess import check_call, check_output
GIT_TAGS_BRANCH = 'git-tags'
os.environ['HGPLAIN'] = 'yes'
parser = argparse.ArgumentParser(
description="Copy Git tags in Mercurial global tags."
)
parser.add_argument("-s", "--simulate", action="store_true",
help="Don't commit nor push, rollback changes "
"to the tags file instead.")
parser.add_argument("--logging-level", default='INFO')
parser.add_argument("-R", "--repository", default=".",
help="Mercurial repository to operate on.")
cl_args = parser.parse_args()
repo = cl_args.repository
simulate = cl_args.simulate
logging.basicConfig(level=getattr(logging, cl_args.logging_level.upper()))
logger = logging.getLogger(os.path.basename(sys.argv[0]))
os.chdir(repo)
dirty = check_output(('hg', 'status', '-mard')).strip()
if dirty:
logger.error("Repository %r has local modifications. Aborting.", repo)
sys.exit(1)
logger.info("Updating repository %r to the %r branch", repo, GIT_TAGS_BRANCH)
check_call(('hg', 'update', "-q", GIT_TAGS_BRANCH))
logger.info("Importing Git tags as local modifications")
shutil.copy2(os.path.join('.hg', 'git-tags'),
os.path.join('.hgtags'))
logger.info("Displaying the diff.")
sys.stderr.flush()
diff = check_output(('hg', 'diff'))
if not(diff.strip()):
logger.warning("Empty diff, nothing to do, see you next time.")
sys.exit(0)
remote = check_output(('hg', 'config', 'paths.default')).strip().decode()
sys.stdout.buffer.write(diff)
def revert():
check_call(('hg', 'revert', '.hgtags'))
confirmation = input("Commit and push those changes to '%s'?\n"
"Please enter 'YES' to confirm: " % remote)
if confirmation.strip() != 'YES':
revert()
logger.warning("Not confirmed, changes reverted. Bye")
sys.exit(0)
def check_call_with_simulate(cmd):
if simulate:
logger.info("Simulation mode: would have run %r", cmd)
else:
check_call(cmd)
def info_with_simulate(msg, *a, **kw):
if simulate:
logger.info("Simulation mode: would (be) " + msg, *a, **kw)
else:
logger.info(msg.capitalize(), *a, **kw)
if simulate:
logger.info("Simulation mode: reverting .hgtags")
revert()
logger.info("Simulation mode: current working directory is %s",
os.getcwd())
info_with_simulate("committing the changes")
check_call_with_simulate(
('hg', 'commit', '-m', "Updated Mercurial tags from Git tags", '.hgtags'))
info_with_simulate("pushing")
check_call_with_simulate(('hg', 'push', '-r', '.'))
if simulate:
logger.warning("End of simulation, hope you enjoyed it. Bye")
else:
logger.warning("Changes committed and pushed. Bye")
convert-git-tags-push.py
\ No newline at end of file
#!/usr/bin/env python3
import argparse
import sys
import time
from subprocess import Popen, PIPE, check_call, check_output
STABLE_BRANCH_SUFFIX = '-stable'
def extract_stable_branch_version(brname):
return tuple(int(segment)
for segment in brname[:-len(STABLE_BRANCH_SUFFIX)].split('-'))
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
epilog=""
"Examples: `{self} gitlab-ce heptapod-rails` (the default)\n"
" `{self} --branch-prefix 13-9-stable`".format(self=sys.argv[0])
)
parser.add_argument("--heptapod-repo", default='heptapod-rails')
parser.add_argument("--gitlab-repo", default='gitlab-ce')
parser.add_argument("--branch-prefix")
cl_args = parser.parse_args()
def is_branch_to_pull(branch_name):
if not branch_name.endswith(STABLE_BRANCH_SUFFIX):
return False
prefix = cl_args.branch_prefix
if prefix is not None:
return branch_name.startswith(prefix)
return True
heptapod_repo, gitlab_repo = cl_args.heptapod_repo, cl_args.gitlab_repo
git_branches = check_output(('git', '-C', gitlab_repo, 'branch')
).decode().splitlines()
git_branches = [b.strip() for b in git_branches]
stable_branches = [(extract_stable_branch_version(br), br)
for br in git_branches if is_branch_to_pull(br)]
stable_branches.sort()
print("Sorted stable branches: %r" % [b[1] for b in stable_branches])
for version, branch in stable_branches:
print("Pulling Git branch %r -- checking prior conversion" % branch)
log = Popen(('hg', 'log', '-R', heptapod_repo,
'-r', "bookmark(%s)" % branch),
stderr=PIPE)
log.communicate()
if log.poll() == 0:
print(" already converted, pull should be small")
else:
print(" full branch conversion, sleeping first for 10s for "
"easy interruption")
time.sleep(10)
check_call(('hg', 'pull', '-R', heptapod_repo,
'-r', branch, gitlab_repo))
convert-pull-local.py
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment