Example #1
0
  def test_get_time_labels(self):
    """
    Checks the get_time_labels() function.
    """

    # test the pydoc examples
    self.assertEquals(['6m', '40s'], str_tools.get_time_labels(400))
    self.assertEquals(['1 hour', '40 seconds'], str_tools.get_time_labels(3640, True))

    self.assertEquals([], str_tools.get_time_labels(0))
    self.assertEquals(['-10s'], str_tools.get_time_labels(-10))

    self.assertRaises(TypeError, str_tools.get_time_labels, None)
    self.assertRaises(TypeError, str_tools.get_time_labels, 'hello world')
Example #2
0
  def test_get_time_labels(self):
    """
    Checks the get_time_labels() function.
    """

    # test the pydoc examples
    self.assertEquals(['6m', '40s'], str_tools.get_time_labels(400))
    self.assertEquals(['1 hour', '40 seconds'], str_tools.get_time_labels(3640, True))

    self.assertEquals([], str_tools.get_time_labels(0))
    self.assertEquals(['-10s'], str_tools.get_time_labels(-10))

    self.assertRaises(TypeError, str_tools.get_time_labels, None)
    self.assertRaises(TypeError, str_tools.get_time_labels, 'hello world')
Example #3
0
    def _updateAccountingInfo(self):
        """
    Updates mapping used for accounting info. This includes the following keys:
    status, resetTime, read, written, readLimit, writtenLimit
    
    Any failed lookups result in a mapping to an empty string.
    """

        conn = torTools.getConn()
        queried = dict([(arg, "") for arg in ACCOUNTING_ARGS])
        queried["status"] = conn.getInfo("accounting/hibernating", None)

        # provides a nicely formatted reset time
        endInterval = conn.getInfo("accounting/interval-end", None)
        if endInterval:
            # converts from gmt to local with respect to DST
            if time.localtime()[8]: tz_offset = time.altzone
            else: tz_offset = time.timezone

            sec = time.mktime(time.strptime(
                endInterval, "%Y-%m-%d %H:%M:%S")) - time.time() - tz_offset
            if CONFIG["features.graph.bw.accounting.isTimeLong"]:
                queried["resetTime"] = ", ".join(
                    str_tools.get_time_labels(sec, True))
            else:
                days = sec / 86400
                sec %= 86400
                hours = sec / 3600
                sec %= 3600
                minutes = sec / 60
                sec %= 60
                queried["resetTime"] = "%i:%02i:%02i:%02i" % (days, hours,
                                                              minutes, sec)

        # number of bytes used and in total for the accounting period
        used = conn.getInfo("accounting/bytes", None)
        left = conn.getInfo("accounting/bytes-left", None)

        if used and left:
            usedComp, leftComp = used.split(" "), left.split(" ")
            read, written = int(usedComp[0]), int(usedComp[1])
            readLeft, writtenLeft = int(leftComp[0]), int(leftComp[1])

            queried["read"] = str_tools.get_size_label(read)
            queried["written"] = str_tools.get_size_label(written)
            queried["readLimit"] = str_tools.get_size_label(read + readLeft)
            queried["writtenLimit"] = str_tools.get_size_label(written +
                                                               writtenLeft)

        self.accountingInfo = queried
        self.accountingLastUpdated = time.time()
Example #4
0
 def _updateAccountingInfo(self):
   """
   Updates mapping used for accounting info. This includes the following keys:
   status, resetTime, read, written, readLimit, writtenLimit
   
   Any failed lookups result in a mapping to an empty string.
   """
   
   conn = torTools.getConn()
   queried = dict([(arg, "") for arg in ACCOUNTING_ARGS])
   queried["status"] = conn.getInfo("accounting/hibernating", None)
   
   # provides a nicely formatted reset time
   endInterval = conn.getInfo("accounting/interval-end", None)
   if endInterval:
     # converts from gmt to local with respect to DST
     if time.localtime()[8]: tz_offset = time.altzone
     else: tz_offset = time.timezone
     
     sec = time.mktime(time.strptime(endInterval, "%Y-%m-%d %H:%M:%S")) - time.time() - tz_offset
     if CONFIG["features.graph.bw.accounting.isTimeLong"]:
       queried["resetTime"] = ", ".join(str_tools.get_time_labels(sec, True))
     else:
       days = sec / 86400
       sec %= 86400
       hours = sec / 3600
       sec %= 3600
       minutes = sec / 60
       sec %= 60
       queried["resetTime"] = "%i:%02i:%02i:%02i" % (days, hours, minutes, sec)
   
   # number of bytes used and in total for the accounting period
   used = conn.getInfo("accounting/bytes", None)
   left = conn.getInfo("accounting/bytes-left", None)
   
   if used and left:
     usedComp, leftComp = used.split(" "), left.split(" ")
     read, written = int(usedComp[0]), int(usedComp[1])
     readLeft, writtenLeft = int(leftComp[0]), int(leftComp[1])
     
     queried["read"] = str_tools.get_size_label(read)
     queried["written"] = str_tools.get_size_label(written)
     queried["readLimit"] = str_tools.get_size_label(read + readLeft)
     queried["writtenLimit"] = str_tools.get_size_label(written + writtenLeft)
   
   self.accountingInfo = queried
   self.accountingLastUpdated = time.time()