Python Bucket.delete_object方法代码示例

本文整理汇总了Python中sae.storage.Bucket.delete_object方法的典型用法代码示例。如果您正苦于以下问题:Python Bucket.delete_object方法的具体用法?Python Bucket.delete_object怎么用?Python Bucket.delete_object使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sae.storage.Bucket的用法示例。


Python Bucket.delete_object方法代码示例

在下文中一共展示了Bucket.delete_object方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: initialize

# 需要导入模块: from sae.storage import Bucket [as 别名]
# 或者: from sae.storage.Bucket import delete_object [as 别名]
def initialize(*args):
    global trie, FREQ, total, min_freq, initialized
    if len(args)==0:
        dictionary = DICTIONARY
    else:
        dictionary = args[0]
    with DICT_LOCK:
        if initialized:
            return
        if trie:
            del trie
            trie = None

        t1 = time.time()

        cache_file = 'jieba.cache'
        default_dict = dictionary
        default_bucket = getattr(settings, 'STORAGE_BUCKET_NAME')
        bucket = Bucket(default_bucket)

        cache_file_content = bucket.get_object_contents(dictionary)
        dict_stamp = bucket.stat_object(default_dict)['timestamp']

        load_from_cache_fail = True
        try:
            cache_stamp = bucket.stat_object(cache_file)['timestamp']
        except:
            cache_exists = False
        else:
            if cache_stamp > dict_stamp:
                logger.debug("loading model from cache %s" % cache_file)
                try:
                    cache_content = bucket.get_object_contents(cache_file)
                    trie,FREQ,total,min_freq = marshal.loads(cache_content)
                    load_from_cache_fail = False
                except:
                    load_from_cache_fail = True

        if load_from_cache_fail:
            trie,FREQ,total = gen_trie(cache_file_content)
            FREQ = dict([(k,log(float(v)/total)) for k,v in FREQ.iteritems()]) #normalize
            min_freq = min(FREQ.itervalues())
            logger.debug("dumping model to file cache %s" % cache_file)
            try:
                tmp_suffix = "."+str(random.random())
                cache_file = 'dict' + tmp_suffix + '.cache'
                cache_file = os.path.join(tempfile.gettempdir(), cache_file)
                with open(cache_file,'wb') as temp_cache_file:
                    marshal.dump((trie,FREQ,total,min_freq),temp_cache_file)
                if cache_exists:
                    bucket.delete_object('jieba.cache')
                bucket.put_object('jieba.cache', open(cache_file, 'rb'))
            except:
                logger.error("dump cache file failed.")
                logger.exception("")

        initialized = True

        logger.debug("loading model cost %s seconds." % (time.time() - t1))
        logger.debug("Trie has been built succesfully.")
开发者ID:xkong,项目名称:saejieba,代码行数:62,代码来源:__init__.py

示例2: exportImport

# 需要导入模块: from sae.storage import Bucket [as 别名]
# 或者: from sae.storage.Bucket import delete_object [as 别名]
def exportImport(filename,tp):
	result={}
	# for client debug
	if settings.DEBUG:
		data = xlrd.open_workbook(settings.MEDIA_ROOT+filename)
	# for sae
	else:
		bucket = Bucket('resources')
		obj = bucket.get_object_contents(filename)
		data=xlrd.open_workbook(file_contents=obj)
	table = data.sheets()[0]
	# check the column
	ncols=table.ncols
	nrows=table.nrows
	# for student
	if (tp==0 and (not ncols==11)) or (tp==1 and (not ncols==9)):
		result['status']='failured'
		result['tip']='excel列数不对'
	elif nrows<2:
		result['status']='failured'
		result['tip']='至少需要一条记录'
	else:
		statistic=executeImport(table,tp)
		result['status']='success'
		result['tip']='导入成功,共 %d 人,成功导入 %d 人,跳过 %d 人' \
		% (statistic['sum'],statistic['count'],statistic['existed'])
		result['usernames']=statistic['usernames']
	# delete the uploaded temp file
	#  for client debug
	if settings.DEBUG:
		os.remove(settings.MEDIA_ROOT+filename)
	#  for sae
	else:
		bucket.delete_object(filename)
	return result
