From patchwork Thu May 30 07:11:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Neidhardt X-Patchwork-Id: 14157 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id E756C1704F; Thu, 30 May 2019 08:46:12 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id 4307B1700C for ; Thu, 30 May 2019 08:46:11 +0100 (BST) Received: from localhost ([127.0.0.1]:48708 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWFlK-0000fg-Dz for patchwork@mira.cbaines.net; Thu, 30 May 2019 03:46:10 -0400 Received: from eggs.gnu.org ([209.51.188.92]:54479) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWFlE-0000fX-Fg for guix-patches@gnu.org; Thu, 30 May 2019 03:46:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hWFlC-00023q-K7 for guix-patches@gnu.org; Thu, 30 May 2019 03:46:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:47141) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hWFlC-00023k-Gz for guix-patches@gnu.org; Thu, 30 May 2019 03:46:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hWFlC-0005sS-CY for guix-patches@gnu.org; Thu, 30 May 2019 03:46:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#36000] [PATCH 1/4] guix: Add helper for generating desktop entry files. Resent-From: Pierre Neidhardt Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 30 May 2019 07:46:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 36000 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 36000@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.155920231822519 (code B ref -1); Thu, 30 May 2019 07:46:02 +0000 Received: (at submit) by debbugs.gnu.org; 30 May 2019 07:45:18 +0000 Received: from localhost ([127.0.0.1]:60685 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hWFkT-0005r8-OZ for submit@debbugs.gnu.org; Thu, 30 May 2019 03:45:18 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40028) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hWFkR-0005qo-Sl for submit@debbugs.gnu.org; Thu, 30 May 2019 03:45:16 -0400 Received: from lists.gnu.org ([209.51.188.17]:54330) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hWFkM-0001kh-Kl for submit@debbugs.gnu.org; Thu, 30 May 2019 03:45:10 -0400 Received: from eggs.gnu.org ([209.51.188.92]:54400) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWFkL-0000Xq-9U for guix-patches@gnu.org; Thu, 30 May 2019 03:45:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hWFkJ-0001gL-Sp for guix-patches@gnu.org; Thu, 30 May 2019 03:45:09 -0400 Received: from mslow2.mail.gandi.net ([217.70.178.242]:58044) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hWFkJ-0001fC-I1 for guix-patches@gnu.org; Thu, 30 May 2019 03:45:07 -0400 Received: from relay8-d.mail.gandi.net (unknown [217.70.183.201]) by mslow2.mail.gandi.net (Postfix) with ESMTP id 60AC03AACCB for ; Thu, 30 May 2019 07:12:06 +0000 (UTC) X-Originating-IP: 92.169.116.19 Received: from localhost.localdomain (lfbn-1-4117-19.w92-169.abo.wanadoo.fr [92.169.116.19]) (Authenticated sender: mail@ambrevar.xyz) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 202941BF205 for ; Thu, 30 May 2019 07:11:39 +0000 (UTC) From: Pierre Neidhardt Date: Thu, 30 May 2019 09:11:38 +0200 Message-Id: <20190530071138.31690-1-mail@ambrevar.xyz> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * guix/build/utils.scm (make-desktop-entry-file): New procedure. --- guix/build/utils.scm | 99 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/guix/build/utils.scm b/guix/build/utils.scm index 5fe3286843..21bdc42719 100644 --- a/guix/build/utils.scm +++ b/guix/build/utils.scm @@ -1100,6 +1100,105 @@ with definitions for VARS." (chmod prog-tmp #o755) (rename-file prog-tmp prog)))) +(define* (make-desktop-entry-file destination #:key + (type "Application") ; One of "Application", "Link" or "Directory". + (version "1.1") + name + (generic-name name) + (no-display #f) + comment + icon + (hidden #f) + only-show-in + not-show-in + (d-bus-activatable #f) + try-exec + exec + path + (terminal #f) + actions + mime-type + (categories "Application") + implements + keywords + (startup-notify #t) + startup-w-m-class + #:rest all-args) + "Create a desktop entry file at DESTINATION. +You must specify NAME. + +Values can be booleans, numbers, strings or list of strings. + +Additionally, locales can be specified with an alist where the key is the +locale. The #f key specifies the default. Example: + + #:name '((#f \"I love Guix\") (\"fr\" \"J'aime Guix\")) + +produces + + Name=I love Guix + Name[fr]=J'aime Guix + +For a complete description of the format, see the specifications at +https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html." + (define (escape-semicolon s) + (string-join (string-split s #\;) "\\;")) + (define* (parse key value #:optional locale) + (set! value (match value + (#t "true") + (#f "false") + ((? number? n) n) + ((? string? s) (escape-semicolon s)) + ((? list? value) + (catch 'wrong-type-arg + (lambda () (string-join (map escape-semicolon value) ";")) + (lambda args (error "List arguments can only contain strings: ~a" args)))) + (_ (error "Value must be a boolean, number, string or list of strings")))) + (format #t "~a=~a~%" + (if locale + (format #f "~a[~a]" key locale) + key) + value)) + + (define key-error-message "This procedure only takes key arguments beside DESTINATION") + + (unless name + (error "Missing NAME key argument")) + (unless (member #:type all-args) + (set! all-args (append (list #:type type) all-args))) + (mkdir-p (dirname destination)) + + (with-output-to-file destination + (lambda () + (format #t "[Desktop Entry]~%") + (let loop ((args all-args)) + (match args + (() #t) + ((_) (error key-error-message)) + ((key value . ...) + (unless (keyword? key) + (error key-error-message)) + (set! key + (string-join (map string-titlecase + (string-split (symbol->string + (keyword->symbol key)) + #\-)) + "")) + (match value + (((_ . _) . _) + (for-each (lambda (locale-subvalue) + (parse key + (if (and (list? (cdr locale-subvalue)) + (= 1 (length (cdr locale-subvalue)))) + ;; Support both proper and improper lists for convenience. + (cadr locale-subvalue) + (cdr locale-subvalue)) + (car locale-subvalue))) + value)) + (_ + (parse key value))) + (loop (cddr args)))))))) + ;;; ;;; Locales.