Commit 5849a294 authored by Seblu's avatar Seblu

Rework motd behaviour and GUI

parent 6e9823f1
......@@ -327,11 +327,10 @@ def c_install(args):
# select image to install
repoman = load_repositories(args)
image, repo = next(get_images([args.pattern], repoman, min=1, max=1))
if repo:
# Print repo MOTD
arrow("Repository %s MOTD" %
# Print setup information
if repo is not None:
arrow("Repository message")
out(repo.motd, endl="")
# print setup information
arrow(u"Installing %s v%s" % (, image.version))
# let's go
dt =, subparser, run_setup=not args.dry_run)
......@@ -354,25 +353,23 @@ def c_list(args):
def c_motd(args):
Display (and edit) repository's MOTD
Show and set repository's message
repoman = load_repositories(args)
repo = repoman[args.repository]
arrow("Current MOTD for %s:" %
if args.edit:
# check local repository
if not repo.local:
raise ISError(u"Repository must be local")
arrow("New MOTD (end with a blank line):")
motd = ""
# raw_input return bytestring
data = raw_input().decode(sys.stdin.encoding)
motd += data
while data:
data = raw_input().decode(sys.stdin.encoding)
motd += u"\n%s" % data
if args.file:
args.set = open(args.file, "rb").read()
elif args.remove:
args.set = ""
for reponame in repoman.select_repositories(args.repository):
arrow(reponame, -1)
if args.set is not None:
except IndexError as e:
raise ISError(e)
def c_move(args):
......@@ -675,9 +672,11 @@ def arg_parser_init():
# motd command parser
p = subparser.add_parser("motd", help=c_motd.__doc__.lower())
p.add_argument("repository", help="repository to display/edit MOTD")
p.add_argument("--edit", action="store_true",
help="edit repository's MOTD")
g = p.add_mutually_exclusive_group()
g.add_argument("-r", "--remove", action="store_true", help="remove the motd")
g.add_argument("-s", "--set", help="set the motd from command line")
g.add_argument("-f", "--file", help="set the motd from a file")
p.add_argument("repository", nargs="*", default=[u"*"], help="image repository")
# move command parser
p = subparser.add_parser("move", help=c_move.__doc__.lower())
......@@ -267,11 +267,20 @@ list [-h] [-A] [-d] [-D] [-f] [-j] [-i] [-l] [-m] [-s] [-u] [<remote_image>...]
display image url
motd [-h] [--edit] *repository*
Display MOTD of a repository
motd [-h] [-f] [-r] [-s] *repository*
Show or set the message of the day (MOTD) of repository.
This message is only displayed during installation of an image from this repository.
edit the MOTD of the repository
-f, --file *FILE*
set the repository MOTD from file *FILE*.
-s, --set *MESSAGE*
set the repository MOTD from command line argument *MESSAGE*.
-r, --remove
remove the repository MOTD.
MOTD are supported by repository version >= 2.0.
move [-h] [-f] <local_image>... *repository*
......@@ -586,25 +586,24 @@ class Repository(object):
# Remove dummy repository
def motd(self):
Return repository message of the day
motd = self.db.ask("SELECT motd FROM repository").fetchone()[0]
return None if len(motd) == 0 else motd
def motd(self, new_motd=None):
def setmotd(self, value=""):
Display and edit repository motd
Set repository message of the day
if new_motd is None:
motd = self.db.ask("SELECT motd FROM repository").fetchone()
motd = None
if motd is None:
raise ISError("Unable to retrieve %s's MOTD" %
# check local repository
if not self.local:
raise ISError(u"Repository must be local")
self.db.ask("UPDATE repository SET motd = ?", (new_motd,))
# check local repository
if not self.local:
raise ISError(u"Repository must be local")
arrow("Updating motd")
self.db.ask("UPDATE repository SET motd = ?", (value,))
class Repository_v1(Repository):
......@@ -671,14 +670,21 @@ class Repository_v1(Repository):
return images
def motd(self, new_motd=None):
def motd(self):
Display and edit repository motd
Return repository message of the day.
Repository v1 don't have message of day
if new_motd:
warn("[%s] repository v1, unable to edit MOTD." %
return None
def setmotd(self, value=""):
Don't set repository message of the day. Not supported by v1.
# check local repository
warn(u"Repository v1 doesn't support motd. Unable to set")
class RepositoryManager(object):
......@@ -157,7 +157,7 @@ _is() {
[[ "$cur" == -* ]] && _opt '-h --help --edit' && return 0
[[ "$cur" == -* ]] && _opt '-h --help -r --remove -f --files -s --set' && return 0
......@@ -264,8 +264,10 @@ _is() {
"--edit[edit repository's MOTD]"
'(-f --files)'{-f,--files}'[set the motd from a file]: motd:_files'
'(-s --set)'{-s,--set}'[set the motd from command line]'
'(-r --remove)'{-r,--remove}'[remove the motd]'
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