开发者ID:hityangzhen,项目名称:Olearning,代码行数:37,代码来源:MyExcel.py

示例3: get

# 需要导入模块: from sae.storage import Bucket [as 别名]
# 或者: from sae.storage.Bucket import delete_object [as 别名]
    def get(self, request, *args, **kwargs):
        from sae.deferredjob import MySQLExport, DeferredJob
        from sae.storage import Bucket as SBucket
        import time
        import datetime

        export_bucket = 'xkongbackup'
        bucket = SBucket(export_bucket)

        now = time.strftime('%Y_%m_%d_%H_%M_%S')
        filename = 'app_ninan_%s.zip' % now

        deferred_job = DeferredJob()
        job = MySQLExport(export_bucket, filename, 'note_note',
                          'backends/backupsuccess/')
        deferred_job.add(job)

        resp = {'touch': filename}

        #  Delete all files in this bucket created a month ago
        a_month_ago = datetime.datetime.now() - datetime.timedelta(days=30)

        for object_ in bucket.list():
            last_modified = object_['last_modified']
            if last_modified:
                mtime = datetime.datetime.strptime(last_modified,
                                                   '%Y-%m-%dT%H:%M:%S.%f')
            else:
                continue

            if object_['content_type'] is not None and mtime < a_month_ago:
                bucket.delete_object(object_['name'])

        return self.render_to_response(resp)
开发者ID:xkong,项目名称:ninantrash,代码行数:36,代码来源:views.py

示例4: delPic

# 需要导入模块: from sae.storage import Bucket [as 别名]
# 或者: from sae.storage.Bucket import delete_object [as 别名]
def delPic(request,id):
	if isUser(request):
		if request.method == "POST":
			try:
				pic_id = request.POST.get('del_pic_id','')
				pic = Pictures.objects.get(id=pic_id)
			except Exception, e:
				raise e
			if 'SERVER_SOFTWARE' in os.environ:
				try:
					from sae.storage import Bucket
					bucket = Bucket('media')
					pic_path = str(id) + '/' + pic.pic_src[pic.pic_src.rindex("/")+1:]
					bucket.delete_object(pic_path)
					pic.delete()
				except Exception, e:
					raise e
			else:
				try:
					os.remove(pic.pic_src[1:])
					# print pic.pic_src[1:pic.pic_src.rindex("/")+1]
					if not os.listdir(pic.pic_src[1:pic.pic_src.rindex("/")+1]):
						os.rmdir(pic.pic_src[1:pic.pic_src.rindex("/")+1])
					pic.delete()
				except Exception, e:
					raise e
开发者ID:wtq2255,项目名称:uuweb,代码行数:28,代码来源:views.py

示例5: delete_img

# 需要导入模块: from sae.storage import Bucket [as 别名]
# 或者: from sae.storage.Bucket import delete_object [as 别名]
def delete_img(con, pid, title):
    if 'SERVER_SOFTWARE' in os.environ:
        p = get_product_detail(con, title)
        bucket = Bucket('domain1')
        for url in p.img_list:
            img_name = url.split("/")[-1]
            bucket.delete_object(img_name)
            print "delete bucket object", img_name
    sql = "delete from {0} where pid ={1}".format(IMG_TABLE, pid)
    execute_non_query(con, sql)
开发者ID:myang321,项目名称:EIA,代码行数:12,代码来源:database_setup.py

示例6: edit0

