示例#1
0
    def test_timelib(self):
        mt = timelib.localtime_mutable()
        print mt
        mt.add_seconds(3600)
        print mt
        print timelib.strftime("%Y-%m-%d", timelib.weekof(timelib.time()))

        t = timelib.now()
        for d in range(1, 60):
            week = timelib.weekof(t+(d*60*60*24))
            print timelib.MutableTime(week)

        print "Local time:"
        print timelib.localtimestamp()

        p = timelib.TimespecParser()
        for spec, secs in [
            ("0s", 0.0),
            ("3m", 180.0),
            ("3.0m", 180.0),
            ("3minute+2secs", 182.0),
            ("2h 3minute+2.2secs", 7382.2),
            ("-3m", -180.0),
            ("-3.0m", -180.0),
            ("1h3m", 3780.0),
            ("1h-3m", 3420.0),
            ("1d 3m", 86580.0)]:
            p.parse(spec)
            self.assert_(p.seconds == secs)

        self.assertRaises(ValueError, p.parse, "12m -m")
示例#2
0
 def date(self, argv):
     """date [FORMAT]
 Display the current time and date. Optionally supply a format
 string."""
     if len(argv) > 1:
         fmt = " ".join(argv[1:])
         self._ui.print(timelib.localtimestamp(fmt=fmt))
     else:
         self._ui.print(timelib.localtimestamp())
示例#3
0
文件: CLI.py 项目: kdart/pycopia3
 def date(self, argv):
     """date [FORMAT]
 Display the current time and date. Optionally supply a format
 string."""
     if len(argv) > 1:
         fmt = " ".join(argv[1:])
         self._ui.print(timelib.localtimestamp(fmt=fmt))
     else:
         self._ui.print(timelib.localtimestamp())
示例#4
0
 def run_tests(self):
     #for test, testargs, testkwargs in self._tests:
     for i, entry in enumerate(self._tests):
         if not self.check_prerequisites(entry, i):
             continue
         try:
             self.config.logfile.note("%s: %r" % (timelib.localtimestamp(), entry))
             rv = entry()
         except KeyboardInterrupt:
             self.info("Test suite aborted by user.")
             if self._nested:
                 raise TestSuiteAbort, "aborted by user"
             else:
                 break
         except TestSuiteAbort, err:
             self.info("Suite aborted by test %s (%s)." % (entry.name(), err))
             entry.result = INCOMPLETE
             rv = ABORT
         # this should only happen with incorrectly written execute().
         if rv is None:
             self.report.diagnostic("warning: test returned None, assuming failed. "
                                   "Please fix the %s.execute()" % (entry.name()))
             rv = FAILED
         # keep return value in results
         # check for abort condition and abort if so
         if rv == ABORT:
             break
示例#5
0
 def run_tests(self):
     #for test, testargs, testkwargs in self._tests:
     for i, entry in enumerate(self._tests):
         if not self.check_prerequisites(entry, i):
             continue
         try:
             self.config.logfile.note("%s: %r" %
                                      (timelib.localtimestamp(), entry))
             rv = entry()
         except KeyboardInterrupt:
             self.info("Test suite aborted by user.")
             if self._nested:
                 raise TestSuiteAbort, "aborted by user"
             else:
                 break
         except TestSuiteAbort, err:
             self.info("Suite aborted by test %s (%s)." %
                       (entry.name(), err))
             entry.result = INCOMPLETE
             rv = ABORT
         # this should only happen with incorrectly written execute().
         if rv is None:
             self.report.diagnostic(
                 "warning: test returned None, assuming failed. "
                 "Please fix the %s.execute()" % (entry.name()))
             rv = FAILED
         # keep return value in results
         # check for abort condition and abort if so
         if rv == ABORT:
             break
