• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python models.File类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中models.File的典型用法代码示例。如果您正苦于以下问题:Python File类的具体用法?Python File怎么用?Python File使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: expose_path

def expose_path(group):
    form_keys = ["path", "size", "hash", "hash_function", "modified", "signature"]
    for key in form_keys:
        if key not in request.form:
            raise ValueError("Missing form value %s" % key)
    path = request.form["path"]
    signature = request.form["signature"]

    # Don't include signature
    d = {k: request.form[k] for k in form_keys[:-1]}

    if not security.check_json_sig(d, app.config["BASEJUMP_KEY"], signature):
        raise ValueError("Invalid signature provided.")

    key = security.sign_path(path, app.config["SECRET_KEY"])

    meta = request.form
    with db_session() as s:
        f = s.query(File).filter(File.key == key).all()
        if f:
            raise ValueError("This path is already exposed.")

        last_modified = datetime.fromtimestamp(int(meta["modified"]))
        f = File(path=path, group=group, key=key, size=meta["size"], checksum=meta["hash"], checksumType=meta["hash_function"], modified=last_modified)
        s.add(f)
        s.commit()
        url_path = f.queue_url()
    url = request.url_root + url_path
    return jsonify({"queue_url": url})
开发者ID:chaosphere2112,项目名称:basejump,代码行数:29,代码来源:app.py


示例2: fstream

def fstream(name):
    fstream_count = File.objects(name=name).count()
    if fstream_count:
        fstream = File.objects(name=name).first()
        return fstream.data.read()
    else:
        return ''
开发者ID:ajduncan,项目名称:kegger,代码行数:7,代码来源:app.py


示例3: file_upload

def file_upload(user):
    
    _file = request.files['file']
    cont = ''
    for d in _file.stream:
        cont += d
    from binascii import hexlify
    cont = hexlify(cont)
    
    name = _file.filename
    root = models.get_dir(name=user, path='/')
    db_f = g.db.query(File).filter_by(owner=user, name=name, dir=root.inode).first()
    if db_f is not None:
        return "File already exists", 409

    new_file = File(name=name, owner=user, content=cont, dir=root.inode)
    new_file.directory = root
    tx = Transaction(user=user, 
                     action="CREATE", 
                     type="FILE", 
                     pathname=new_file.pathname(),
                     ip_address=request.remote_addr)
    g.db.add(new_file)
    g.db.add(tx)
    return "Success"
开发者ID:MBloom,项目名称:OneDir,代码行数:25,代码来源:app.py


示例4: get

    def get(self):
        if not self.check_user(False):
            #self.logged_user_home()
            self.redirect('/')
            return

        max_results = 10
        tmp = self.request.get("max")
        if len(tmp):
            max_results = int(tmp)

        query = File.gql("WHERE author = :1", self.get_current_user())
        files = query.fetch(max_results);

        if len(files) > 0:
            head = files[0].head
        else:
            head = Revision()

        user = users.User(base.SUGGESTIONS_USER)
        query = File.gql("WHERE author = :1", user)
        public_files = query.fetch(50);
        files = files + public_files

        template_values = {
            'user'      : self.get_current_user(),
            'files'   	: files,
            'head'      : head,
            'login_url' : users.create_login_url(self.request.uri)
        }

        path = self.get_template_path( 'files.html' )
        self.response.out.write(template.render(path, template_values))
开发者ID:sqba,项目名称:zentxt,代码行数:33,代码来源:files.py


示例5: upload

def upload(request, uri):
    if request.POST:
        _uri = request.POST.get("uri")
        _md5_hash = request.POST.get("hash")
        _name = request.POST.get("name")
        _description = request.POST.get("description")
        _time = datetime.datetime.now()
        _directory = request.POST.get("directory")
        if _directory != "":
            _rank = 2
            # 判断文件夹是否存在,若存在,则其中文件数加一,否则创建新的文件夹
            try:
                d = Directory.objects.get(uri=uri + "/" + _directory)
            except Directory.DoesNotExist:
                d = None
            if d:
                d.file_num += 1
                d.save()
            else:
                d = Directory(uri=uri + "/" + _directory, file_num=1, time=_time, name=_directory)
                d.save()
        else:
            _rank = 1
        pd = PrimaryDirectory.objects.get(uri=uri)
        pd.file_num += 1
        pd.save()
        file = File(uri=_uri, md5_hash=_md5_hash, name=_name,
                    description=_description, time=_time,
                    url=getDownloadUrl(_uri), download_num=0, rank=_rank)
        file.save()
        return HttpResponse("ok")
    return render_to_response("upload.html", {"uri": uri}, context_instance=RequestContext(request))
