run 'runon list' to list all available distributions
This commit is contained in:
parent
679b94b11e
commit
96418fbbb5
25
runon
25
runon
@ -16,7 +16,11 @@ import subprocess
|
|||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
|
||||||
|
|
||||||
def load_config(user_confname, osname):
|
def natural_sortkey(string):
|
||||||
|
tokenize = re.compile(r'(\d+)|(\D+)').findall
|
||||||
|
return tuple(int(num) if num else alpha for num, alpha in tokenize(string))
|
||||||
|
|
||||||
|
def read_ini(user_confname, osname=''):
|
||||||
ini_list = [ 'runon.conf', '.runon.conf', os.path.join(xdg.BaseDirectory.xdg_config_home, 'runon', 'runon.conf'), '/etc/runon/runon.conf' ]
|
ini_list = [ 'runon.conf', '.runon.conf', os.path.join(xdg.BaseDirectory.xdg_config_home, 'runon', 'runon.conf'), '/etc/runon/runon.conf' ]
|
||||||
defaults = {
|
defaults = {
|
||||||
'osname': osname,
|
'osname': osname,
|
||||||
@ -26,6 +30,14 @@ def load_config(user_confname, osname):
|
|||||||
ini_list.insert(0, user_confname)
|
ini_list.insert(0, user_confname)
|
||||||
ini = configparser.ConfigParser(defaults=defaults, interpolation=configparser.ExtendedInterpolation())
|
ini = configparser.ConfigParser(defaults=defaults, interpolation=configparser.ExtendedInterpolation())
|
||||||
ini.read(ini_list)
|
ini.read(ini_list)
|
||||||
|
return ini
|
||||||
|
|
||||||
|
def list_osnames(user_confname):
|
||||||
|
ini = read_ini(user_confname)
|
||||||
|
return ini.sections()
|
||||||
|
|
||||||
|
def load_config(user_confname, osname):
|
||||||
|
ini = read_ini(user_confname, osname)
|
||||||
if not ini.has_section(osname):
|
if not ini.has_section(osname):
|
||||||
print('ERROR: cannot find configuration for distribution "{}"'.format(osname))
|
print('ERROR: cannot find configuration for distribution "{}"'.format(osname))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@ -153,7 +165,8 @@ def main():
|
|||||||
else:
|
else:
|
||||||
parser.description = 'run commands on any distribution'
|
parser.description = 'run commands on any distribution'
|
||||||
parser.add_argument('osname',
|
parser.add_argument('osname',
|
||||||
help = 'distribution name to run on')
|
help = 'distribution name to run on, '
|
||||||
|
'"list" to dump all available distributions')
|
||||||
parser.epilog = '(c) 2021 Gilles Grandou <gilles@grandou.net>'
|
parser.epilog = '(c) 2021 Gilles Grandou <gilles@grandou.net>'
|
||||||
|
|
||||||
parser.add_argument('-v', '--verbose', action='store_true',
|
parser.add_argument('-v', '--verbose', action='store_true',
|
||||||
@ -169,6 +182,14 @@ def main():
|
|||||||
if osname:
|
if osname:
|
||||||
args.osname = osname
|
args.osname = osname
|
||||||
|
|
||||||
|
if args.osname == 'list':
|
||||||
|
osnames = list_osnames(args.config)
|
||||||
|
print('Available distributions:')
|
||||||
|
for o in sorted(osnames, key=natural_sortkey):
|
||||||
|
print(' {}'.format(o))
|
||||||
|
print()
|
||||||
|
return 0
|
||||||
|
|
||||||
client = docker.from_env()
|
client = docker.from_env()
|
||||||
conf = load_config(args.config, args.osname)
|
conf = load_config(args.config, args.osname)
|
||||||
image = build_image(client, conf, args.update, args.verbose)
|
image = build_image(client, conf, args.update, args.verbose)
|
||||||
|
Loading…
Reference in New Issue
Block a user