Beispiel #1
0
    def save_logo(self, request_files):
        ''' save logo file
        request_files = self.request.files['logo']
        '''

        if not makesure_path_exist( self.logodir ):
            return _('create appliance logo dir "%s" failed') % self.logodir

        max_size = settings.APPLIANCE_LOGO_MAXSIZE

        for f in request_files:

            if len(f['body']) > max_size:
                return self.trans(_('Picture must smaller than %s !')) % human_size(max_size)

            tf = tempfile.NamedTemporaryFile()
            tf.write(f['body'])
            tf.seek(0)

            try:
                img = Image.open(tf.name)
            except Exception, emsg:
                return _('Open %(filename)s failed: %(emsg)s , is it a picture ?') % {
                    'filename': f.get('filename'), 'emsg': emsg }

            try:
                # can convert image type
                img.save(self.p_logo_raw)

            except Exception, emsg:
                return _('Save %(filename)s failed: %(emsg)s') % {
                    'filename': f.get('filename'), 'emsg': emsg }
Beispiel #2
0
    def save_logo(self, request_files):
        ''' save logo file
        request_files = self.request.files['logo']
        '''

        logodir = self.logodir

        if not makesure_path_exist( logodir ):
            return _('Create logodir "%s" failed') % logodir

        max_size = settings.APPLIANCE_LOGO_MAXSIZE

        for f in request_files:

            if len(f['body']) > max_size:
                return _('Logo must smaller than %s !') % human_size(max_size)

            save_raw_file = os.path.join(logodir, 'r.png')
            save_raw_file = os.path.join(logodir, 'thumb.png')

            tf = tempfile.NamedTemporaryFile()
            tf.write(f['body'])
            tf.seek(0)

            try:
                img = Image.open(tf.name)

                # can convert image type
                img.save( save_raw_file )

                img.thumbnail((120, 120), Image.ANTIALIAS)
                img.save( save_thumb_file )

            except Exception, emsg:
                e = _('Save %(filename)s failed: %(emsg)s') % {
                    'filename': f.get('filename'), 'emsg': emsg }
                logging.error( e )
                return e

            tf.close()
Beispiel #3
0
    def save_logo(self, request_files):
        ''' save logo file
        request_files = self.request.files['logo']
        '''

        if not makesure_path_exist(self.logodir):
            return _('create appliance logo dir "%s" failed') % self.logodir

        max_size = settings.APPLIANCE_LOGO_MAXSIZE

        for f in request_files:

            if len(f['body']) > max_size:
                return self.trans(
                    _('Picture must smaller than %s !')) % human_size(max_size)

            tf = tempfile.NamedTemporaryFile()
            tf.write(f['body'])
            tf.seek(0)

            try:
                img = Image.open(tf.name)
            except Exception, emsg:
                return _(
                    'Open %(filename)s failed: %(emsg)s , is it a picture ?'
                ) % {
                    'filename': f.get('filename'),
                    'emsg': emsg
                }

            try:
                # can convert image type
                img.save(self.p_logo_raw)

            except Exception, emsg:
                return _('Save %(filename)s failed: %(emsg)s') % {
                    'filename': f.get('filename'),
                    'emsg': emsg
                }
Beispiel #4
0
    def save_file(self, fileobj):

        upload_dir = get_runtime_data('site.upload.base_dir',
                                      '/opt/LuoYun/data/')

        path = '%s/appliance/%s/screenshot/' % (upload_dir.rstrip('/'),
                                                self.appliance_id)

        if not makesure_path_exist(path):
            return _('makesure_path_exist failed.')

        sha1_obj = sha1()
        sha1_obj.update(fileobj['body'])

        checksum = sha1_obj.hexdigest()
        filename = fileobj['filename']

        savename = '%s-%s' % (checksum, filename)
        fullname = os.path.join(path, savename)

        f = open(fullname, 'wb')
        f.write(fileobj['body'])
        f.close()

        try:
            thumbname = '%s-thumb.png' % checksum
            fullthumb = os.path.join(path, thumbname)

            img = Image.open(fullname)

            img.thumbnail((800, 500), Image.ANTIALIAS)
            img.save(fullthumb)
        except:
            pass

        self.filename = filename
        self.checksum = checksum
        self.size = os.path.getsize(fullname)
Beispiel #5
0
    def save_file(self, fileobj):

        upload_dir = get_runtime_data('site.upload.base_dir', '/opt/LuoYun/data/')

        path = '%s/appliance/%s/screenshot/' % (
            upload_dir.rstrip('/'), self.appliance_id )

        if not makesure_path_exist( path ):
            return _('makesure_path_exist failed.')

        sha1_obj = sha1()
        sha1_obj.update( fileobj['body'] )

        checksum = sha1_obj.hexdigest()
        filename = fileobj['filename']

        savename = '%s-%s' % (checksum, filename)
        fullname = os.path.join(path, savename)

        f = open(fullname, 'wb')
        f.write( fileobj['body'] )
        f.close()

        try:
            thumbname = '%s-thumb.png' % checksum
            fullthumb = os.path.join(path, thumbname)

            img = Image.open(fullname)

            img.thumbnail((800, 500), Image.ANTIALIAS)
            img.save( fullthumb )
        except:
            pass

        self.filename = filename
        self.checksum = checksum
        self.size     = os.path.getsize( fullname )