Anonymous avatar Anonymous committed e7a3bc8

Began coding timezone and hwclock backend support

Comments (0)

Files changed (3)

modules/support/vectorlinux/DATESET.py

 from datetime import datetime
 import utils
 import logging
-
+import os
 
 log = logging.getLogger('vasm')
 
+class HWClock(object):
+    """ Interact with the hwclock """
+    def __init__(self, descriptor = "/etc/hardwareclock")
+        self.descriptor = descriptor
+
+    def _line_sets_value(self, line):
+        """ Returns True if line is "localtime" or "UTC" """
+        return line.startswitn("localtime") or line.startswitn("UTC")
+
+    def get_value(self):
+        """ Read self.descriptor and return the current setting """
+        with open(self.descriptor) as f:
+            for line in f:
+                if _line_sets_value(line):
+                    return line.strip()
+
+    def set_value(self, value):
+        """ Save the provided value to /etc/hardwareclock """
+        newdata = []
+        with open(self.descriptor) as f:
+            for line in f:
+                if _lit_sets_value(line):
+                    line = "%s\n"% value
+                newdata.append(line)
+
+        f = open(self.descriptor, 'w')
+        f.writelines(''.join(newdata))
+        f.close()
+        
+class TimeZone(object):
+    """ Interact with the system timezone settings """
+    def __init__(self, zone=None):
+        self.zone = zone
+        self.tzlink = "/etc/localtime-copied-from"
+        self.timezones_base_dir = "/usr/share/zoneinfo"
+
+    def get_current_timezone(self):
+        """ Return a string representing the current timezone """
+        # To get the value, we must read /etc/localtime-copied-from.
+        # If this excepts, then no timezone is set.
+        tz = os.readlink(self.tzlink)
+        return tz.replace('/usr/share/zoneinfo/', "")
+
+    def _remove_tz_link(self):
+        """ remove the symlink that sets the timezone """
+        return  os.remove(self.tzlink)
+
+    def set_zone(self, zone=None):
+        """ Set the timezone to `zone` """
+        # first we remove the current setting
+        self._remove_tz_link()
+        
+        # we need to create a symlink to /usr/share/zoneinfo
+        src = os.path.join(self.timezones_base_dir, zone)
+        dest = self.tzlink
+        # This will except
+        return os.symlink(src, dest)
+
+    
+    
 
 class DateTime:
     """Manage the system date and time.

modules/support/vectorlinux/tests/test_DATESET.py

 
 import unittest
 import DATESET
-import os
 
 
 class DateTimeTest(unittest.TestCase):

modules/support/vectorlinux/utils.py

 
 def get_popen(cmd):
     """ return a subprocess.Popen object for the provided command to be launched """
-    #if type(cmd) == "list":
-    #    return sp.Popen(cmd, stdout=sp.PIPE, stderr=sp.STDOUT)
-    return sp.Popen(cmd, stdout=sp.PIPE, stderr=sp.STDOUT)
+    return sp.Popen(cmd, stdout=sp.PIPE, stderr=sp.PIPE)
 
 def launch_external_gui(f):
     """ Runs an external GUI application in a separate thread to keep
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.