开发者ID:Jiang-Le,项目名称:WeLearn,代码行数:32,代码来源:views.py


示例6: download

def download():
    '''Grabs the latest.'''

    # Download Files
    date_str = date.today().strftime("%Y_%m_%d")
    new_folder_path = "data/downloaded_%s" % date_str
    download_files(new_folder_path)


    # Delete if already exist in database
    for path, subdirs, files in os.walk(new_folder_path):
        for f in files:
            if already_downloaded(path + '/' + f):
                print "Didn't save '%s' because it was already in the database." % f
                os.remove(path + '/' + f)
            else:
                print "Saved new file '%s/%s'" % (path, f)

                File.create(
                    name = f,
                    years=next(re.finditer(r'\d{4}_\d{4}', f)),
                    sha1 = sha1OfFile(path + '/' + f),
                    updated = date.today(),
                    ingested = False
                )
开发者ID:josephmisiti,项目名称:iCorruptionHack,代码行数:25,代码来源:downloader.py


示例7: doShare

def doShare(path):
    is_private = False
    is_public = False

    try:
        f = File.get(File.public_share_url == path)
        is_public = True
    except peewee.DoesNotExist:
        try:
            f = File.get(File.private_share_url == path)
            is_private = True
        except peewee.DoesNotExist:
            return jsonify(message='error'), 404

    if not ((is_public and f.open_public_share) or (is_private and f.open_private_share)):
        return jsonify(message='error'), 404

    args = request.args
    if 'password' in args:
        if args['password'] == f.private_share_password:
            return jsonify(message='OK')
        else:
            return jsonify(message='error'), 401

    s = Serializer(app.config['SECRET_KEY'])
    token = s.dumps({'path': path})

    payload = {
        'filename': f.filename,
        'folder': f.folder.name,
        'openPublic': f.open_public_share,
        'openPrivate': f.open_private_share,
        'token': token,
    }
    return jsonify(message='OK', payload=payload)
开发者ID:kissthink,项目名称:MyCloud,代码行数:35,代码来源:app.py


示例8: add

def add(request, key=None, type=FILE):
    to = key # lame but it does the trick for now
    if type == FOLDER:
        form = FolderForm(request.form)
    else:
        form = FileForm(request.form)
    if request.method == "POST" and form.validate():
        if len(form.slug.data) < 1:
            form.slug.data = slugify(form.name.data)
        if type == FOLDER:
            file = File.add(to=to,type=type, name=form.name.data,
                                            slug=form.slug.data,
                                            breadcrumb=form.breadcrumb.data,
                                            state=form.state.data,
                                            active=form.active.data,
                                            author=users.get_current_user(),
                                            updated=datetime.now())
        elif type == FILE:
            file = request.files.get('file')
            data = db.Blob(file.read())
            file = File.add(to=to,type=type, name=form.name.data,
                                            slug=form.slug.data,
                                            breadcrumb=form.breadcrumb.data,
                                            state=form.state.data,
                                            active=form.active.data,
                                            author=users.get_current_user(),
                                            updated=datetime.now(),
                                            content_type=file.content_type,
                                            data=data, size=len(data))

        if form.save.data is True:
            return redirect(url_for('nut:files/list'), 301)
        if form.cont.data is True:
            return redirect(url_for('nut:files/edit', key=file.key()), 301)
    return render_template('app:files/form.html', form=form)
开发者ID:4416,项目名称:hazel-cms,代码行数:35,代码来源:views.py


示例9: RegisterFile