# 需要导入模块: from sae.storage import Bucket [as 别名]
# 或者: from sae.storage.Bucket import delete_object [as 别名]
def edit0(request):
    pname = pcomment = pmood = newname = 0
    from sae.storage import Bucket
    bucket = Bucket('abc')
    if request.POST:
        if request.POST.has_key('correct'):
            if request.GET.has_key('atitle'):
                pname = request.GET['atitle']
                pn = t.objects.all()
                if (len(pn)!= 0):
                    pname = pn[0].title
                    for i in pn:
                        i.delete()
                we = imagess.objects.filter(title = pname)
                if (len(we)!= 0):
                    img = bucket.get_object_contents('stati/'+pname)
                    im = Image.open(StringIO.StringIO(img))
                    imgout = StringIO.StringIO()
                    im.save(imgout,"jpeg")
                    img_data = imgout.getvalue()
                    we[0].title = request.POST['cname']+'.jpg'
                    newname = we[0].title
                    if (newname != pname):
                        ne = t(title = newname)
                        ne.save()
                        bucket.put_object('stati/'+newname, img_data)
                        im = Image.open(StringIO.StringIO(img))
                        out = im.resize((128, 128))
                        imgout = StringIO.StringIO()
                        out.save(imgout,"jpeg")
                        img_data = imgout.getvalue()
                        bucket.put_object('manage/'+newname, img_data)
                        bucket.delete_object('manage/'+pname)
                        bucket.delete_object('stati/'+pname)
                    pname = newname
                    we[0].comment = request.POST['ccomment']
                    we[0].mood = request.POST['cmood']
                    we[0].save()
            pname = request.POST['cname']+'.jpg'
            pcomment = request.POST['ccomment']
            pmood = request.POST['cmood']
    elif request.GET.has_key('atitle'):
        if (pname == 0):
            pname = request.GET['atitle']
            p = t(title = pname)
            p.save()
            we = imagess.objects.filter(title = pname)
            if (len(we)!= 0):
                pcomment = we[0].comment
                pmood = we[0].mood
    if (pname!=0):
        pname = pname[:-4]
        
    return render_to_response('editt.html',{'pname':pname,'newname':newname, \
    'pmood': pmood, 'pcomment':pcomment},context_instance=RequestContext(request)) 
开发者ID:450534021,项目名称:gxhlchfzxy,代码行数:57,代码来源:edit.py

示例7: initialize

# 需要导入模块: from sae.storage import Bucket [as 别名]
# 或者: from sae.storage.Bucket import delete_object [as 别名]
def initialize(dictionary=None):
    global pfdict, FREQ, total, min_freq, initialized, DICTIONARY, DICT_LOCK
    if not dictionary:
        dictionary = DICTIONARY
    with DICT_LOCK:
        if initialized:
            return

        logger.debug("Building prefix dict from %s ..." % X_CACHE_FILE)
        t1 = time.time()
        cache_file = X_CACHE_FILE
        if settings.DEBUG:
            bucket = Bucket('xkong1946')
        else:
            bucket = Bucket()

        dict_stamp = bucket.stat_object(dictionary)['timestamp']
        cache_stamp = bucket.stat_object(cache_file)['timestamp']

        load_from_cache_fail = True
        if cache_stamp > dict_stamp:
            logger.debug("Loading model from cache %s" % cache_file)
            try:
                cf = bucket.get_object_contents(cache_file)
                pfdict, FREQ, total = marshal.loads(cf)
                # prevent conflict with old version
                load_from_cache_fail = not isinstance(pfdict, set)
            except Exception, e:
                print e
                load_from_cache_fail = True

        if load_from_cache_fail:
            dict_file_content = bucket.get_object_contents(dictionary)
            pfdict, FREQ, total = gen_pfdict(dict_file_content)
            logger.debug("Dumping model to file cache %s" % cache_file)
            try:
                import StringIO
                fd = StringIO.StringIO()
                fd.write(marshal.dumps((pfdict, FREQ, total)))
                if bucket.stat_object(X_CACHE_FILE):
                    bucket.delete_object(X_CACHE_FILE)
                bucket.put_object(X_CACHE_FILE, fd.getvalue())

            except Exception:
                logger.exception("Dump cache file failed.")

        initialized = True

        logger.debug("Loading model cost %s seconds." % (time.time() - t1))
        logger.debug("Prefix dict has been built succesfully.")
开发者ID:xkong,项目名称:saesearch,代码行数:52,代码来源:__init__.py

示例8: delete_file

# 需要导入模块: from sae.storage import Bucket [as 别名]
# 或者: from sae.storage.Bucket import delete_object [as 别名]
def delete_file(file_path):
    from urlparse import urlsplit
    from sae.storage import Bucket

    res = urlsplit(file_path)

    hostname, path = res.hostname, res.path

    bucket_name = hostname.split(".", 1)[0].split("-")[-1]

    _, object_name = path.split("/", 1)

    bucket = Bucket(bucket_name)
    bucket.delete_object(object_name)
开发者ID:13917547121,项目名称:me,代码行数:16,代码来源:tools_sae.py

示例9: MakeBackup

# 需要导入模块: from sae.storage import Bucket [as 别名]
# 或者: from sae.storage.Bucket import delete_object [as 别名]
def MakeBackup():

    """
    定时备份文件任务
    """
    dbchgcounter = kv.get("kvdbchg")
    if dbchgcounter == None:
        dbchgcounter = 0
    if dbchgcounter == 0:
        return u"数据未改变"
    dbchgcounter = 0
    kv.set("kvdbchg",dbchgcounter)
    
    
    bucket = Bucket('backup')
    tm = datetime.now()
    # 删除过期文件
    dellist = []
    fdlist = []
    fwlist = []
    for finf in bucket.list():
        last_modified = str(finf[u'last_modified'])
        last_modified = last_modified[:last_modified.index(".")]#2013-05-22T05:09:32.259140 -> 2013-05-22T05:09:32
        filetime = datetime.strptime(last_modified,"%Y-%m-%dT%H:%M:%S")
        fname = str(finf[u"name"])
        if "d.zip.data" in fname:
            fdlist.append((fname,tm-filetime))
        else:
            fwlist.append((fname,tm-filetime))
            
    if len(fdlist) > 3:
        sorted(fdlist,key = lambda x:x[1])
        dellist = fdlist[3:]
    if len(fwlist) > 4:
        sorted(fwlist,key = lambda x:x[1])
        dellist += fdlist[4:]
    
    for fname in dellist:
        bucket.delete_object(fname[0])
    
    #备份新文件
    filename = tm.strftime(u"%Y-%m-%d_%H_%M_%S")
    if tm.weekday() == 5: #周六
        filename += "w.zip.data"
    else:
        filename += "d.zip.data"
    WriteZipFile(filename)
    
    return u"已备份"
开发者ID:zhangningningcn,项目名称:weixinsendmail,代码行数:51,代码来源:kvbackup.py

示例10: __init__

# 需要导入模块: from sae.storage import Bucket [as 别名]
# 或者: from sae.storage.Bucket import delete_object [as 别名]
class SaeStorageSaver:
    def __init__(self, key):
        self.bucket = Bucket(key)

    def StoreTxtFile(self, path, content):
        self.bucket.put_object(path, content)

    def StoreBinFile(self, path, content):
        self.bucket.put_object(path, content)

    def GetObjectByPath(self, path):
        return self.bucket.get_object_contents(path)

    def GetItemUnder(self, path):
        return [x for x in self.bucket.list(path)]

    def GetBackupList(self):
        return self.GetItemUnder(g_backup_path)

    def DeleteObject(self, obj):
        self.bucket.delete_object(obj)
开发者ID:kmalloc,项目名称:CnblogsGrabber,代码行数:23,代码来源:sae_storage_saver.py

示例11: beauti

