当前位置: 首页>>代码示例>>Python>>正文


Python File.get方法代码示例

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


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

示例1: doShare

# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import get [as 别名]
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,代码行数:37,代码来源:app.py

示例2: already_downloaded

# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import get [as 别名]
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,代码行数:12,代码来源:downloader.py

示例3: summary

# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import get [as 别名]
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,代码行数:13,代码来源:views.py

示例4: ImportJsonOnMenuSelection

# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import get [as 别名]
def ImportJsonOnMenuSelection(self, event):
    openFileDialog = wx.FileDialog(self, "Open MEtadat file", "", "",
                                   "JSON files (*.json)|*.json", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)

    if openFileDialog.ShowModal() == wx.ID_CANCEL:
        return     # the user changed idea...

    # proceed loading the file chosen by the user
    # this can be done with e.g. wxPython input streams:
    data = None
    with open(openFileDialog.GetPath(), 'r') as f:
        data = json.load(f)

    for md5, metadata in data.items():
        try:
            f = File.get(File.md5 == md5)
        except Exception as e:
            logger.error("Unable to get file for md5:%s", md5)
            logger.exception(e)
            continue    # Don't do more work with this file
        for field, values in metadata.items():
            if field == 'import-time':
                return
            for value in values:
                try:
                    Metadata(file=f, field=field, value=value).save()
                except peewee.IntegrityError as e:
                    logger.info("Duplicate metadata ignored (%s, %s, %s)", md5, field, value)
                except Exception as e:
                    logger.error("Unable to save metadata (%s, %s, %s)", md5, field, value)
                    logger.exception(e)
    self.update_metadata()
    self.update_tags()
开发者ID:mklauber,项目名称:Curator,代码行数:35,代码来源:__init__.py

示例5: post

# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import get [as 别名]
    def post(self):
        item = None
        vals = {}

        # get all the incoming values
        title = self.request.get('title').strip()
        blob_key = None
        label_raw = self.request.get('label_raw').strip()

        # get the file information
        uploaded_files = self.get_uploads('file')
        if len(uploaded_files) == 1:
            blob_info = uploaded_files[0]
            blob_key = blob_info.key()

        if self.request.get('key'):
            item = File.get( self.request.get('key') )
            item.title       = title
            item.label_raw   = label_raw
        else:
            item = File(
                title       = title,
                label_raw   = label_raw,
                )

        if blob_key:
            item.blob = blob_key

        # update and save this file
        item.set_derivatives()
        item.put()
        self.redirect('.')
开发者ID:ranginui,项目名称:kohacon,代码行数:34,代码来源:file.py

示例6: ingested

# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import get [as 别名]
def ingested(filepath):
    '''Return true if file is already ingested, false otherwise'''
    # TODO: implement better (just checks if file in table right now)
    try:
        myfile = File.get(name=filepath)
        print "%s already in database." % filepath
        return True
    except:
        return False
开发者ID:leahbannon,项目名称:iCorruptionHack,代码行数:11,代码来源:ingester.py

示例7: edit

# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import get [as 别名]
def edit(request, key):
    file = File.get(key)
    form = FileEditForm(request.form, obj=file)
    if request.method == "POST" and form.validate():
        form.auto_populate(file)
        file.put()
        if form.save.data is True:
            return redirect(url_for('nut:files/list'), 301)
    return render_template('app:files/form.html', form=form, file=file)
开发者ID:4416,项目名称:hazel-cms,代码行数:11,代码来源:views.py

示例8: get_tags

# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import get [as 别名]
def get_tags(file_name):
    """Retreives a list of the tags for a specific file"""

    if File.get(File.file_name == file_name):

        file_tags = (Tag
                     .select()
                     .join(FileTag)
                     .where(FileTag.file_id == File.get(File.file_name == file_name)))

        tag_list = []

        for t in file_tags:
            tag_list.append(t.tag_name)

        return tag_list

    else:
        print "Sorry! Couldn't understand request!"
开发者ID:mosegontar,项目名称:ScratchTrack,代码行数:21,代码来源:catalog.py

示例9: get

# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import get [as 别名]
    def get(self):
        item = None
        if self.request.get('key'):
            item = File.get( self.request.get('key') )

        vals = {
            'item'       : item,
            # this is either new.html or edit.html
            'upload_url' : blobstore.create_upload_url( str(urllib.unquote(self.request.path)) ),
            }
        self.template( 'file-form.html', vals, 'admin' );
开发者ID:ranginui,项目名称:kohacon,代码行数:13,代码来源:file.py

示例10: delete_entry

# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import get [as 别名]
def delete_entry(kind, entry, from_file=None):
    """Deletes a file name entry or tag entry from the catalog"""

    if kind == 'files':

        to_delete = File.get(File.file_name == entry)

        to_delete.delete_instance()

        print "'%s' deleted from catalog!" % entry

    elif kind == 'tag' and from_file:

        try:
            existing_file = File.get(File.file_name == from_file)

            if existing_file:
                try:
                    association = FileTag.get(FileTag.file_id == existing_file,
                                              FileTag.tag_id == Tag.get(Tag.tag_name == entry))
                    association.delete_instance()

                    print "Deleted '%s' from '%s'" % (entry, from_file)

                except:

                    print "'%s' no longer tagged to %s" % (entry, from_file)

        except:
            print "'%s' not in catalog" % from_file

    elif kind == 'tag':

        tag_item = Tag.get(Tag.tag_name == entry)

        tag_item.delete_instance()

        print "'%s' deleted from catalog" % entry

    else:
        pass