示例#6
0
文件: Html.py 项目: xiangke/pycopia
 def message(self, msgtype, msg, level=1):
     if msgtype.find("TIME") >= 0:
         msg = timelib.localtimestamp(msg)
     msg = str(msg)
     msgtype = self._MSGTYPESUB.get(msgtype, msgtype)
     if msg.find("\n") > 0:
         return "<p>%s:</p>\n<pre>%s</pre>\n" % (msgtype, escape(msg))
     else:
         return "<p>%s: %s</p>\n" % (msgtype, escape(msg))
示例#7
0
 def message(self, msgtype, msg, level=1):
     if msgtype.find("TIME") >= 0:
         msg = timelib.localtimestamp(msg)
     msg = str(msg)
     msgtype = self._MSGTYPESUB.get(msgtype, msgtype)
     if msg.find("\n") > 0:
         return "<p>%s:</p>\n<pre>%s</pre>\n" % (msgtype, escape(msg))
     else:
         return '<p>%s: %s</p>\n' % (msgtype, escape(msg))
示例#8
0
 def send(self, smtp, mail_options=None, rcpt_options=None):
     """send off this message using the supplied SMTP sender object."""
     mopts = mail_options or []
     rcptopts = rcpt_options or []
     if not self.mail_from or not self.rcpt_to:
         raise RuntimeError, "AutoMessage: cannot send. no From or recipients."
     if self.has_key("Bcc"):
         del self["Bcc"]
     now = timelib.now()
     self["Date"] = formatdate(now)
     self["Message-ID"] = "<%s.%x@%s>" % (timelib.localtimestamp(
         now, fmt="%Y%m%d%H%M%S"), id(self) % 0x7fffffff, _get_hostname())
     return smtp.sendmail(self.mail_from, self.rcpt_to, self.as_string(0),
                          mopts, rcptopts)
示例#9
0
 def send(self, smtp, mail_options=None, rcpt_options=None):
     """send off this message using the supplied SMTP sender object."""
     mopts = mail_options or []
     rcptopts = rcpt_options or []
     if not self.mail_from or not self.rcpt_to:
         raise RuntimeError, "AutoMessage: cannot send. no From or recipients."
     if self.has_key("Bcc"):
         del self["Bcc"]
     now = timelib.now()
     self["Date"] = formatdate(now)
     self["Message-ID"] = "<%s.%x@%s>" % (
         timelib.localtimestamp(now, fmt="%Y%m%d%H%M%S"), 
         id(self) % 0x7fffffff,
         _get_hostname())
     return smtp.sendmail(self.mail_from, self.rcpt_to, self.as_string(0), mopts, rcptopts)
示例#10
0
文件: core.py 项目: llwang/powerdroid
    def _runTests(self):
        """Runs all the tests in the suite. 

        Handles running the TestEntry, reporting interrupts, checking for
        abort conditions, If a Test returns None (the default), it is reported
        as a failure since it was not written correctly.
        """
        for i, entry in enumerate(self._tests):
            if not self.CheckPrerequisites(entry, i):
                continue
            # merge any test-class specific configuration.
            cl = entry.inst.__class__
            testconf = os.path.join(
                os.path.dirname(sys.modules[cl.__module__].__file__),
                "%s.conf" % (cl.__name__, ))
            self.config.mergefile(testconf)
            self.config.evalupdate(self.config.options_override)
            # Add a note to the logfile to delimit test cases there.
            if self.config.flags.VERBOSE:
                self.config.logfile.note("%s: %r" %
                                         (timelib.localtimestamp(), entry))
            try:
                rv = entry.Run()
            except KeyboardInterrupt:
                if self._nested:
                    raise TestSuiteAbort, "Sub-suite aborted by user."
                else:
                    if self.config.UI.yes_no("Test interrupted. Abort suite?"):
                        self.Info("Test suite aborted by user.")
                        break
            except TestSuiteAbort, err:
                self.Info("Suite aborted by test %s (%s)." %
                          (entry.test_name, err))
                entry.result = constants.INCOMPLETE
                rv = constants.ABORT
                break
            # This should only happen with an incorrectly written execute() method.
            if rv is None:
                self.report.diagnostic(
                    "warning: test returned None, assuming Incomplete. "
                    "Please fix the %s.execute() method." % (entry.test_name))
                rv = constants.INCOMPLETE
            # check for abort condition and break the loop if so
            if rv == constants.ABORT:
                break
