diff options
author | Aleksey Filippov <alekseyf@google.com> | 2018-01-29 00:10:43 +0000 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2018-01-30 07:08:22 +1100 |
commit | 2cf85ae16f79b5edcbfa34d57b477c984c79e7a5 (patch) | |
tree | f0c533465924188dec1a95926ae48b4c63c00309 /mesonbuild/scripts | |
parent | 4e5ad57161a475dfab1c1a4edde075b2620b9f75 (diff) | |
download | meson-2cf85ae16f79b5edcbfa34d57b477c984c79e7a5.zip meson-2cf85ae16f79b5edcbfa34d57b477c984c79e7a5.tar.gz meson-2cf85ae16f79b5edcbfa34d57b477c984c79e7a5.tar.bz2 |
Use os.path: basename() and dirname() instead of split()
According to Python documentation[1] dirname and basename
are defined as follows:
os.path.dirname() = os.path.split()[0]
os.path.basename() = os.path.split()[1]
For the purpose of better readability split() is replaced
by appropriate function if only one part of returned tuple
is used.
[1]: https://docs.python.org/3/library/os.path.html#os.path.split
Diffstat (limited to 'mesonbuild/scripts')
-rw-r--r-- | mesonbuild/scripts/gettext.py | 2 | ||||
-rw-r--r-- | mesonbuild/scripts/meson_install.py | 16 |
2 files changed, 9 insertions, 9 deletions
diff --git a/mesonbuild/scripts/gettext.py b/mesonbuild/scripts/gettext.py index 30ac54c..f308c5a 100644 --- a/mesonbuild/scripts/gettext.py +++ b/mesonbuild/scripts/gettext.py @@ -81,7 +81,7 @@ def do_install(src_sub, bld_sub, dest, pkgname, langs): srcfile = os.path.join(bld_sub, l + '.gmo') outfile = os.path.join(dest, l, 'LC_MESSAGES', pkgname + '.mo') - os.makedirs(os.path.split(outfile)[0], exist_ok=True) + os.makedirs(os.path.dirname(outfile), exist_ok=True) shutil.copyfile(srcfile, outfile) shutil.copystat(srcfile, outfile) print('Installing %s to %s' % (srcfile, outfile)) diff --git a/mesonbuild/scripts/meson_install.py b/mesonbuild/scripts/meson_install.py index fe1de1f..2f9f135 100644 --- a/mesonbuild/scripts/meson_install.py +++ b/mesonbuild/scripts/meson_install.py @@ -164,10 +164,10 @@ def do_copydir(data, src_prefix, src_dir, dst_dir, exclude): print('Tried to copy file %s but a directory of that name already exists.' % abs_dst) if os.path.exists(abs_dst): os.unlink(abs_dst) - parent_dir = os.path.split(abs_dst)[0] + parent_dir = os.path.dirname(abs_dst) if not os.path.isdir(parent_dir): os.mkdir(parent_dir) - shutil.copystat(os.path.split(abs_src)[0], parent_dir) + shutil.copystat(os.path.dirname(abs_src), parent_dir) shutil.copy2(abs_src, abs_dst, follow_symlinks=False) append_to_log(abs_dst) @@ -211,7 +211,7 @@ def install_data(d): fullfilename = i[0] outfilename = get_destdir_path(d, i[1]) mode = i[2] - outdir = os.path.split(outfilename)[0] + outdir = os.path.dirname(outfilename) d.dirmaker.makedirs(outdir, exist_ok=True) print('Installing %s to %s' % (fullfilename, outdir)) do_copyfile(fullfilename, outfilename) @@ -221,7 +221,7 @@ def install_man(d): for m in d.man: full_source_filename = m[0] outfilename = get_destdir_path(d, m[1]) - outdir = os.path.split(outfilename)[0] + outdir = os.path.dirname(outfilename) d.dirmaker.makedirs(outdir, exist_ok=True) print('Installing %s to %s' % (full_source_filename, outdir)) if outfilename.endswith('.gz') and not full_source_filename.endswith('.gz'): @@ -238,7 +238,7 @@ def install_man(d): def install_headers(d): for t in d.headers: fullfilename = t[0] - fname = os.path.split(fullfilename)[1] + fname = os.path.basename(fullfilename) outdir = get_destdir_path(d, t[1]) outfilename = os.path.join(outdir, fname) print('Installing %s to %s' % (fname, outdir)) @@ -304,7 +304,7 @@ def install_targets(d): for t in d.targets: fname = check_for_stampfile(t[0]) outdir = get_destdir_path(d, t[1]) - outname = os.path.join(outdir, os.path.split(fname)[-1]) + outname = os.path.join(outdir, os.path.basename(fname)) aliases = t[2] should_strip = t[3] install_rpath = t[4] @@ -316,7 +316,7 @@ def install_targets(d): do_copyfile(fname, outname) if should_strip and d.strip_bin is not None: if fname.endswith('.jar'): - print('Not stripping jar target:', os.path.split(fname)[1]) + print('Not stripping jar target:', os.path.basename(fname)) continue print('Stripping target {!r}'.format(fname)) ps, stdo, stde = Popen_safe(d.strip_bin + [outname]) @@ -366,7 +366,7 @@ def run(args): print('Installer script for Meson. Do not run on your own, mmm\'kay?') print('meson_install.py [install info file]') datafilename = args[0] - private_dir = os.path.split(datafilename)[0] + private_dir = os.path.dirname(datafilename) log_dir = os.path.join(private_dir, '../meson-logs') with open(os.path.join(log_dir, 'install-log.txt'), 'w') as lf: install_log_file = lf |