Esempio n. 1
0
def change(s, l):
    global start
    string_date = " ".join(str(x) for x in l)
    list_date = string_date.split()
    year = int(list_date[0])
    if (list_date[0] == "00"):
        start += 1
    year = (start * 1000) + year
    month = int(list_date[1])
    dayOfWeek = int(
        list_date[2])  #CONVERT THE TIME VARIABLE INTO INTEGER VALUE
    day = int(list_date[3])
    hour = int(list_date[4])
    minute = int(list_date[5])
    second = int(list_date[6])
    microsecond = int(list_date[7])
    user_zone = 'UTC'
    local_tz = utc_to_local(
        datetime(year, month, day, hour, minute, second, microsecond),
        user_zone)
    if s == 1:
        month = monthDict[local_tz.month]
        print local_tz
        os.system('date -s "' + str(local_tz.day) + " " + month + " " +
                  str(local_tz.year) + " " + str(local_tz.hour) + ":" +
                  str(local_tz.minute) + ":" + str(local_tz.second) +
                  '"')  #SET THE TIME IN LINUX MACHINE
    elif s == 2:
        try:
            import win32api
            import win32security
        except ImportError as e:
            print str(e)
            sys.exit(1)
        print local_tz
        priv_flags = win32security.TOKEN_ADJUST_PRIVILEGES | win32security.TOKEN_QUERY
        hToken = win32security.OpenProcessToken(win32api.GetCurrentProcess(),
                                                ntsecuritycon.MAXIMUM_ALLOWED)
        time_privilege = win32security.LookupPrivilegeValue(
            None, win32security.SE_TIME_ZONE_NAME)
        win32security.AdjustTokenPrivileges(
            hToken, 0, [(time_privilege, win32security.SE_PRIVILEGE_ENABLED)])
        win32api.SetTimeZoneInformation(
            (0, u'GMT Standard Time', (2000, 10, 5, 2, 0, 0, 0, 0), 0,
             u'GMT Daylight Time', (2000, 5, 3, 1, 0, 0, 0, 0), -60))
        win32api.SetSystemTime(
            local_tz.year, local_tz.month, dayOfWeek, local_tz.day,
            local_tz.hour, local_tz.minute, local_tz.second,
            local_tz.microsecond)  #SET THE TIME IN WINDOWS MACHINE
    else:
        print 'wrong param'
Esempio n. 2
0
 def set(self):
     tzi = tuple(getattr(self, n) for n, t in self._fields_)
     win32api.SetTimeZoneInformation(tzi)