Пример #1
0
    def compress_file(self, file_path, archive_path):
        self.import_utils()
        utils.log('Compressing "%s"...' % file_path)

        try:
            import zipfile
            z = zipfile.ZipFile(archive_path, 'w', zipfile.ZIP_DEFLATED)
            z.write(file_path, os.path.basename(file_path))
            z.close()
            utils.log('Done writing "%s".' % archive_path)
        except Exception, msg:
            utils.log('Warning: Compressing falied (%s)' % msg)
            utils.log(
                '         Trying to compress using a platform-specific tool...'
            )
            try:
                import zip_cmd
            except ImportError:
                script_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
                utils.log(
                    'Could not find \'zip_cmd\' module in the script directory (%s).'
                    % script_dir)
                raise Exception('Compressing failed!')
            else:
                if os.path.exists(archive_path):
                    os.unlink(archive_path)
                    utils.log('Removing stale "%s".' % archive_path)

                zip_cmd.main(file_path, archive_path)
                utils.log('Done compressing "%s".' % archive_path)
Пример #2
0
    def compress_file( self, file_path, archive_path ):
        self.import_utils()
        utils.log( 'Compressing "%s"...' % file_path )

        try:
            import zipfile
            z = zipfile.ZipFile( archive_path, 'w', zipfile.ZIP_DEFLATED )
            z.write( file_path, os.path.basename( file_path ) )
            z.close()
            utils.log( 'Done writing "%s".'% archive_path )
        except Exception, msg:
            utils.log( 'Warning: Compressing falied (%s)' % msg )
            utils.log( '         Trying to compress using a platform-specific tool...' )
            try:
                import zip_cmd
            except ImportError:
                script_dir = os.path.dirname( os.path.abspath( sys.argv[0] ) )
                utils.log( 'Could not find \'zip_cmd\' module in the script directory (%s).' % script_dir )
                raise Exception( 'Compressing failed!' )
            else:
                if os.path.exists( archive_path ):
                    os.unlink( archive_path )
                    utils.log( 'Removing stale "%s".' % archive_path )
                    
                zip_cmd.main( file_path, archive_path )
                utils.log( 'Done compressing "%s".' % archive_path )
Пример #3
0
def collect_logs(results_dir, runner_id, tag, platform, comment_file,
                 timestamp, user, source, run_type, **unused):

    results_file = os.path.join(results_dir, '%s.xml' % runner_id)
    results_writer = open(results_file, 'w')
    utils.log('Collecting test logs into "%s"...' % results_file)

    if not os.path.exists(timestamp):
        t = time.gmtime()
        utils.log('Warning: timestamp file "%s" does not exist' % timestamp)
        utils.log('Using current UTC time (%s)' % t)
    else:
        t = time.gmtime(os.stat(timestamp).st_mtime)

    results_xml = xml.sax.saxutils.XMLGenerator(results_writer)
    results_xml.startDocument()
    results_xml.startElement(
        'test-run', {
            'tag': tag,
            'platform': platform,
            'runner': runner_id,
            'timestamp': time.strftime('%Y-%m-%dT%H:%M:%SZ', t),
            'source': source,
            'run-type': run_type
        })

    copy_comments(results_xml, comment_file)
    collect_test_logs([results_dir], results_writer)

    results_xml.endElement("test-run")
    results_xml.endDocument()
    results_writer.close()
    utils.log('Done writing "%s".' % results_file)

    utils.log('Compressing "%s"...' % results_file)
    archive_path = os.path.join(results_dir, '%s.zip' % runner_id)

    try:
        z = zipfile.ZipFile(archive_path, 'w', zipfile.ZIP_DEFLATED)
        z.write(results_file, os.path.basename(results_file))
        z.close()
        utils.log('Done writing "%s".' % archive_path)
    except Exception, msg:
        utils.log('Warning: Compressing falied (%s)' % msg)
        utils.log(
            '         Trying to compress using a platform-specific tool...')
        try:
            import zip_cmd
        except ImportError:
            script_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
            utils.log(
                'Could not find \'zip_cmd\' module in the script directory (%s).'
                % script_dir)
            raise Exception('Compressing failed!')
        else:
            if os.path.exists(archive_path):
                os.unlink(archive_path)
                utils.log('Removing stale "%s".' % archive_path)

            zip_cmd.main(results_file, archive_path)
            utils.log('Done compressing "%s".' % archive_path)
def collect_logs( 
          locate_root_dir
        , runner_id
        , tag
        , platform
        , comment_file
        , timestamp
        , user
        , source
        , run_type
        ):
    
    results_file = os.path.join( locate_root_dir, '%s.xml' % runner_id )
    results_writer = open( results_file, 'w' )
    utils.log( 'Collecting test logs into "%s"...' % results_file )
    
    if not os.path.exists( timestamp ):
        t = time.gmtime()
        utils.log( 'Warning: timestamp file "%s" does not exist'% timestamp )
        utils.log( 'Using current UTC time (%s)' % t )
    else:
        t = time.gmtime( os.stat( timestamp ).st_mtime )
    
    results_xml = xml.sax.saxutils.XMLGenerator( results_writer )
    results_xml.startDocument()
    results_xml.startElement( 
          'test-run'
        , { 
              'tag':        tag
            , 'platform':   platform
            , 'runner':     runner_id
            , 'timestamp':  time.strftime( '%a, %d %b %Y %H:%M:%S +0000', t )     
            , 'source':     source
            , 'run-type':   run_type
            }
        )
    
    copy_comments( results_xml, comment_file )
    collect_test_logs( [ locate_root_dir ], results_writer )

    results_xml.endElement( "test-run" )
    results_xml.endDocument()
    results_writer.close()
    utils.log( 'Done writing "%s".' % results_file )

    utils.log( 'Compressing "%s"...' % results_file )
    archive_path = os.path.join( locate_root_dir,'%s.zip' % runner_id )

    try:
        z = zipfile.ZipFile( archive_path, 'w', zipfile.ZIP_DEFLATED )
        z.write( results_file, os.path.basename( results_file ) )
        z.close()
        utils.log( 'Done writing "%s".'% archive_path )
    except Exception, msg:
        utils.log( 'Warning: Compressing falied (%s)' % msg )
        utils.log( '         Trying to compress using a platform-specific tool...' )
        try: import zip_cmd
        except ImportError:
            script_dir = os.path.dirname( os.path.abspath( sys.argv[0] ) )
            utils.log( 'Could not find \'zip_cmd\' module in the script directory (%s).' % script_dir )
            raise Exception( 'Compressing failed!' )
        else:
            if os.path.exists( archive_path ):
                os.unlink( archive_path )
                utils.log( 'Removing stale "%s".' % archive_path )
                
            zip_cmd.main( results_file, archive_path )
            utils.log( 'Done compressing "%s".' % archive_path )