Adding verbosity
authorJosé Bollo <jose.bollo@iot.bzh>
Thu, 3 Dec 2015 11:18:13 +0000 (12:18 +0100)
committerJosé Bollo <jose.bollo@iot.bzh>
Thu, 3 Dec 2015 11:18:13 +0000 (12:18 +0100)
Change-Id: Icc0fdc6a230e2bf11fccc4f7739009e7266f6b9d

Makefile.am
wgtpkg-digsig.c
wgtpkg-install.c
wgtpkg-pack.c
wgtpkg-sign.c
wgtpkg-verbose.c [new file with mode: 0644]
wgtpkg.h

index a0fe372..02a724c 100644 (file)
@@ -1,6 +1,14 @@
 bin_PROGRAMS = wgtpkg-install wgtpkg-pack wgtpkg-sign
 
-COMMONSRCS = wgtpkg-base64.c wgtpkg-certs.c wgtpkg-digsig.c wgtpkg-files.c wgtpkg-workdir.c wgtpkg-xmlsec.c wgtpkg-zip.c
+COMMONSRCS = \
+       wgtpkg-base64.c \
+       wgtpkg-certs.c \
+       wgtpkg-digsig.c \
+       wgtpkg-files.c \
+       wgtpkg-verbose.c \
+       wgtpkg-workdir.c \
+       wgtpkg-xmlsec.c \
+       wgtpkg-zip.c
 
 AM_CFLAGS  = -Wall -Wno-pointer-sign
 AM_CFLAGS += -ffunction-sections -fdata-sections
index 26ee824..273c902 100644 (file)
@@ -271,7 +271,7 @@ int verify_digsig(struct filedesc *fdesc)
        int res;
 
        assert ((fdesc->flags & flag_signature) != 0);
-printf("\n\nchecking file %s\n\n",fdesc->name);
+       notice("-- checking file %s",fdesc->name);
 
        /* reset the flags */
        file_clear_flags();
index 7781c62..7a88ebf 100644 (file)
@@ -29,7 +29,7 @@
 /* install the widget of the file */
 static void install(const char *wgtfile)
 {
-printf("\n\nINSTALLING widget %s\n", wgtfile);
+       notice("-- INSTALLING widget %s", wgtfile);
 
        if (enter_workdir(1))
                goto error;
@@ -56,6 +56,8 @@ int main(int ac, char **av)
 
        xmlsec_init();
 
+       ac = verbose_scan_args(ac, av);
+       
        /* canonic names for files */
        for (i = 1 ; av[i] != NULL ; i++)
                if ((av[i] = realpath(av[i], NULL)) == NULL) {
index 9164447..a8aaa05 100644 (file)
@@ -47,6 +47,8 @@ static void usage()
                "\n"
                "   -o wgtfile       the output widget file\n"
                "   -f               force overwriting\n"
+               "   -q               quiet\n"
+               "   -v               verbose\n"
                "\n",
                appname
        );
@@ -56,6 +58,8 @@ static struct option options[] = {
        { "output",      required_argument, NULL, 'o' },
        { "force",       no_argument,       NULL, 'f' },
        { "help",        no_argument,       NULL, 'h' },
+       { "quiet",       no_argument,       NULL, 'q' },
+       { "verbose",     no_argument,       NULL, 'v' },
        { NULL, 0, NULL, 0 }
 };
 
@@ -71,13 +75,20 @@ int main(int ac, char **av)
        force = 0;
        wgtfile = directory = NULL;
        for (;;) {
-               i = getopt_long(ac, av, "hfo:", options, NULL);
+               i = getopt_long(ac, av, "qvhfo:", options, NULL);
                if (i < 0)
                        break;
                switch (i) {
                case 'o':
                        wgtfile = optarg;
                        break;
+               case 'q':
+                       if (verbosity)
+                               verbosity--;
+                       break;
+               case 'v':
+                       verbosity++;
+                       break;
                case 'f':
                        force = 1;
                        break;
@@ -124,7 +135,7 @@ int main(int ac, char **av)
                return 1;
        }
 
-printf("\n\nPACKING widget %s from directory %s\n", wgtfile, directory);
+       notice("-- PACKING widget %s from directory %s", wgtfile, directory);
 
        /* creates an existing widget (for realpath it must exist) */
        i = open(wgtfile, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, 0666);
index 6a6a72a..cd506fc 100644 (file)
@@ -63,6 +63,8 @@ static void usage()
                "   -d number        the number of the distributor signature (zero for automatic)\n"
                "   -a               the author signature\n"
                "   -f               force overwriting\n"
+               "   -q               quiet\n"
+               "   -v               verbose\n"
                "\n",
                appname
        );
@@ -75,6 +77,8 @@ static struct option options[] = {
        { "author",      no_argument,       NULL, 'a' },
        { "force",       no_argument,       NULL, 'f' },
        { "help",        no_argument,       NULL, 'h' },
+       { "quiet",       no_argument,       NULL, 'q' },
+       { "verbose",     no_argument,       NULL, 'v' },
        { NULL, 0, NULL, 0 }
 };
 
@@ -187,7 +191,7 @@ int main(int ac, char **av)
                return 1;
        }
 
-printf("\n\nSIGNING content of directory %s for number %u\n", directory, number);
+       notice("-- SIGNING content of directory %s for number %u", directory, number);
 
        certfiles[ncert] = NULL;
        return !!create_digsig(number, keyfile, (const char**)certfiles);
diff --git a/wgtpkg-verbose.c b/wgtpkg-verbose.c
new file mode 100644 (file)
index 0000000..1472a90
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ Copyright 2015 IoT.bzh
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+#include <string.h>
+
+int verbosity = 1;
+
+int verbose_scan_args(int argc, char **argv)
+{
+       int i, r;
+       for (i=r=0 ; i < argc ; i++) {
+               if (!strcmp(argv[i], "-q"))
+                       verbosity = verbosity ? verbosity-1 : 0;
+               else if (!strcmp(argv[i], "-v"))
+                       verbosity++;
+               else
+                       argv[r++] = argv[i];
+       }
+       argv[r] = NULL;
+       return r;
+}
+
+
index 5a2fcbf..d35b7f4 100644 (file)
--- a/wgtpkg.h
+++ b/wgtpkg.h
@@ -88,6 +88,15 @@ extern struct filedesc *get_signature(unsigned int number);
 extern int file_set_prop(struct filedesc *file, const char *name, const char *value);
 extern const char *file_get_prop(struct filedesc *file, const char *name);
 
+/**************************************************************/
+/* from wgtpkg-verbose */
+extern int verbosity;
+#define warning(...) do{if(verbosity)syslog(LOG_WARNING,__VA_ARGS__);}while(0)
+#define notice(...)  do{if(verbosity)syslog(LOG_NOTICE,__VA_ARGS__);}while(0)
+#define info(...)    do{if(verbosity)syslog(LOG_INFO,__VA_ARGS__);}while(0)
+#define debug(...)   do{if(verbosity>1)syslog(LOG_DEBUG,__VA_ARGS__);}while(0)
+extern int verbose_scan_args(int argc, char **argv);
+
 /**************************************************************/
 /* from wgtpkg-workdir */