From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yw1-x112a.google.com (mail-yw1-x112a.google.com [IPv6:2607:f8b0:4864:20::112a]) by sourceware.org (Postfix) with ESMTPS id DB6E43858C29 for ; Thu, 18 Jan 2024 22:23:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DB6E43858C29 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DB6E43858C29 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::112a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705616592; cv=none; b=S6gEugZiAyckiIbnqJ57lKOmCzfG6JXrPJtEfeFFg77qoJXqNEACg6oaoRUoDkYlIdMIt/I0L/eN2RStRkfA/qekWZdY3aM9OGfVpYbnTv/p6gYbwW13B6CEkKsns0YmPgv5+TZfqNmicwlQsk8rrObvj8lXqXO2RHpU2RtLCjw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705616592; c=relaxed/simple; bh=oB8xR0lq4egx9W/ioA6+t9VjWc60ncjselx+kJa9ufE=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=X3FOi1d36UzgZGjcXym1yO+QYSHVTpOIZzSgVklhro6JNe2ptNuEpsJ014Ff2AId4mvQjK60Fl2YKdK92+ZW0221Bj8ZwPfZTAPf/JLXZerG5yYIn7M9d2AJxi9m87Rkvv0dNklbYKQu7OJppZMR5HIxYLL6yvbmVB1HEE/cxEI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x112a.google.com with SMTP id 00721157ae682-5ff7dd8d7ceso1435627b3.0 for ; Thu, 18 Jan 2024 14:23:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705616589; x=1706221389; darn=sourceware.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=GlV1aQbn3w74BSGPwIeISOpyF06X5lH5YVLy4Ox+IVg=; b=R7IfzljLHbDp1zPMtMchAjktWdh9ubsWJmoynI8RVRfqND4VBBds1pUX3d7licx/og Sz6dfjIfsTjM2JL5gw3jvAJPitwVporDGOv/+ykGLyXRqYPEj5kUYvtXQQpy7ip6vCFR dXL0G5m2s/3xm/irgOI0R/phVQbRMLzA1OSuifg4ZqWKBd+1Y28gcdoOJdZcBgN9yWmF aNZ5P0uRxc5pypCFEr7aZOH1Gkxwjz82NBJn/CKh7WX43WFvYuEzW5VA5PLpxNhgz1+T TcWrD58C2r4w578MTSy0TWCzhkHcu6gcXAreIrP7j3PY3aLA0n4hEykzlpoSV16yDWt9 68cQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705616589; x=1706221389; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GlV1aQbn3w74BSGPwIeISOpyF06X5lH5YVLy4Ox+IVg=; b=oZB9/a+t5BIv1l/hNtfU8jr16mhWZsibBQaXE6gnJAI0g9NFq3yDaVXm4vH2fa5/Yg TzKSP4I2Nb0nxOJBMbbPb7QbxS+ZgNiO+TVjnaCiBP+tNYZDWIRv5WAXKQShUwhLR+Wj 8QiSsXfgUzKH2DXa/M0XCVLlu1rhNsV2WWymuqUSYChnJfZHUNRN0z0I4EVvQRAm121U NNMazrHR8WeH7Fsc9qfscztH/sCqDXLLFl2HOfW/HD0fMhVunUaK353gFi35kBhNJR3s MjC7u6+r5smTMySF8xo3MddQ+8XXgvwcDqE2Hny8svX4ILBhGYagL7zaNzAXPZsnuAwW XGhg== X-Gm-Message-State: AOJu0YwnZ2NiOv8fdVhF2aykRuh+zGIrTHjzDBAZw0a8HMsW/ThAE4zO Ad2zuXsh83lJQomE4OjoINh9gspGXxs9Z7V1bV5nO7Y/NuYbt1rwjngsSRl+EYwPDJeT9jYrcvb UjhqXiVvVk5DYfCqF+hytfBISI6Ty3c+K X-Google-Smtp-Source: AGHT+IGWhDkF6EO33vo/cxvrEsl72PdiCdxa77Nhig/JrHeVbhQMDZCclHWdpsp+yHP/RLbnE+T6RF45RVTLZBXgoSs= X-Received: by 2002:a25:abb1:0:b0:dbe:6985:66fd with SMTP id v46-20020a25abb1000000b00dbe698566fdmr1278536ybi.119.1705616589198; Thu, 18 Jan 2024 14:23:09 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: "H.J. Lu" Date: Thu, 18 Jan 2024 14:22:32 -0800 Message-ID: Subject: Re: Further build-many-glibcs.py fixes for utcnow() deprecation To: Joseph Myers Cc: libc-alpha@sourceware.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3021.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Fri, Jan 12, 2024 at 6:05=E2=80=AFPM Joseph Myers = wrote: > > It turns out that the replacement of datetime.datetime.utcnow(), for a > warning produced early in running build-many-glibcs.py with Python > 3.12, (a) wasn't complete (there were other uses elsewhere in the > script also needing updating) and (b) broke reading of build-time from > build-state.json, because an aware datetime was written out including > +00:00 for the timezone, which was not expected by the strptime call. > > Fix the first by making the change to > datetime.datetime.now(datetime.timezone.utc) for all the remaining > utcnow() calls. Fix the second by using strftime with an explicit > format instead of just str() when formatting build times for > build-state.json and and email subjects, and then setting the timezone > explicitly when reading from build-state.json. (Other uses, in > particular messages output by the bot, continue to use str() as the > precise format should not matter in those cases; it shouldn't actually > matter for email subjects either but it seems a good idea to keep > those short.) > > Tested with a bot-cycle run and checking the format of times in > build-state.json afterwards. > > diff --git a/scripts/build-many-glibcs.py b/scripts/build-many-glibcs.py > index ec2ded6e56..20601ed853 100755 > --- a/scripts/build-many-glibcs.py > +++ b/scripts/build-many-glibcs.py > @@ -1057,7 +1057,8 @@ class Context(object): > def update_build_state(self, action, build_time, build_versions): > """Update the build state after a build.""" > build_time =3D build_time.replace(microsecond=3D0) > - self.build_state[action]['build-time'] =3D str(build_time) > + self.build_state[action]['build-time'] =3D build_time.strftime( > + '%Y-%m-%d %H:%M:%S') > self.build_state[action]['build-versions'] =3D build_versions > build_results =3D {} > for log in self.status_log_list: > @@ -1103,15 +1104,17 @@ class Context(object): > old_time_str =3D self.build_state[action]['build-time'] > if not old_time_str: > return True > - old_time =3D datetime.datetime.strptime(old_time_str, > - '%Y-%m-%d %H:%M:%S') > - new_time =3D datetime.datetime.utcnow() > + old_time =3D datetime.datetime.strptime( > + old_time_str, '%Y-%m-%d %H:%M:%S').replace( > + tzinfo=3Ddatetime.timezone.utc) > + new_time =3D datetime.datetime.now(datetime.timezone.utc) > delta =3D new_time - old_time > return delta.total_seconds() >=3D delay > > def bot_cycle(self): > """Run a single round of checkout and builds.""" > - print('Bot cycle starting %s.' % str(datetime.datetime.utcnow())= ) > + print('Bot cycle starting %s.' > + % str(datetime.datetime.now(datetime.timezone.utc))) > self.load_bot_config_json() > actions =3D ('host-libraries', 'compilers', 'glibcs') > self.bot_run_self(['--replace-sources'], 'checkout') > @@ -1163,12 +1166,13 @@ class Context(object): > shutil.copytree(self.logsdir, self.logsdir_old) > for a in actions: > if must_build[a]: > - build_time =3D datetime.datetime.utcnow() > + build_time =3D datetime.datetime.now(datetime.timezone.u= tc) > print('Rebuilding %s at %s.' % (a, str(build_time))) > self.bot_run_self([], a) > self.load_build_state_json() > self.bot_build_mail(a, build_time) > - print('Bot cycle done at %s.' % str(datetime.datetime.utcnow())) > + print('Bot cycle done at %s.' > + % str(datetime.datetime.now(datetime.timezone.utc))) > > def bot_build_mail(self, action, build_time): > """Send email with the results of a build.""" > @@ -1184,7 +1188,7 @@ class Context(object): > build_time =3D build_time.replace(microsecond=3D0) > subject =3D (self.bot_config['email-subject'] % > {'action': action, > - 'build-time': str(build_time)}) > + 'build-time': build_time.strftime('%Y-%m-%d %H:%M:%S= ')}) > results =3D self.build_state[action]['build-results'] > changes =3D self.build_state[action]['result-changes'] > ever_passed =3D set(self.build_state[action]['ever-passed']) > @@ -1233,7 +1237,8 @@ class Context(object): > msg['From'] =3D self.bot_config['email-from'] > msg['To'] =3D self.bot_config['email-to'] > msg['Message-ID'] =3D email.utils.make_msgid() > - msg['Date'] =3D email.utils.format_datetime(datetime.datetime.ut= cnow()) > + msg['Date'] =3D email.utils.format_datetime( > + datetime.datetime.now(datetime.timezone.utc)) > with smtplib.SMTP(self.bot_config['email-server']) as s: > s.send_message(msg) > > > -- > Joseph S. Myers > josmyers@redhat.com > LGTM. Thanks. --=20 H.J.