man 2 clock_settime<br>call it with ctypes<br clear="all">--<br>Best Regards,<br> -- KDr2 <a href="http://kdr2.net">http://kdr2.net</a><br><br><br>
<br><br><div class="gmail_quote">On Thu, May 6, 2010 at 10:47 AM, J <span dir="ltr"><<a href="mailto:dreadpiratejeff@gmail.com">dreadpiratejeff@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Is there a better way to do this?<br>
<br>
def SkewTime():<br>
'''<br>
Optional function. We can skew time by 1 hour if we'd like to see real sync<br>
changes being enforced<br>
'''<br>
TIME_SKEW=1<br>
<a href="http://logging.info" target="_blank">logging.info</a>('Time Skewing has been selected. Setting clock ahead 1 hour')<br>
# Let's get our current time<br>
t = TimeCheck()<br>
<a href="http://logging.info" target="_blank">logging.info</a>('Current time is: %s' % time.asctime(t))<br>
# Now create new time string in the form MMDDhhmmYYYY for the date program<br>
hr = t.tm_hour + TIME_SKEW<br>
date_string = time.strftime('%m%d%H%M%Y',(t.tm_year,<br>
t.tm_mon,<br>
t.tm_mday,<br>
hr,<br>
t.tm_min,<br>
t.tm_sec,<br>
t.tm_wday,<br>
t.tm_yday,<br>
t.tm_isdst))<br>
logging.debug('New date string is: %s' % date_string)<br>
logging.debug('Setting new system time/date')<br>
status = SilentCall('/bin/date %s' % date_string)<br>
<a href="http://logging.info" target="_blank">logging.info</a>('Pre-sync time is: %s' % time.asctime())<br>
<br>
TimeCheck() as referenced above is a simple function that just returns<br>
the time.time_struct object from time.localtime(). I pull time a few<br>
times and it was a little cleaner to put that into a function and just<br>
call the function whenever I needed to.<br>
<br>
SilentCall() is a modification of subprocess.call() (which in reality<br>
just calls Popen(*popenargs,**kwargs).wait()) but it defaults to<br>
redirecting stdin and stdout to /dev/null to suppress shell output<br>
from the command being called.<br>
<br>
Anyway, what I'm wondering, is, while this works, is there a better<br>
way to do it than using part of the originally returned time_struct<br>
and injecting my own new hour argument (hr).<br>
<br>
The goal of this function is to just set the system clock one hour<br>
ahead, so when I call the Linux command 'ntpdate' I can get a real<br>
time change when it syncs the local clock to an NTP server.<br>
<br>
This just looks... well, big to me. I tried passing only the things I<br>
really needed to time.strftime(), but apparently, that requires the<br>
full 9-tuple from time_struct, not just individual parts of it.<br>
<br>
Like I said, it works well, I just wonder if there is a cleaner way of<br>
setting the local clock to a different time in python without having<br>
to do all this. The reason most of that exists, is because the linux<br>
date command expects to see the new date/time like this:<br>
MMDDhhmmYYYY.ss.<br>
<br>
Or am I just looking at this too hard and really did work it out nicely?<br>
<br>
Cheers<br>
Jeff<br>
<font color="#888888">--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br>