3 ## This file is part of the libsigrokdecode project.
5 ## Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
7 ## This program is free software; you can redistribute it and/or modify
8 ## it under the terms of the GNU General Public License as published by
9 ## the Free Software Foundation; either version 3 of the License, or
10 ## (at your option) any later version.
12 ## This program is distributed in the hope that it will be useful,
13 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ## GNU General Public License for more details.
17 ## You should have received a copy of the GNU General Public License
18 ## along with this program; if not, see <http://www.gnu.org/licenses/>.
24 from shutil import copy
25 from getopt import getopt
30 def _install_pretty_print(item):
31 """Pretty print an install item. Enforce maximum line width."""
36 _inst_pp_col += len(item)
37 if _inst_pp_col > _inst_pp_col_max:
39 _inst_pp_col = len(item)
42 def install(srcdir, dstdir, s):
44 for pd in os.listdir(srcdir):
45 pd_dir = srcdir + '/' + pd
46 if not os.path.isdir(pd_dir):
49 for f in os.listdir(pd_dir):
50 pd_file = pd_dir + '/' + f
51 if not os.path.isfile(pd_file):
54 install_list.extend(config_get_extra_install(pd_file))
56 install_list.append(f)
58 worklist.append((pd, pd_dir, install_list))
61 print("Installing %d %s:" % (len(worklist), s))
62 for pd, pd_dir, install_list in worklist:
63 _install_pretty_print("{} ".format(pd))
64 pd_dst = os.path.join(dstdir, pd)
68 if e.errno != errno.EEXIST:
72 for f in install_list:
73 copy(os.path.join(pd_dir, f), pd_dst)
75 _install_pretty_print(None)
78 def config_get_extra_install(config_file):
80 for line in open(config_file).read().split('\n'):
82 if len(line) == 0 or line[0] == '#':
85 if words[0] != 'extra-install':
87 install_list.extend(words[1:])
99 install-decoders [-i <decoder source>] -o <install path>""")
110 opts, args = getopt(sys.argv[1:], 'i:o:')
111 for opt, arg in opts:
116 except Exception as e:
119 if len(args) != 0 or dst is None:
122 install(src, dst, 'protocol decoders')
123 install(src + '/common', dst + '/common', 'common modules')