# 需要导入模块: from sae.storage import Bucket [as 别名]
# 或者: from sae.storage.Bucket import delete_object [as 别名]
def beauti(request):
    r = g = b = s = 0
    from sae.storage import Bucket

    bucket = Bucket("abc")
    aa = bucket.list(path="meihua/")
    for ii in aa:
        bucket.delete_object(ii.name)
    if request.GET:
        if request.GET.has_key("btitle"):
            b = request.GET["btitle"]
        if request.GET.has_key("ptitle"):
            g = request.GET["ptitle"]
    if request.POST:
        if request.POST.has_key("lvjing"):
            if request.FILES or request.GET.has_key("btitle"):
                if request.FILES:
                    f = request.FILES["file"]
                    bucket.put_object("lvjing/" + f.name, f)
                    img = bucket.get_object_contents("lvjing/" + f.name)
                    s = "lv" + str(f)
                elif request.GET.has_key("btitle"):
                    name = request.GET["btitle"]
                    img = bucket.get_object_contents("stati/" + name)
                    s = "lv" + name
                im = Image.open(StringIO.StringIO(img))
                im.getdata()
                out = im.split()
                imgout = StringIO.StringIO()
                out[0].save(imgout, "jpeg")
                img_data = imgout.getvalue()
                bucket.put_object("meihua/" + s, img_data)
        if request.POST.has_key("suotu"):
            if request.FILES or request.GET.has_key("btitle"):
                if request.FILES:
                    f = request.FILES["file"]
                    bucket.put_object("suotu/" + f.name, f)
                    img = bucket.get_object_contents("suotu/" + f.name)
                    s = "su" + str(f)
                elif request.GET.has_key("btitle"):
                    name = request.GET["btitle"]
                    img = bucket.get_object_contents("stati/" + name)
                    s = "su" + name
                im = Image.open(StringIO.StringIO(img))
                out = im.resize((128, 128))
                imgout = StringIO.StringIO()
                out.save(imgout, "jpeg")
                img_data = imgout.getvalue()
                bucket.put_object("meihua/" + s, img_data)

        if request.POST.has_key("xuanzhuan"):
            if request.FILES or request.GET.has_key("btitle"):
                if request.POST["dushu"] != "":
                    dushu = request.POST["dushu"]
                    i = string.atoi(dushu)
                else:
                    i = 0
                if request.FILES:
                    f = request.FILES["file"]
                    bucket.put_object("xuanzhuan/" + f.name, f)
                    img = bucket.get_object_contents("xuanzhuan/" + f.name)
                    s = "xu" + str(f)
                else:
                    name = request.GET["btitle"]
                    img = bucket.get_object_contents("stati/" + name)
                    s = "xu" + name

                im = Image.open(StringIO.StringIO(img))
                out = im.rotate(i)
                imgout = StringIO.StringIO()
                out.save(imgout, "jpeg")
                img_data = imgout.getvalue()
                bucket.put_object("meihua/" + s, img_data)

        if request.POST.has_key("huidu1"):
            if request.FILES or request.GET.has_key("btitle"):
                if request.FILES:
                    f = request.FILES["file"]
                    bucket.put_object("huidu1/" + f.name, f)
                    img = bucket.get_object_contents("huidu1/" + f.name)
                    s = "h1" + str(f)
                else:
                    name = request.GET["btitle"]
                    img = bucket.get_object_contents("stati/" + name)
                    s = "h1" + name
                im = Image.open(StringIO.StringIO(img))
                im.getdata()
                out = im.split()
                if len(out) > 0:
                    imgout = StringIO.StringIO()
                    out[0].save(imgout, "jpeg")
                else:
                    im.save(imgout, "jpeg")
                img_data = imgout.getvalue()
                bucket.put_object("meihua/" + s, img_data)

        if request.POST.has_key("huidu2"):
            if request.FILES or request.GET.has_key("btitle"):
                if request.FILES:
                    f = request.FILES["file"]
#.........这里部分代码省略.........
开发者ID:450534021,项目名称:gxhlchfzxy,代码行数:103,代码来源:beautify.py

示例12: saveChange

