Skip to content

Commit

Permalink
Configurable ssh host and path for releases
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher committed Apr 10, 2024
1 parent 846275e commit f9571e8
Showing 1 changed file with 71 additions and 26 deletions.
97 changes: 71 additions & 26 deletions bin/release
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ from datetime import datetime
from termcolor import colored
from urllib.parse import urlparse

# on Tuxfamily
ssh_path = 'galette/galette-repository/plugins/'
ssh_host = 'ssh.tuxfamily.org'
galette_dl_repo = 'http://download.tuxfamily.org/galette/plugins/'
local_dl_repo = os.path.join(
os.path.dirname(
Expand All @@ -22,19 +25,23 @@ sign = True
assume_yes = False
nightly = False
ssh_key = False
tag_commit = None


def print_err(msg):
"""
Display colored error message
"""
print(colored(msg, 'red', attrs=['bold']))


def get_numeric_version(ver):
"""
Returns all numeric version
"""
return re.findall(r'\d+', ver)


def valid_version(ver):
"""
Check if provided version is valid.
Expand All @@ -44,6 +51,7 @@ def valid_version(ver):
"""
return '.'.join(get_numeric_version(ver)) == ver


def incr_version(ver):
"""
Increment version number
Expand All @@ -52,6 +60,7 @@ def incr_version(ver):
version[-1] = str(int(version[-1]) + 1)
return version


def propose_version():
"""
Propose new minor and major versions,
Expand All @@ -63,24 +72,24 @@ def propose_version():
for tagref in tagrefs:
tag = tagref.tag
if valid_version(tag.tag):
#last minor version is always the last one :)
# last minor version is always the last one :)
if tag.tag > last_minor:
last_minor = tag.tag

#last major version
# last major version
if len(tag.tag) == 5 and tag.tag > last_major:
last_major = tag.tag

if verbose:
print('last minor: %s | last major %s' % (last_minor, last_major))

#no version provided. propose one
# no version provided. propose one
new_minor = None
new_major = None

if len(last_minor) == 5:
#if the latest is a major version
new_minor = last_minor + ('.1')
# if the latest is a major version
new_minor = last_minor + '.1'
else:
new_minor = '.'.join(incr_version(last_minor))

Expand All @@ -91,19 +100,24 @@ def propose_version():
major: %s
""" % (new_minor, new_major))


def get_latest_version():
"""
Look for latest version
"""
global tag_commit

last = None
for tagref in tagrefs:
tag = tagref.tag
if valid_version(tag.tag):
#last minor version is always the last one :)
if last == None or tag.tag > last:
last = tag.tag
if tag is not None and valid_version(tag.tag):
# last minor version is always the last one :)
if last is None or tag.tag > last.tag:
last = tag

tag_commit = last.hexsha
return last.tag

return last

def is_existing_version(ver):
"""
Expand Down Expand Up @@ -135,6 +149,7 @@ def ask_user_confirm(msg):
"Invalid input. Please enter 'yes' or 'no' (or 'y' or 'n')."
)


def get_rel_name(buildver):
"""
Build archive name from command line parameters
Expand All @@ -157,6 +172,7 @@ def get_rel_name(buildver):

return archive_name


def _do_build(ver):
"""
Proceed build
Expand All @@ -171,7 +187,7 @@ def _do_build(ver):
)

if not force:
#first check if a version
# first check if a version
local = False
ascLocal = False

Expand All @@ -186,7 +202,7 @@ def _do_build(ver):
exists = response.status == 200

if not exists:
#also check from local repo
# also check from local repo
exists = os.path.exists(galette_archive)
if exists:
local = True
Expand All @@ -197,7 +213,7 @@ def _do_build(ver):
ascexists = response.status == 200

if not ascexists:
#also check from local repo
# also check from local repo
ascexists = os.path.exists(
os.path.join(
local_dl_repo,
Expand All @@ -213,7 +229,7 @@ def _do_build(ver):
loctxt = ''
if local:
loctxt = 'locally '
msg = 'Relase %s already %sexists' % (rel_name, loctxt)
msg = 'Release %s already %sexists' % (rel_name, loctxt)

if ascexists:
loctxt = ''
Expand Down Expand Up @@ -257,7 +273,7 @@ def _do_build(ver):
typever,
galette_archive
))
print('Archive command: %s' % (archive_cmd))
print('Archive command: %s' % archive_cmd)

