From 22c90b6de84ffbef79010f518afa327f600c57b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Dunand?= Date: Fri, 20 Jul 2012 11:10:00 +0200 Subject: [PATCH] Add motd command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This command allow to display/edit the MOTD for a local repository Signed-off-by: Sébastien Luttringer --- bin/is | 32 ++++++++++++++++++++++++++++++++ completion/bash/is | 10 +++++++--- completion/zsh/_installsystems | 6 ++++++ doc/is.1.rst | 7 +++++++ installsystems/repository.py | 29 ++++++++++++++++++++++++++++- 5 files changed, 80 insertions(+), 4 deletions(-) diff --git a/bin/is b/bin/is index 6c1dba0..66a97b0 100755 --- a/bin/is +++ b/bin/is @@ -317,6 +317,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" % repo.config.name) + repo.motd() # Print setup information arrow(u"Installing %s v%s" % (image.name, image.version)) # let's go @@ -337,6 +341,28 @@ def c_list(args): o_size=args.size, o_url=args.url, o_description=args.description) +def c_motd(args): + ''' + Display (and edit) repository's MOTD + ''' + repoman = load_repositories(args) + repo = repoman[args.repository] + arrow("Current MOTD for %s:" % repo.config.name) + repo.motd() + 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 + repo.motd(motd[:-1]) + def c_move(args): ''' Move packaged image from a repository to another one @@ -627,6 +653,12 @@ def arg_parser_init(): p.add_argument("pattern", nargs="*", default=[], help="[repository/][image][:version]") p.set_defaults(func=c_list) + # 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") + p.set_defaults(func=c_motd) # move command parser p = subparser.add_parser("move", help=c_move.__doc__.lower()) p.add_argument("-f", "--force", action="store_true", diff --git a/completion/bash/is b/completion/bash/is index 4d6ad76..977f014 100644 --- a/completion/bash/is +++ b/completion/bash/is @@ -52,9 +52,9 @@ _is() { _get_comp_words_by_ref cur prev cword _get_first_arg cmds=('add' 'build' 'cat' 'changelog' 'check' 'chroot' 'clean' 'copy' 'del' - 'extract' 'get' 'help' 'info' 'init' 'install' 'list' 'move' 'new' 'repo' - 'search' 'version' 'diff' 'payload' 'prepare_chroot' 'unprepare_chroot', - 'upgrade_db') + 'extract' 'get' 'help' 'info' 'init' 'install' 'list' 'motd' 'move' + 'new' 'repo' 'search' 'version' 'diff' 'payload' 'prepare_chroot' + 'unprepare_chroot', 'upgrade_db') opts=('-h' '--help' '-V' '--version' '-v' '--verbosity' @@ -156,6 +156,10 @@ _is() { [[ "$cur" == -* ]] && _opt '-h --help -l --long -j --json -m --md5 -s --size -d --date -A --author -u --url -D --description' && return 0 _remote_image ;; + motd) + [[ "$cur" == -* ]] && _opt '-h --help --edit' && return 0 + _repo + ;; move) [[ "$cur" == -* ]] && _opt '-h --help -f --force' && return 0 _count_args diff --git a/completion/zsh/_installsystems b/completion/zsh/_installsystems index 6792bfc..1edddc5 100644 --- a/completion/zsh/_installsystems +++ b/completion/zsh/_installsystems @@ -258,6 +258,12 @@ _is() { '*:image:_installsystems_remote_images' ) ;; + (motd) + args+=( + '1:repository:_installsystems_repo' + "--edit[edit repository's MOTD]" + ) + ;; (move) args+=( '(-f --force)'{-f,--force}'[move image without confirmation]' diff --git a/doc/is.1.rst b/doc/is.1.rst index eb487ad..b715584 100644 --- a/doc/is.1.rst +++ b/doc/is.1.rst @@ -255,6 +255,13 @@ list [-h] [-A] [-d] [-D] [-j] [-l] [-m] [-s] [-u] [...] display image url +motd [-h] [--edit] *repository* + Display MOTD of a repository + + --edit + edit the MOTD of the repository + + move [-h] [-f] ... *repository* Move one *image* (or more) to another *repository*. diff --git a/installsystems/repository.py b/installsystems/repository.py index dc815a7..a16c96c 100644 --- a/installsystems/repository.py +++ b/installsystems/repository.py @@ -215,7 +215,7 @@ class Repository(object): ''' # check local repository if not self.local: - raise ISError(u"Repository addition must be local") + raise ISError(u"Repository must be local") try: arrow("Updating last file") last_path = os.path.join(self.config.path, self.config.lastname) @@ -584,6 +584,25 @@ class Repository(object): # Remove dummy repository shutil.rmtree(tmpdir) + def motd(self, new_motd=None): + ''' + Display and edit repository motd + ''' + if new_motd is None: + try: + motd = self.db.ask("SELECT motd FROM repository").fetchone() + except: + motd = None + if motd is None: + raise ISError("Unable to retrieve %s's MOTD" % self.config.name) + out(motd[0]) + else: + # check local repository + if not self.local: + raise ISError(u"Repository must be local") + self.db.ask("UPDATE repository SET motd = ?", (new_motd,)) + self.update_last() + class Repository_v1(Repository): @@ -649,6 +668,14 @@ class Repository_v1(Repository): images.append(d) return images + def motd(self, new_motd=None): + ''' + Display and edit repository motd + ''' + out('') + if new_motd: + warn("[%s] repository v1, unable to edit MOTD." % self.config.name) + class RepositoryManager(object): ''' -- GitLab