def RegisterFile(Service=None, FileName=None, ProvisionedSpace="10G"):

    if Service  is None:
	raise StorageError('RegisterFile(): Service can not be None')

    if FileName is None:
	raise StorageError('RegisterFile(): FileName can not be None')

    vfilespace = StringSizeToBytes(ProvisionedSpace)
    
    if Service.freespace - vfilespace > 0:
	NewFile = File()
	NewFile.vfilename 	= FileName
        NewFile.ufid		= GetUniqueFileID(FileName)
	NewFile.pfilesize	= 0
        NewFile.vfilesize	= vfilespace
	NewFile.service		= Service
	NewFile.pfilename	= GetPhysicalFileName(Service.localpath, FileName)
	NewFile.status		= 'O'
	NewFile.save()
	
	SFreeSpace = CalculateFreeSpace(Service)
	Service.freespace = SFreeSpace
	Service.save()

	return NewFile
    else:
	raise StorageError('RegisterFile(): No have left space')
开发者ID:emilianobilli,项目名称:tacho,代码行数:28,代码来源:storageutils.py


示例10: search

def search(query, offset = 0, limit = 10):
  results = None
  search_type = None

  if query:
    if len(query) > 10 and lower_hex_regex.match(query):
      for d in hash_sizes:
        if len(query) == hash_sizes[d]:
          search_type = '%s search' % d.upper()
          results = File.all().filter('%s =' % d, query)
          break
      if not search_type:
        search_type = 'SHA1 prefix search'
        results = File.all().filter('sha1 >= ', query).filter('sha1 < ', query + u'\ufffd')
    else: #Last resort: basename matching
      match_case = 0
      if query.lower() == query:
        results = File.all().filter('name_lower >= ', query).filter('name_lower < ', query + u'\ufffd')
      else:
        match_case = 1
        results = File.all().filter('name >= ', query).filter('name < ', query + u'\ufffd')
      search_type = 'Filename prefix search%s' % ['', ', matching case,'][match_case]
      #db.GqlQuery("SELECT * FROM MyModel WHERE prop >= :1 AND prop < :2", "abc", u"abc" + u"\ufffd")
  if results and limit:
    results.fetch(limit)
  return {'results': results, 'search_type': search_type, 'query': query, 'search_limit': limit, 'search_offset': offset}
开发者ID:bneijt,项目名称:dynmirror.net,代码行数:26,代码来源:views.py


示例11: file_path

def file_path(slug):
    f = File.all().filter('abs_path = ', slug).get()
    if f is None:
        f = File.all().filter('slug = ', slug).get()
    if f is None:
        return u''
    return f.get_absolute_url()
开发者ID:4416,项目名称:hazel-cms,代码行数:7,代码来源:__init__.py


示例12: GetOutput

    def GetOutput(self):
#        if not self.check_user():
#            return

        file_id = self.request.get("id")
        file = self.get_file(file_id)
        if file is None:
            file = File()
            file.put()
        else:
            if self.get_file_permission(file) < base.ACCESS_READ:
                self.redirect('/')
                return

        head = file.head
        if head is None:
            file_text = "Welcome to ZenTxt!"
            revisions = []
        else:
            #file_text = cgi.escape(head.content)
            file_text = head.content
            revisions = self.get_revisions(file)

        template_values = {
            'user'      : self.get_current_user(),
            'file_id'   : file_id,
            'revisions' : revisions,
            'file_text' : file_text,
            'login_url' : users.create_login_url(self.request.uri)
        }

        path = self.get_template_path( 'file.html' )
        return template.render(path, template_values)
开发者ID:sqba,项目名称:zentxt,代码行数:33,代码来源:file.py


示例13: test_model_file

 def test_model_file(self):
     """Test File Model"""
     folder = Folder(name='test')
     folder.save()
     obj = File(name='test', folder=folder)
     obj.save()
     self.assertEquals(folder, obj.folder)
     self.assertNotEquals(obj.id, None)
     obj.delete()
开发者ID:tovmeod,项目名称:anaf,代码行数:9,代码来源:tests.py


示例14: create_file

 def create_file(self, filename, user=None):
     file = File()
     if user is None:
         user = self.get_current_user()
     file.author = user
     file.name = filename
     key = file.put()
     self.create_permission(file, file.author, ACCESS_WRITE)
     #self.redirect('/file?' + urllib.urlencode({'id': key}))
     return key
开发者ID:sqba,项目名称:zentxt,代码行数:10,代码来源:base.py


示例15: already_downloaded

def already_downloaded(filepath):
    '''
    Return true if we already have this version of the file
    (check date and file hash). False otherwise
    '''
    try:
        File.get(File.sha1 == sha1OfFile(filepath))
        return True
    except peewee.DoesNotExist:
        return False