# 需要导入模块: from sae.storage import Bucket [as 别名]
# 或者: from sae.storage.Bucket import delete_object [as 别名]
def saveChange(request, ID):
    userid = request.session.get('userid', '')
    if userid == '':
        return HttpResponseRedirect('/index')
    title = request.POST['title']
    text = request.POST['text']
    textNoHtml = re.sub('<[^>]*?>','',text)

    if len(textNoHtml) < 120:
        shortContent = textNoHtml + '......'
    else:
        shortContent = textNoHtml[0:120] + '......'
    #保存更新之后的文章标题,内容和概述。
    passageObj = Passage.objects.get(id = int(ID))
    passageObj.Title = title
    passageObj.ShortContent = shortContent
    passageObj.LongContent = text
    passageObj.save()

    #picSrcLs获取文中所有图片的路径
    picSrcLs = re.findall('<img src="(.*?)">',text)
    #picNameLs获取文中所有图片的文件名
    picNameLs = []
    for pss in picSrcLs:
        if 'pictures'in pss:
            picNameLs.append(pss[49:])
        else:
            continue
    #picSavedObjLs存储所有已保存的图片数据。
    picSavedObjLs = Picture.objects.filter(PassageID = passageObj)
    #picStayLs用于保存仍然存在的图片名称。
    picStayLs = []
    #以下循环用于判断:图片表中有没有图片在编辑中被删除。
    for picObj in picSavedObjLs:
        if picObj.OriginalImageName in picNameLs:
            picStayLs.append(picObj.OriginalImageName)
            continue
        else:
            bucket = Bucket('media')
            bucket.delete_object(picObj.OriginalImagePath.name)
            bucket.delete_object(picObj.CompressedImagePath.name)
            #os.remove(os.path.join(settings.MEDIA_ROOT, picObj.OriginalImagePath.name))
            #os.remove(os.path.join(settings.MEDIA_ROOT, picObj.CompressedImagePath.name))
            picObj.delete()
    #删除picNameLs已存在Picture表中的图片名称,剩下的图片都在PictureCache图片缓存表中。
    for pic in picStayLs:
        picNameLs.remove(pic)

    for pn in picNameLs:
        cpobj = CachePicture.objects.get(ImageName = pn)
        #print 'sss',cpobj.ImagePath.name
        bucket = Bucket('media')
        im = Image.open(cStringIO.StringIO(bucket.get_object_contents(cpobj.ImagePath.name)))
        #im = Image.open(os.path.join(settings.MEDIA_ROOT, cpobj.ImagePath.name))
        w, h = im.size
        if w > h:
            im.thumbnail((66, (66*h)//w))
        else:
            im.thumbnail(((w*74)//h, 74))
        #savepath = os.path.join(settings.MEDIA_ROOT, 'compressedpictures' ,'thumnail'+cpobj.ImageName)
        savepath = os.path.join('compressedpictures' ,'thumnail'+cpobj.ImageName)
        fm = cpobj.ImageName.split('.')[1]
        if fm.lower() == 'jpg':
            fm = 'jpeg'
        buf = cStringIO.StringIO()
        im.save(buf, fm)
        img_data = buf.getvalue()
        bucket.put_object(savepath, img_data)
        #im.save(savepath, fm)
        picObj = Picture()
        picObj.PassageID = passageObj
        picObj.OriginalImageName = pn
        picObj.OriginalImagePath = cpobj.ImagePath
        picObj.CompressedImageName = 'thumnail'+cpobj.ImageName
        picObj.CompressedImagePath.name = os.path.join('compressedpictures' ,'thumnail'+cpobj.ImageName)
        picObj.save()
        cpobj.delete()
        buf.close()
    #删除缓存表中的数据以及对应的图片。
    username = User.objects.get(id = userid).UserName
    deleteCachePicLs = CachePicture.objects.filter(UserName = username)
    if len(deleteCachePicLs) > 0:
        bucket = Bucket('media')
        for pic in deleteCachePicLs:
            #os.remove(os.path.join(settings.MEDIA_ROOT, pic.ImagePath.name))
            bucket.delete_object(pic.ImagePath.name)
            pic.delete()
    return HttpResponseRedirect('/passage/'+ID)
开发者ID:ChanSeaThink,项目名称:chanalpha,代码行数:90,代码来源:views.py

示例13: delFile

# 需要导入模块: from sae.storage import Bucket [as 别名]
# 或者: from sae.storage.Bucket import delete_object [as 别名]
def delFile(filename):
    bucket = Bucket('images')
    bucket.delete_object(filename)
    return True
开发者ID:ycx211314,项目名称:ienglish,代码行数:6,代码来源:storagetool.py

示例14: manage

# 需要导入模块: from sae.storage import Bucket [as 别名]
# 或者: from sae.storage.Bucket import delete_object [as 别名]
def manage(request):
    from sae.storage import Bucket
    bucket = Bucket('abc')
    sa = t.objects.all()
    for x in sa:
        x.delete()
    if request.GET:     #delete
        if request.GET.has_key('ctitle'):
            name = request.GET["ctitle"]
            bucket.delete_object('manage/'+name)
            bucket.delete_object('stati/'+name)
            ta = imagess.objects.filter(title = name)
            if (len(ta)!= 0):
                for i in ta:
                    i.delete()
        if request.GET.has_key('stitle'):  #save beautify
            name = request.GET["stitle"]
            if (name != '0'):
                new_name = name[2:]
                new_comment = '..'
                new_mood = '..'
                ta = imagess.objects.filter(title = new_name)
                if (len(ta)!= 0):
                    new_comment = ta[0].comment
                    new_mood = ta[0].mood
                    new_lat = ta[0].lat
                    new_lon = ta[0].lon
                new_photo = imagess(picture = 0, comment = new_comment, mood = new_mood, \
                title = name, lat = new_lat, lon = new_lon)
                new_photo.save()
                obj = bucket.get_object_contents('meihua/'+name)
                im = Image.open(StringIO.StringIO(obj))
                imgout = StringIO.StringIO()
                im.save(imgout,"jpeg")
                img_data = imgout.getvalue()
                bucket.put_object('stati/'+name, img_data)
                im = Image.open(StringIO.StringIO(obj))
                out = im.resize((128, 128))
                imgout = StringIO.StringIO()
                out.save(imgout,"jpeg")
                img_data = imgout.getvalue()
                bucket.put_object('manage/'+name, img_data)
       #陈列部分           
    A = []
    a = bucket.list(path='manage/')
    for i in a:
        dic = []
        s = i.name.split('/')[-1]
        dic.append(s)
        dic.append(i.last_modified)
        ta = imagess.objects.filter(title = s)
        if (len(ta)!= 0):
            dic.append(ta[0].mood)
            dic.append(ta[0].comment)
        A.append(dic)

    if request.GET:
        if request.GET.has_key('search'):#search
            if request.GET['writesearch'] != '':
                A=[]
                wcomment = request.GET['writesearch']
                result = imagess.objects.filter(comment = wcomment)
                for i in range(0, len(result)):
                    a = bucket.stat_object('manage/'+result[i].title)
                    dic = []
                    dic.append(result[i].title)
                    dic.append(a.last_modified)
                    dic.append(result[i].mood)
                    dic.append(result[i].comment)
                    A.append(dic)
    
    return render_to_response('manage.html',{'A':A },\
                              context_instance=RequestContext(request)) 
开发者ID:450534021,项目名称:gxhlchfzxy,代码行数:75,代码来源:manage.py

示例15: saveWritting

# 需要导入模块: from sae.storage import Bucket [as 别名]
# 或者: from sae.storage.Bucket import delete_object [as 别名]
def saveWritting(request):
    #blog 应用中最重要的试图函数。
    #包括以下主要功能:1,保存博文;2,生成缩略图;3,把缓存表的图片信息移到源图表,然后清空缓存表。
    userid = request.session.get('userid', '')
    if userid == '':
        return HttpResponseRedirect('/index')
    title = request.POST['title']
    text = request.POST['text']
    textNoHtml = re.sub('<[^>]*?>','',text)
    #print len(textNoHtml)
    #print text
    #print textNoHtml
    if len(textNoHtml) < 120:
        shortContent = textNoHtml + '......'
    else:
        shortContent = textNoHtml[0:120] + '......'
    nt = datetime.now()
    #以下是保存博文数据到数据表中。
    passageObj = Passage()
    writerObj = User.objects.get(id = userid)
    passageObj.UserID = writerObj
    passageObj.Title = title
    passageObj.Time = nt
    passageObj.ShortContent = shortContent
    passageObj.LongContent = text
    passageObj.save()
    #以下是把所有缓存表的图片去处移到源图表,并生成压缩图。
    picSrcLs = re.findall('<img src="(.*?)">',text)
    picNameLs = []
    for pss in picSrcLs:
        if 'pictures'in pss:
            picNameLs.append(pss[49:])
        else:
            continue
    #此变量用于保存文章的ID
    ID = 0
    passageObj = Passage.objects.get(UserID = writerObj, Time = nt)
    ID = passageObj.id
    for pn in picNameLs:
        cpobj = CachePicture.objects.get(ImageName = pn)
        #print 'sss',cpobj.ImagePath.name
        bucket = Bucket('media')
        im = Image.open(cStringIO.StringIO(bucket.get_object_contents(cpobj.ImagePath.name)))
        #im = Image.open(os.path.join(settings.MEDIA_ROOT, cpobj.ImagePath.name))
        w, h = im.size
        if w > h:
            im.thumbnail((66, (66*h)//w))
        else:
            im.thumbnail(((w*74)//h, 74))
        #savepath = os.path.join(settings.MEDIA_ROOT, 'compressedpictures' ,'thumnail'+cpobj.ImageName)
        savepath = os.path.join('compressedpictures' ,'thumnail'+cpobj.ImageName)
        fm = cpobj.ImageName.split('.')[1]
        if fm.lower() == 'jpg':
            fm = 'jpeg'
        buf = cStringIO.StringIO()
        im.save(buf, fm)
        img_data = buf.getvalue()
        bucket.put_object(savepath, img_data)
        #im.save(savepath, fm)
        picObj = Picture()
        picObj.PassageID = passageObj
        picObj.OriginalImageName = pn
        picObj.OriginalImagePath = cpobj.ImagePath
        picObj.CompressedImageName = 'thumnail'+cpobj.ImageName
        picObj.CompressedImagePath.name = os.path.join('compressedpictures' ,'thumnail'+cpobj.ImageName)
        picObj.save()
        cpobj.delete()
        buf.close()
    #删除缓存表中的数据以及对应的图片。
    deleteCachePicLs = CachePicture.objects.filter(UserName = writerObj.UserName)
    if len(deleteCachePicLs) > 0:
    	bucket = Bucket('media')
        for pic in deleteCachePicLs:
            #os.remove(os.path.join(settings.MEDIA_ROOT, pic.ImagePath.name))
            bucket.delete_object(pic.ImagePath.name)
            pic.delete()
    #以下到return代码前的代码用于文章数量增加1
    dataCountObjLs = DataCount.objects.all()
    if len(dataCountObjLs) == 0:
        dataCountObj = DataCount()
        dataCountObj.PassageCount = 1
        dataCountObj.save()
    else:
        dataCountObj = dataCountObjLs[0]
        dataCountObj.PassageCount += 1
        print dataCountObj.PassageCount
        dataCountObj.save()
    #return HttpResponseRedirect('/index')
    return HttpResponseRedirect('/passage/'+ str(ID))
开发者ID:ChanSeaThink,项目名称:chanalpha,代码行数:91,代码来源:views.py

本文标签属性:

示例:示例志愿表

代码:代码编程

Python:python菜鸟教程

上一篇:C++ cublas_uplo_const函数代码示例
下一篇:C++ Allele::isMissing方法代码示例

为您推荐