开发者ID:mosegontar,项目名称:ScratchTrack,代码行数:43,代码来源:catalog.py

示例11: _on_moved_project

# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import get [as 别名]
    def _on_moved_project(self, event):
        """
        On_modified event handler for project files.

        This should get called when a project file has been moved.

        - If the file exists in database:
            - If the target path is inside project directory, change the\
            path entry in database.
            - If the target path is outside project directory, set the\
            file as deleted (project.id = NULL).
        - If the file does not exist in database:
            - If the target path is inside the project directory, add the\
            file into the database.
            - If the target path is outside the project directory, do nothing.

        :param event: The event.
        :type event: :py:class:`watchdog.events.FileSystemEvent`

        """
        source = os.path.abspath(event.src_path)
        target = os.path.abspath(event.dest_path)
        try:
            project = Project.get_by_id(self.project_id)
            source_file = File.get('one', File.project == project,
                                   File.path == source)
            project_path = os.path.abspath(project.dir)
            if source_file is not None:
                # Case 1
                if target.startswith(project_path):
                    source_file.path = target
                    act_path = target
                    action = REVERSE_ACTIONS['Renamed to something']
                # Case 2
                else:
                    source_file.project_id = None
                    act_path = source
                    action = REVERSE_ACTIONS['Deleted']
                source_file.update()
                self._project_prototype(act_path, action)
            else:
                # Case 3
                if target.startswith(project_path):
                    action = REVERSE_ACTIONS['Created']
                    self._project_prototype(target, action)
                # Case 4, should never happen.
                else:
                    pass
        except Exception as excp:
            log_msg = ('Exception in Project file handler on_moved '
                       'callback: {exception!s}')
            log_msg = log_msg.format(exception=excp)
            _logger().exception(log_msg)
开发者ID:diwa-aalto,项目名称:diwacs,代码行数:55,代码来源:handlers.py

示例12: delete

# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import get [as 别名]
def delete(request, key):
    form = FileConfirmDeleteForm(request.form)
    if request.method == "POST" and form.validate():
        if form.drop.data is True:
            File.drop(key)
            return redirect(url_for('nut:files/list'), 301)
        if form.cascade.data is True:
            File.drop(key, cascade=True)
            return redirect(url_for('nut:files/list'), 301)
    file = File.get(key)
    files = dict([(n.get_key(), n) for n in File.all().filter("ancestors = ", key)])
    file = rec(file, files)

    return render_template('app:files/confirm_delete.html', file=file, form=form)
开发者ID:4416,项目名称:hazel-cms,代码行数:16,代码来源:views.py

示例13: files

# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import get [as 别名]
def files(folder_name, filename):
    actual_filename = secure_filename(folder_name + '_' + filename)

    try:
        f = File.get(filename=filename)
    except peewee.DoesNotExist:
        return jsonify(message='error'), 404

    if request.method == 'GET':
        args = request.args
        if 'query' in args and args['query'] == 'info':
            payload = {
                'filename': f.filename,
                'public': f.public_share_url,
                'private': f.private_share_url,
                'password': f.private_share_password,
                'openPublic': f.open_public_share,
                'openPrivate': f.open_private_share
            }
            return jsonify(message='OK', payload=payload)

        return send_from_directory(app.config['UPLOAD_FOLDER'], actual_filename)

    if request.method == 'DELETE':

        actual_filename = secure_filename(folder_name + '_' + filename)
        file_path = os.path.join(app.config['UPLOAD_FOLDER'], actual_filename)

        if os.path.exists(file_path):
            f.delete_instance()
            os.remove(file_path)
            return jsonify(message='OK')
        else:
            return jsonify(message='error'), 404

    if request.method == 'PUT':
        req = request.get_json()
        share_type = req['shareType']
        if share_type == 'openPrivate':
            f.open_private_share = True
            f.open_public_share = False
        elif share_type == 'openPublic':
            f.open_private_share = False
            f.open_public_share = True
        elif share_type == 'None':
            f.open_public_share = False
            f.open_private_share = False
        f.save()
        return jsonify(message='OK')
开发者ID:kissthink,项目名称:MyCloud,代码行数:51,代码来源:app.py

示例14: post

# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import get [as 别名]
    def post(self):
        logging.getLogger().info("Post is %s" % self.request.POST)
        fil = self.request.POST["file_2"]
        if not fil.value:
            self.redirect("/")
            return

        file = File.get(self.request.get("csskey"))
        file.name = fil.filename
        file.file = db.Blob(cssmin.cssmin(fil.value))
        file.original = db.Blob(fil.value)
        file.content_type = fil.type
        file.user = users.get_current_user()
        file.put()
        self.redirect("/")
开发者ID:jakobholmelund,项目名称:appengine-image-host,代码行数:17,代码来源:backend.py

示例15: update_preview

# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import get [as 别名]
    def update_preview(self):
        if self.preview is None:
            return

        # The logic for creating a accurate image as large as can be seen
        preview = wx.Image()
        preview.LoadFile(File.get(md5=self.preview).path)

        width, height = self.PreviewPanel.GetSize()
        hRatio = height / preview.Height
        wRatio = width / preview.Width
        ratio = min(hRatio, wRatio)
        image = preview.Scale(preview.Width * ratio, preview.Height * ratio, wx.IMAGE_QUALITY_HIGH)
        result = image.ConvertToBitmap()
        # set the Result.
        self.Preview.SetBitmap(result)
开发者ID:mklauber,项目名称:Curator,代码行数:18,代码来源:__init__.py


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