示例#11
0
 def __str__(self):
     pdu = self.pdu
     trapoid = pdu.varbinds[1]
     s = [
         "Trap from %s with ID %s for %s at %s:"
         % (self.ip, pdu.request_id, self.community, localtimestamp(self.timestamp))
     ]
     s.append("  Uptime: %s" % (pdu.varbinds[0],))
     obj = trapoid.value.get_object()
     if obj:
         s.append("  Trap OID: %s (%s)" % (trapoid, obj.__name__))
     else:
         s.append("  Trap OID: %s" % (trapoid,))
     for vb in pdu.varbinds[2:]:
         if vb.Object:
             s.append("    %s (%s) = %s" % (vb.oid, vb.Object.__name__, vb.value))
         else:
             s.append("    %s = %s" % (vb.oid, vb.value))
     return "\n".join(s)
示例#12
0
 def __str__(self):
     pdu = self.pdu
     trapoid = pdu.varbinds[1]
     s = [
         "Trap from %s with ID %s for %s at %s:" %
         (self.ip, pdu.request_id, self.community,
          localtimestamp(self.timestamp))
     ]
     s.append("  Uptime: %s" % (pdu.varbinds[0], ))
     obj = trapoid.value.get_object()
     if obj:
         s.append("  Trap OID: %s (%s)" % (trapoid, obj.__name__))
     else:
         s.append("  Trap OID: %s" % (trapoid, ))
     for vb in pdu.varbinds[2:]:
         if vb.Object:
             s.append("    %s (%s) = %s" %
                      (vb.oid, vb.Object.__name__, vb.value))
         else:
             s.append("    %s = %s" % (vb.oid, vb.value))
     return "\n".join(s)
示例#13
0
文件: runner.py 项目: wildone/pycopia
 def _message(self, msgtype, msg, level):
     if msgtype.find("TIME") >= 0:
         msg = timelib.localtimestamp(msg, "%b %d %H:%M:%S")
     return urwid.Columns([(20, urwid.Text(("repmsg", msgtype), "right")),
                           urwid.Text(msg)],
                          dividechars=1)
示例#14
0
 def message(self, msgtype, msg, level=1):
     if msgtype.find("TIME") >= 0:
         msg = timelib.localtimestamp(msg)
     return "%s%s: %s\n" % ("  " * (level - 1), msgtype, msg)
示例#15
0
 def test_timelib(self):
     print("Local time:")
     print(timelib.localtimestamp())
示例#16
0
文件: ANSI.py 项目: tijmengit/pycopia
 def message(self, msgtype, msg, level=1):
     if msgtype.find("TIME") >= 0:
         msg = BLUE + timelib.localtimestamp(msg) + RESET
     msgtype = self._TRANSLATE.get(msgtype, msgtype)
     return "%s%s: %s\n" % ("  " * (level - 1), msgtype, msg)
示例#17
0
 def message(self, msgtype, msg, level=1):
     if msgtype.find("TIME") >= 0:
         msg = BLUE + timelib.localtimestamp(msg) + RESET
     msgtype = self._TRANSLATE.get(msgtype, msgtype)
     return "%s %s\n" % (msgtype, msg)
示例#18
0
 def message(self, msgtype, msg, level=1):
     if msgtype.find("TIME") >= 0:
         msg = timelib.localtimestamp(msg)
     return "%s%s: %s\n" % ("  "*(level-1), msgtype, msg)
示例#19
0
 def _message(self, msgtype, msg, level):
     if msgtype.find("TIME") >= 0:
         msg = timelib.localtimestamp(msg, "%b %d %H:%M:%S")
     return urwid.Columns([(20, urwid.Text(("repmsg", msgtype), "right")), urwid.Text(msg)], dividechars=1)