def _clean_date(self, date, attribute_name, element): """Helper function that will clean a date. Returns a string in valid RFC3339 form (with seconds granularity). @param date: Date to clean. Will convert either int, float, date or datetime to RFC3339 string. @type date: date, datetime, int, float, RFC3339 String @param attribute_name: Name of attribute being cleaned. Used for potential error message. @type attribute_name: string @param element: Name of element being cleaned. Used for potential error message. @type element: string @return: string of RFC3339 date. """ if isinstance(date, float) or isinstance(date, int) \ or isinstance(date, datetime.datetime): return utils.date_to_rfc3339(date) elif isinstance(date, basestring): rfc_date = utils.rfc3339_to_date(date) if rfc_date is not False: return rfc_date raise IllegalAttributeValueError(attribute_name, date, ['float', 'datetime.datetime', 'RFC3339 String'], element)
def add_testcase(self, testcase): """Adds a test case to the document. @param testcase: The test case to be added @type testcase: L{TestCase} """ logging.debug(("Command: %s " "Time used: %s " "Size transferred: %s " "Estimated speed: %s") % ( testcase.command.get_command(), testcase.get_timer().get_string_processing_time(), testcase.f.get_size_string(), testcase.get_speed_string(), )) self.root.append(etree.Element("testcase", type=testcase.command.command_name, encryption=testcase.command.args.get_encryption(), compression=testcase.command.args.get_compression(), compression_level=testcase.command.args.get_compression_level(), num_files=str(testcase.f.get_num_files()), total_size=str(testcase.f.get_size()), fileset=str(testcase.f.get_fs_name()), transfer_time=str(testcase.timer.get_processing_time()), to=testcase.command.builder.host, date=date_to_rfc3339(testcase.timer.start_time), ))