Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o, Mike Gilbert <floppym@g.o>
Subject: Re: [gentoo-portage-dev] [PATCH v2] bin/doins.py: implement install -p option (bug 642632)
Date: Sun, 31 Dec 2017 06:15:09
Message-Id: 7deb15ec-7156-1a5e-6405-763e4ce291e3@gentoo.org
In Reply to: Re: [gentoo-portage-dev] [PATCH v2] bin/doins.py: implement install -p option (bug 642632) by Mike Gilbert
1 On 12/30/2017 01:45 PM, Mike Gilbert wrote:
2 > On Fri, Dec 29, 2017 at 7:19 PM, Zac Medico <zmedico@g.o> wrote:
3 >> +def _set_timestamps(source_stat, dest):
4 >> + """Apply timestamps from source_stat to dest.
5 >> +
6 >> + Args:
7 >> + source_stat: stat result for the source file.
8 >> + dest: path to the dest file.
9 >> + """
10 >> + os.utime(dest, (source_stat.st_atime, source_stat.st_mtime))
11 >> +
12 >> +
13 >> +if sys.version_info >= (3, 3):
14 >> + def _set_timestamps_ns(source_stat, dest):
15 >> + os.utime(dest, ns=(source_stat.st_atime_ns, source_stat.st_mtime_ns))
16 >> +
17 >> + _set_timestamps_ns.__doc__ = _set_timestamps.__doc__
18 >> + _set_timestamps = _set_timestamps_ns
19 >> +
20 >> +
21 >
22 > This seems weirdly complex. I guess the goal was to reduce the
23 > sys.version_info check to once per import?
24
25 Yeah, and generally it's cleanest to create compatibility shims in cases
26 like this.
27
28 > The __doc__ trick is nifty, but I'm not sure I would ever want to use it myself.
29
30 Yeah, the alternative of writing the docstring twice wasn't very appealing.
31
32 > Anyway, just my thoughts as an unpracticed python programmer. It looks
33 > like this code will get the job done.
34
35 --
36 Thanks,
37 Zac