From 135b790c851c52400279e7c932e1f900d91ae5cc Mon Sep 17 00:00:00 2001 From: Uwe Hermann Date: Tue, 24 May 2016 21:42:02 +0200 Subject: [PATCH] Move common/ directory into decoders/. This simplifies cross-platform handling of the Python/decoder paths and module installation/dist a bit and also fixes bug #804. --- Makefile.am | 11 ++-------- decoders/common/__init__.py | 20 +++++++++++++++++++ .../common}/plugtrx/__init__.py | 0 {common => decoders/common}/plugtrx/mod.py | 0 .../common}/sdcard/__init__.py | 0 {common => decoders/common}/sdcard/mod.py | 0 .../common}/srdhelper/__init__.py | 0 {common => decoders/common}/srdhelper/mod.py | 0 decoders/dcf77/pd.py | 2 +- decoders/ds1307/pd.py | 2 +- decoders/rtc8564/pd.py | 2 +- decoders/sdcard_sd/pd.py | 2 +- decoders/sdcard_spi/pd.py | 2 +- decoders/xfp/pd.py | 2 +- srd.c | 6 ------ tools/install-decoders | 10 ++++++---- 16 files changed, 34 insertions(+), 25 deletions(-) create mode 100644 decoders/common/__init__.py rename {common => decoders/common}/plugtrx/__init__.py (100%) rename {common => decoders/common}/plugtrx/mod.py (100%) rename {common => decoders/common}/sdcard/__init__.py (100%) rename {common => decoders/common}/sdcard/mod.py (100%) rename {common => decoders/common}/srdhelper/__init__.py (100%) rename {common => decoders/common}/srdhelper/mod.py (100%) diff --git a/Makefile.am b/Makefile.am index 1a1074e..a8df8f6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -23,12 +23,11 @@ AM_LIBTOOLFLAGS = --silent GNUMAKEFLAGS = --no-print-directory DECODERS_DIR = $(pkgdatadir)/decoders -COMMON_DIR = $(pkgdatadir)/common # Do not hard-code the decoders location on Windows. if WIN32 AM_CPPFLAGS = else -AM_CPPFLAGS = -DDECODERS_DIR='"$(DECODERS_DIR)"' -DCOMMON_DIR='"$(COMMON_DIR)"' +AM_CPPFLAGS = -DDECODERS_DIR='"$(DECODERS_DIR)"' endif # The tests CFLAGS are a superset of the libsigrokdecode CFLAGS. @@ -89,20 +88,14 @@ ChangeLog: dist-hook: ChangeLog $(MKDIR_P) $(distdir)/tools cp ${top_srcdir}/tools/install-decoders $(distdir)/tools - $(MKDIR_P) $(distdir)/common - cp -a ${top_srcdir}/common $(distdir) $(MKDIR_P) $(distdir)/decoders ${top_srcdir}/tools/install-decoders -i ${top_srcdir}/decoders \ -o $(distdir)/decoders -install-common: - $(MKDIR_P) $(DESTDIR)$(COMMON_DIR) - cp -a ${top_srcdir}/common $(DESTDIR)$(pkgdatadir) - install-decoders: $(MKDIR_P) $(DESTDIR)$(DECODERS_DIR) $(PYTHON3) ${top_srcdir}/tools/install-decoders \ -i ${top_srcdir}/decoders -o $(DESTDIR)$(DECODERS_DIR) -install-data-hook: install-common install-decoders +install-data-hook: install-decoders diff --git a/decoders/common/__init__.py b/decoders/common/__init__.py new file mode 100644 index 0000000..c597431 --- /dev/null +++ b/decoders/common/__init__.py @@ -0,0 +1,20 @@ +## +## This file is part of the libsigrokdecode project. +## +## Copyright (C) 2016 Uwe Hermann +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +## + diff --git a/common/plugtrx/__init__.py b/decoders/common/plugtrx/__init__.py similarity index 100% rename from common/plugtrx/__init__.py rename to decoders/common/plugtrx/__init__.py diff --git a/common/plugtrx/mod.py b/decoders/common/plugtrx/mod.py similarity index 100% rename from common/plugtrx/mod.py rename to decoders/common/plugtrx/mod.py diff --git a/common/sdcard/__init__.py b/decoders/common/sdcard/__init__.py similarity index 100% rename from common/sdcard/__init__.py rename to decoders/common/sdcard/__init__.py diff --git a/common/sdcard/mod.py b/decoders/common/sdcard/mod.py similarity index 100% rename from common/sdcard/mod.py rename to decoders/common/sdcard/mod.py diff --git a/common/srdhelper/__init__.py b/decoders/common/srdhelper/__init__.py similarity index 100% rename from common/srdhelper/__init__.py rename to decoders/common/srdhelper/__init__.py diff --git a/common/srdhelper/mod.py b/decoders/common/srdhelper/mod.py similarity index 100% rename from common/srdhelper/mod.py rename to decoders/common/srdhelper/mod.py diff --git a/decoders/dcf77/pd.py b/decoders/dcf77/pd.py index 4f956aa..0f1d3d1 100644 --- a/decoders/dcf77/pd.py +++ b/decoders/dcf77/pd.py @@ -20,7 +20,7 @@ import sigrokdecode as srd import calendar -from srdhelper import bcd2int +from common.srdhelper import bcd2int class SamplerateError(Exception): pass diff --git a/decoders/ds1307/pd.py b/decoders/ds1307/pd.py index 6d862af..f181fd9 100644 --- a/decoders/ds1307/pd.py +++ b/decoders/ds1307/pd.py @@ -21,7 +21,7 @@ import re import sigrokdecode as srd -from srdhelper import bcd2int +from common.srdhelper import bcd2int days_of_week = ( 'Sunday', 'Monday', 'Tuesday', 'Wednesday', diff --git a/decoders/rtc8564/pd.py b/decoders/rtc8564/pd.py index 4bcd096..4ecc15a 100644 --- a/decoders/rtc8564/pd.py +++ b/decoders/rtc8564/pd.py @@ -19,7 +19,7 @@ ## import sigrokdecode as srd -from srdhelper import bcd2int +from common.srdhelper import bcd2int def reg_list(): l = [] diff --git a/decoders/sdcard_sd/pd.py b/decoders/sdcard_sd/pd.py index 442a563..79c2074 100644 --- a/decoders/sdcard_sd/pd.py +++ b/decoders/sdcard_sd/pd.py @@ -19,7 +19,7 @@ ## import sigrokdecode as srd -from sdcard import (cmd_names, acmd_names, accepted_voltages, card_status, sd_status) +from common.sdcard import (cmd_names, acmd_names, accepted_voltages, card_status, sd_status) class Decoder(srd.Decoder): api_version = 2 diff --git a/decoders/sdcard_spi/pd.py b/decoders/sdcard_spi/pd.py index e069b6e..45490ad 100644 --- a/decoders/sdcard_spi/pd.py +++ b/decoders/sdcard_spi/pd.py @@ -19,7 +19,7 @@ ## import sigrokdecode as srd -from sdcard import (cmd_names, acmd_names) +from common.sdcard import (cmd_names, acmd_names) class Decoder(srd.Decoder): api_version = 2 diff --git a/decoders/xfp/pd.py b/decoders/xfp/pd.py index 26f3311..27135e5 100644 --- a/decoders/xfp/pd.py +++ b/decoders/xfp/pd.py @@ -18,7 +18,7 @@ ## import sigrokdecode as srd -from plugtrx import (MODULE_ID, ALARM_THRESHOLDS, AD_READOUTS, GCS_BITS, +from common.plugtrx import (MODULE_ID, ALARM_THRESHOLDS, AD_READOUTS, GCS_BITS, CONNECTOR, TRANSCEIVER, SERIAL_ENCODING, XMIT_TECH, CDR, DEVICE_TECH, ENHANCED_OPTS, AUX_TYPES) diff --git a/srd.c b/srd.c index c74d2de..2947ca8 100644 --- a/srd.c +++ b/srd.c @@ -169,12 +169,6 @@ SRD_API int srd_init(const char *path) } } #ifdef DECODERS_DIR - /* Common modules for use by any decoder. */ - if ((ret = srd_decoder_searchpath_add(COMMON_DIR)) != SRD_OK) { - Py_Finalize(); - return ret; - } - /* Hardcoded decoders install location, if defined. */ if ((ret = srd_decoder_searchpath_add(DECODERS_DIR)) != SRD_OK) { Py_Finalize(); diff --git a/tools/install-decoders b/tools/install-decoders index 465c70e..8445da5 100755 --- a/tools/install-decoders +++ b/tools/install-decoders @@ -24,7 +24,7 @@ from shutil import copy from getopt import getopt -def install(srcdir, dstdir): +def install(srcdir, dstdir, s): worklist = [] for pd in os.listdir(srcdir): pd_dir = srcdir + '/' + pd @@ -39,9 +39,10 @@ def install(srcdir, dstdir): install_list.extend(config_get_extra_install(pd_file)) elif f[-3:] == '.py': install_list.append(f) - worklist.append((pd, pd_dir, install_list)) + if install_list: + worklist.append((pd, pd_dir, install_list)) - print("Installing %d protocol decoders:" % len(worklist)) + print("Installing %d %s:" % (len(worklist), s)) col = 0 for pd, pd_dir, install_list in worklist: msg = pd + ' ' @@ -107,6 +108,7 @@ except Exception as e: if len(args) != 0 or dst is None: usage() -install(src, dst) +install(src, dst, 'protocol decoders') +install(src + '/common', dst + '/common', 'common modules') -- 2.30.2