2016-07-20 08:59:39 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
##
|
|
|
|
## This file is part of the libsigrokdecode project.
|
|
|
|
##
|
|
|
|
## Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
|
|
|
|
##
|
|
|
|
## 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 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
##
|
|
|
|
|
2019-09-09 00:07:19 -07:00
|
|
|
import errno
|
2016-07-20 08:59:39 +08:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
from shutil import copy
|
|
|
|
from getopt import getopt
|
|
|
|
|
|
|
|
|
2018-05-27 17:10:57 +08:00
|
|
|
_inst_pp_col_max = 80
|
|
|
|
_inst_pp_col = 0
|
|
|
|
def _install_pretty_print(item):
|
|
|
|
"""Pretty print an install item. Enforce maximum line width."""
|
|
|
|
global _inst_pp_col
|
|
|
|
if item is None:
|
|
|
|
_inst_pp_col = 0
|
|
|
|
return
|
|
|
|
_inst_pp_col += len(item)
|
|
|
|
if _inst_pp_col > _inst_pp_col_max:
|
|
|
|
print()
|
|
|
|
_inst_pp_col = len(item)
|
|
|
|
print(item, end = "")
|
|
|
|
|
|
|
|
def install(srcdir, dstdir, s):
|
2016-07-20 08:59:39 +08:00
|
|
|
worklist = []
|
|
|
|
for pd in os.listdir(srcdir):
|
|
|
|
pd_dir = srcdir + '/' + pd
|
|
|
|
if not os.path.isdir(pd_dir):
|
|
|
|
continue
|
|
|
|
install_list = []
|
|
|
|
for f in os.listdir(pd_dir):
|
|
|
|
pd_file = pd_dir + '/' + f
|
|
|
|
if not os.path.isfile(pd_file):
|
|
|
|
continue
|
|
|
|
if f == 'config':
|
|
|
|
install_list.extend(config_get_extra_install(pd_file))
|
|
|
|
elif f[-3:] == '.py':
|
|
|
|
install_list.append(f)
|
2018-05-27 17:10:57 +08:00
|
|
|
if install_list:
|
|
|
|
worklist.append((pd, pd_dir, install_list))
|
2016-07-20 08:59:39 +08:00
|
|
|
|
2018-05-27 17:10:57 +08:00
|
|
|
worklist.sort()
|
|
|
|
print("Installing %d %s:" % (len(worklist), s))
|
2016-07-20 08:59:39 +08:00
|
|
|
for pd, pd_dir, install_list in worklist:
|
2018-05-27 17:10:57 +08:00
|
|
|
_install_pretty_print("{} ".format(pd))
|
2016-07-20 08:59:39 +08:00
|
|
|
pd_dst = os.path.join(dstdir, pd)
|
|
|
|
try:
|
|
|
|
os.mkdir(pd_dst)
|
|
|
|
except OSError as e:
|
2019-09-09 00:07:19 -07:00
|
|
|
if e.errno != errno.EEXIST:
|
2016-07-20 08:59:39 +08:00
|
|
|
raise
|
|
|
|
else:
|
|
|
|
pass
|
|
|
|
for f in install_list:
|
|
|
|
copy(os.path.join(pd_dir, f), pd_dst)
|
|
|
|
print()
|
2018-05-27 17:10:57 +08:00
|
|
|
_install_pretty_print(None)
|
2016-07-20 08:59:39 +08:00
|
|
|
|
|
|
|
|
|
|
|
def config_get_extra_install(config_file):
|
|
|
|
install_list = []
|
|
|
|
for line in open(config_file).read().split('\n'):
|
|
|
|
line = line.strip()
|
|
|
|
if len(line) == 0 or line[0] == '#':
|
|
|
|
continue
|
|
|
|
words = line.split()
|
|
|
|
if words[0] != 'extra-install':
|
|
|
|
continue
|
|
|
|
install_list.extend(words[1:])
|
|
|
|
|
|
|
|
return install_list
|
|
|
|
|
|
|
|
|
|
|
|
def usage(msg=None):
|
|
|
|
if msg:
|
|
|
|
print(msg)
|
|
|
|
ret = 1
|
|
|
|
else:
|
|
|
|
ret = 0
|
|
|
|
print("""Usage:
|
|
|
|
install-decoders [-i <decoder source>] -o <install path>""")
|
|
|
|
sys.exit(ret)
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# main
|
|
|
|
#
|
|
|
|
|
|
|
|
src = 'decoders'
|
|
|
|
dst = None
|
|
|
|
try:
|
|
|
|
opts, args = getopt(sys.argv[1:], 'i:o:')
|
|
|
|
for opt, arg in opts:
|
|
|
|
if opt == '-i':
|
|
|
|
src = arg
|
|
|
|
elif opt == '-o':
|
|
|
|
dst = arg
|
|
|
|
except Exception as e:
|
|
|
|
usage(str(e))
|
|
|
|
|
|
|
|
if len(args) != 0 or dst is None:
|
|
|
|
usage()
|
|
|
|
|
2018-05-27 17:10:57 +08:00
|
|
|
install(src, dst, 'protocol decoders')
|
2019-09-09 00:07:19 -07:00
|
|
|
install(src + '/common', dst + '/common', 'common modules')
|
2016-07-20 08:59:39 +08:00
|
|
|
|
|
|
|
|