开发者ID:josephmisiti,项目名称:iCorruptionHack,代码行数:10,代码来源:downloader.py


示例16: parse

def parse(query):
    if query == "":
        return File.select()

    tokens = tokenize(query)
    result = _parse(iter(tokens))
    try:
        iter(result)
    except TypeError:
        result = File.select().join(Metadata, peewee.JOIN_LEFT_OUTER).where(result)
    return result
开发者ID:mklauber,项目名称:Curator,代码行数:11,代码来源:query.py


示例17: parse_pep8

def parse_pep8(run, git_path, output):
    """Parse the pep8 output, store the results"""

    errfiles_set = set()
    errortype_set = set()
    lineno_set = set()

    # Add all files in the project to the db
    allfiles = set()
    os.path.walk(git_path, add_file_to_set, allfiles)
    for filename in allfiles:
        filename = filename.replace(git_path + '/', '', 1)
        runfile = File(filename=filename, run=run)
        runfile.save()

    # Generate a set of error types, error files, and lines
    for line in output.readlines():
        filename, lineno, errnum, errtext = string.split(line, ':', 3)
        lineno = int(lineno)
        filename = filename.replace(git_path + '/', '', 1)

        # Create sets to remove duplicates
        errfiles_set.add(filename)

        # Add new err types to the db
        if (errnum, errtext) not in errortype_set:
            errortype_set.add((errnum, errtext))
            if not Error.objects.filter(error_type=errnum):
                err = Error(error_type=errnum, short_descr=errtext)
                err.save()

        # Create a set of line numbers for each file
        for ln in range(max(1, lineno - 3), lineno + 4):
            lineno_set.add((filename, ln))

        # Add err instances to the db
        runfile = File.objects.get(run=run, filename=filename)
        errtype = Error.objects.get(error_type=errnum)
        runerr = RunError(error=errtype, file=runfile, line_number=lineno,
                          error_descr=errtext)
        runerr.save()

    # Add lines to the db
    for filename in errfiles_set:
        runfile = File.objects.get(run=run, filename=filename)

        f = open(git_path + '/' + filename, 'r')
        lineno = 1
        for line in f:
            if (filename, lineno) in lineno_set:
                linetext = Line(file=runfile, line_number=lineno, text=line)
                linetext.save()
            lineno = lineno + 1
        f.close()
开发者ID:Bryukh,项目名称:spygit,代码行数:54,代码来源:pep8.py


示例18: summary

def summary():
    text = '<h1>Database Summary</h1>\n'
    file1 = File.get(id=1)
    file2 = File.get(id=2)
    file3 = File.get(id=3)

    text += '<h2>' + file1.name + '</h2>\n'
    text += '<h2>' + file2.name + '</h2>\n'
    text += '<h2>' + file3.name + '</h2>\n'

    return text
开发者ID:leahbannon,项目名称:iCorruptionHack,代码行数:11,代码来源:views.py


示例19: post_object

def post_object(request):

    if request.method == "POST":

        upload = request.FILES['file']
        parent = request.POST.get('parent') if 'parent' in request.POST.keys() else None

        f = File(name=upload.name, file=upload, owner=request.user, parent=parent, bytes=request.POST.get('size'), mime=request.POST.get('type'))
        f.save()

        return JsonResponse(f.get_client_inode(), safe=False)
    return JsonResponse({'message':'Invalid file..'}, status=400, safe=False)
开发者ID:DanielKoehler,项目名称:CoffeeCup,代码行数:12,代码来源:endpoints.py


示例20: save_file

def save_file(mime, base64):
    '''
    Calculate hash of the file, look up in the database,
    save if it's a new one and return its hash.  The hash
    can the be used as URL.
    '''
    hash_ = file_keeper_hash(mime, base64)
    objects = File.objects.filter(hash=hash_)
    if not objects:
        file_ = File(hash=hash_, mime=mime, base64=base64)
        file_.save()
    return hash_
开发者ID:vpavlenko,项目名称:pastegraph,代码行数:12,代码来源:__init__.py



注:本文中的models.File类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.Folder类代码示例发布时间:2022-05-27
下一篇:
Python models.Feedback类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap