X-Git-Url: https://sigrok.org/gitweb/?p=libsigrokdecode.git;a=blobdiff_plain;f=tools%2Finstall-decoders;h=30360dbd9e5515d5c37adc6aac4a2485f9159053;hp=8445da561df4beb55f6056f445f4ad2773dec546;hb=4c58713b0d536f37b8630ebd142185aa56946335;hpb=135b790c851c52400279e7c932e1f900d91ae5cc diff --git a/tools/install-decoders b/tools/install-decoders index 8445da5..30360db 100755 --- a/tools/install-decoders +++ b/tools/install-decoders @@ -18,12 +18,27 @@ ## along with this program; if not, see . ## +import errno import os import sys from shutil import copy from getopt import getopt +_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): worklist = [] for pd in os.listdir(srcdir): @@ -42,26 +57,22 @@ def install(srcdir, dstdir, s): if install_list: worklist.append((pd, pd_dir, install_list)) + worklist.sort() print("Installing %d %s:" % (len(worklist), s)) - col = 0 for pd, pd_dir, install_list in worklist: - msg = pd + ' ' - if (col + len(msg) > 80): - print() - col = 0 - print(msg, end='') - col += len(msg) + _install_pretty_print("{} ".format(pd)) pd_dst = os.path.join(dstdir, pd) try: os.mkdir(pd_dst) except OSError as e: - if e.errno != os.errno.EEXIST: + if e.errno != errno.EEXIST: raise else: pass for f in install_list: copy(os.path.join(pd_dir, f), pd_dst) print() + _install_pretty_print(None) def config_get_extra_install(config_file):