>From ba5620880ac965d1ecd302b77dd90bfd8c7bf682 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 31 Jul 2022 21:08:55 +0200 Subject: [PATCH 12/16] gnulib-tool.py: Implement options --symlink and --local-symlink. * gnulib-tool.py (main): Handle options --symlink and --local-symlink. * pygnulib/constants.py (link_if_changed): Ignore FileNotFoundError from os.remove call. --- ChangeLog | 5 +++++ gnulib-tool.py | 14 ++++++++++++++ pygnulib/constants.py | 5 ++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 59bfec205e..0ba5352039 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2022-07-31 Bruno Haible + gnulib-tool.py: Implement options --symlink and --local-symlink. + * gnulib-tool.py (main): Handle options --symlink and --local-symlink. + * pygnulib/constants.py (link_if_changed): Ignore FileNotFoundError from + os.remove call. + gnulib-tool.py: Make --copy-file work. * gnulib-tool.py (main) [copy-file]: Fix reference to uninitialized variable. Fix error handling of os.makedirs. Pass the destdir to the diff --git a/gnulib-tool.py b/gnulib-tool.py index f20d1157a3..f936a92031 100755 --- a/gnulib-tool.py +++ b/gnulib-tool.py @@ -337,6 +337,16 @@ def main(): dest="makefile", default=None, type=str) + # symlink + parser.add_argument('-s', '--symbolic', '--symlink', + dest='symlink', + default=None, + action='store_true') + # local-symlink + parser.add_argument('--local-symlink', + dest='lsymlink', + default=None, + action='store_true') # All other arguments are collected. parser.add_argument("non_option_arguments", nargs='*') @@ -543,6 +553,8 @@ def main(): avoids = [ module for list1 in avoids for module in list1 ] + symlink = cmdargs.symlink == True + lsymlink = cmdargs.lsymlink == True # Create pygnulib configuration. config = classes.GLConfig( @@ -566,6 +578,8 @@ def main(): podomain=podomain, witness_c_macro=witness_c_macro, vc_files=vc_files, + symbolic=symlink, + lsymbolic=lsymlink, modcache=modcache, verbose=verbose, dryrun=dryrun, diff --git a/pygnulib/constants.py b/pygnulib/constants.py index 9ef2e01089..10bd363f5b 100644 --- a/pygnulib/constants.py +++ b/pygnulib/constants.py @@ -330,7 +330,10 @@ def link_if_changed(src, dest): '''Create a symlink, but avoids munging timestamps if the link is correct.''' ln_target = os.path.realpath(src) if not (os.path.islink(dest) and src == ln_target): - os.remove(dest) + try: + os.remove(dest) + except FileNotFoundError: + pass link_relative(src, dest) -- 2.34.1