if commit and extra:
print('Archiving GIT commit %s' % commit)
Expand All @@ -280,31 +296,34 @@ def _do_build(ver):
if upload:
do_scp(galette_archive)


def do_sign(archive):
sign_cmd = 'gpg --detach-sign --armor %s' % archive
p1 = subprocess.Popen(sign_cmd, shell=True)
p1.communicate()


def do_scp(archive):
global ssh_key
global ssh_key, ssh_host, ssh_path

path = 'galette/galette-repository/plugins/'
path = ssh_path
if extra:
path += 'dev/'

if ssh_key:
scp_cmd = 'scp -i %s %s* ssh.tuxfamily.org:%s' % (ssh_key, archive, path)
scp_cmd = 'scp -i %s %s* %s:%s' % (ssh_key, archive, ssh_host, path)
else:
scp_cmd = 'scp -r %s* ssh.tuxfamily.org:%s' % (archive, path)
scp_cmd = 'scp -r %s* %s:%s' % (archive, ssh_host, path)
print(scp_cmd)
p1 = subprocess.Popen(scp_cmd, shell=True)
p1.communicate()


def add_libs(rel_name, galette_archive):
"""
Add external libraries to the archive
"""
galette = tarfile.open(galette_archive, 'r|bz2')
galette = tarfile.open(galette_archive, 'r|bz2', format=tarfile.GNU_FORMAT)
src_dir = os.path.join(local_dl_repo, 'src')
if not os.path.exists(src_dir):
os.makedirs(src_dir)
Expand Down Expand Up @@ -384,7 +403,7 @@ def add_libs(rel_name, galette_archive):
]:
os.remove(os.path.join(root, filename))

galette = tarfile.open(galette_archive, 'w|bz2')
galette = tarfile.open(galette_archive, 'w|bz2', format=tarfile.GNU_FORMAT)

for i in os.listdir(src_dir):
galette.add(
Expand All @@ -397,7 +416,7 @@ def add_libs(rel_name, galette_archive):

def valid_commit(repo, c):
"""
Validate commit existance in repository
Validate commit existence in repository
"""
global commit

Expand All @@ -424,11 +443,12 @@ def valid_commit(repo, c):
except gitdb.exc.BadObject:
return False


def main():
"""
Main method
"""
global verbose, tagrefs, force, extra, assume_yes, nightly, sign, ssh_key
global verbose, tagrefs, force, extra, assume_yes, nightly, sign, ssh_key, repo, ssh_host, ssh_path, galette_dl_repo

parser = argparse.ArgumentParser(description='Release Galette Auto Plugin')
group = parser.add_mutually_exclusive_group()
Expand Down Expand Up @@ -476,10 +496,25 @@ def main():
'--ssh-key',
help='SSH key to be used for uploading',
)
parser.add_argument(
'-H',
'--ssh-host',
help='SSH host to upload to (default %s)' % ssh_host
)
parser.add_argument(
'-P',
'--ssh-path',
help='Path on SSH host (default %s)' % ssh_path
)
parser.add_argument(
'-d',
'--download-url',
help='Download URL (default %s)' % galette_dl_repo
)
parser.add_argument('-f', action='store_true')
args = parser.parse_args()

verbose=args.verbose
verbose = args.verbose

if verbose:
print(args)
Expand All @@ -492,11 +527,20 @@ def main():
force = ask_user_confirm(
'Are you *REALLY* sure you mean -f when you typed -f? [yes/No] '
)
assume_yes=args.assume_yes
assume_yes = args.assume_yes

if args.ssh_key:
ssh_key = args.ssh_key

if args.ssh_host:
ssh_host = args.ssh_host

if args.ssh_path:
ssh_path = args.ssh_path

if args.download_url:
galette_dl_repo = args.download_url

build = False
buildver = None
if args.nightly:
Expand Down Expand Up @@ -527,7 +571,7 @@ def main():
print_err('%s is not a valid version number!' % args.version)
sys.exit(1)
else:
#check if specified version exists
# check if specified version exists
if not is_existing_version(args.version):
print_err('%s does not exist!' % args.version)
else:
Expand All @@ -547,5 +591,6 @@ def main():
if build:
_do_build(buildver)


if __name__ == "__main__":
main()

0 comments on commit f9571e8

Please sign in to comment.