def start_test(odf_handler): # Create the 'results' folder if vfs.exists('results'): vfs.remove('results') vfs.make_folder('results') # Find test files print 'Searching for ODF files...' unitests = get_tests() unitests = list(unitests) nb_tests = len(unitests) print 'Number of files found: %d' % nb_tests test_number = 0 msgs_error = [] for odf_path, po_handler in unitests: # Progress bar test_number += 1 progress(test_number, nb_tests) # Call ODF handler try: odf_sources = odf_handler(odf_path) except: print 'ERROR with test %d / "%s"' % (test_number, odf_path) continue # Post-process the results odf_sources = clean_sources(odf_sources) odf_sources = list(set(odf_sources)) # Remove duplicates odf_sources.sort() # Expected results po_sources = [ u''.join(x.source) for x in po_handler.get_units() ] po_sources = clean_sources(po_sources) po_sources.sort() # Check if odf_sources == po_sources: continue # Error. Create a diff report for the current test. test_name = odf_path.split('/')[-2] filename = 'test_%d_%s.txt' % (test_number, test_name) po_path = get_uri_path(po_handler.uri) write_diff_file(test_number, filename, odf_path, po_path, odf_sources, po_sources) # Inform the user that there where failures msgs_error.append('results/%s\n' % filename) # Summurarizes the results print print 'Results:' print '--------' print ' %s Tests' % nb_tests print ' %s Errors' % len(msgs_error) print if msgs_error: stderr.write('Generated error files\n') stderr.write('---------------------\n') for msg in msgs_error: stderr.write(msg)
def update_20090705(self): """ Encode the unencoded MOV or AVI file, and add the thumb, erase the original file. """ from pprint import pprint from datetime import datetime from tempfile import mkdtemp from issue import Tchack_Issue from ikaaro.file import Video from ikaaro.exceptions import ConsistencyError from itools import vfs from itools.vfs import FileName from itools.core import guess_extension from itools.uri import get_uri_path from videoencoding import VideoEncodingToFLV from ikaaro.registry import get_resource_class for issue in self.search_resources(cls=Tchack_Issue): history = issue.get_history() for record in history.get_records(): filename = record.file comment = record.comment is_video = False if not comment and not filename: continue if filename: file = issue.get_resource(filename) is_video = isinstance(file, Video) if not is_video: continue if is_video: name = file.name filename, ext, lang = FileName.decode(name) if ext is None: mimetype = file.get_content_type() ext = guess_extension(mimetype)[1:] if(mimetype == 'video/x-msvideo' or mimetype == 'video/quicktime'): pprint("The file %s.%s will be encoded in FLV, \ replaced by, then erased." % (filename, ext)) handler_path = get_uri_path(issue.handler.uri) dirname = mkdtemp('videoencoding', 'ikaaro') tempdir = vfs.open(dirname) # Paste the file in the tempdir tmp_uri= "file:///%s/%s" % (dirname, filename) vfs.copy(file.handler.uri, tmp_uri) # Encode to 512 of width encoded = VideoEncodingToFLV(file).encode_avi_to_flv( dirname, filename, name, 512) if encoded is not None: flvfilename, flvmimetype, flvbody, flvextension = encoded['flvfile'] thumbfilename, thumbmimetype, thumbbody, thumbextension = encoded['flvthumb'] # Create the video FLV and thumbnail PNG resources video = get_resource_class(flvmimetype) thumbnail = get_resource_class(thumbmimetype) # Remove the original files if vfs.exists(file.handler.uri): vfs.remove(file.handler.uri) if vfs.exists(file.metadata.uri): vfs.remove(file.metadata.uri) video.make_resource(video, issue, name, body=flvbody, filename=flvfilename, extension=flvextension, format=flvmimetype) thumbnail.make_resource(thumbnail, issue, thumbfilename, body=thumbbody, filename=thumbfilename, extension=thumbextension, format=thumbmimetype) # Clean the temporary folder vfs.remove(dirname) pprint("====================") pprint("xxxxxxxxxxxxxxxx")
# Import from Standard Library from mimetypes import add_type def strong_escape(s): """ a way to escape string """ return "\"" + s.replace("\"", "\\\"") + "\"" FELLOWSHIP_PREFIX = 'http://testsuite.opendocumentfellowship.com/testcases/' if __name__ == '__main__': # Open a log file for failed files if not exists('error_logs'): make_file('error_logs') errors = open('error_logs', 'rw') # does 'a' flag works ?? errors.write(errors.read()) errors.write("# -- Error log --\n") errors.write("# Please update those file manually\n") # Register ConfigFile to .conf ConfigFile.class_mimetypes = ['text/x-setup_conf'] add_type('text/x-setup_conf', '.conf') register_handler_class(ConfigFile) db = Database().get_handler('documents') count = 0 # For each test case