On Tue, 2013-07-30 at 09:52 -0700, Brian C. Lane wrote:
On Tue, Jul 30, 2013 at 11:44:11AM +0200, Vratislav Podzimek wrote:
> Now that we have a function to set system time, we could wrap it with one more
> and use it instead of running 'date -s' which could be problematic and
prints
> out the time and date to tty1.
>
> Also add logging to the set_system_time function, so that we can see why the
> timestamps suddenly changed in the logs.
>
> Signed-off-by: Vratislav Podzimek <vpodzime(a)redhat.com>
> ---
> pyanaconda/isys/__init__.py | 33 ++++++++++++++++++++++++++++--
> pyanaconda/ntp.py | 1 -
> pyanaconda/ui/gui/spokes/datetime_spoke.py | 5 ++---
> 3 files changed, 33 insertions(+), 6 deletions(-)
>
> diff --git a/pyanaconda/isys/__init__.py b/pyanaconda/isys/__init__.py
> index a320bf9..51976db 100755
> --- a/pyanaconda/isys/__init__.py
> +++ b/pyanaconda/isys/__init__.py
> @@ -1,7 +1,7 @@
> #
> # isys.py - installer utility functions and glue for C module
> #
> -# Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 Red Hat, Inc.
> +# Copyright (C) 2001-2013 Red Hat, Inc.
> # All rights reserved.
> #
> # This program is free software; you can redistribute it and/or modify
> @@ -41,6 +41,8 @@ import blivet.arch
> import re
> import struct
> import dbus
> +import time
> +import datetime
>
> import logging
> log = logging.getLogger("anaconda")
> @@ -120,7 +122,34 @@ def set_system_time(secs):
>
> """
>
> - return _isys.set_system_time(secs)
> + _isys.set_system_time(secs)
> + log.info("System time set to %s", time.ctime(secs))
> +
> +def set_system_date_time(year=None, month=None, day=None, hour=None, minute=None,
> + second=None, utc=False):
> + """
> + Set system date and time given by the parameters as numbers. If some
> + parameter is missing or None, the current system date/time field is used
> + instead (i.e. the value is not changed by this function).
> +
> + :type year, month, ..., second: int
> + :param utc: wheter the other parameters specify UTC or local time
> + :type utc: bool
> +
> + """
> +
> + # get the right values
> + utc = 0 if utc else 1
> + year = year or datetime.datetime.now().year
> + month = month or datetime.datetime.now().month
> + day = day or datetime.datetime.now().day
> + hour = hour or datetime.datetime.now().hour
> + minute = minute or datetime.datetime.now().minute
> + second = second or datetime.datetime.now().second
I'd call datetime.datetime.now() once and pick from the result instead.
In practice it doesn't really matter, but there is a slim chance of the
data changing from one call to the next.
Good point, thanks! I wanted to make the
values as actual as possible,
but overlooked that it may possibly create a wrong mixture. Fixing
locally and pushing.
--
Vratislav Podzimek
Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic