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


Python File.create方法代码示例

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


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

示例1: download

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

示例2: folder

# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import create [as 别名]
def folder(folder_name):
    try:
        f = Folder.get(name=folder_name)
    except peewee.DoesNotExist:
        return jsonify(message='error'), 404

    if request.method == 'POST':
        file = request.files['file']
        if file:
            actual_filename = secure_filename(
                folder_name + '_' + file.filename)
            if os.path.exists(os.path.join(app.config['UPLOAD_FOLDER'], actual_filename)):
                return jsonify(message='error'), 409
            file.save(
                os.path.join(app.config['UPLOAD_FOLDER'], actual_filename))
            f2 = File.create(folder=folder_name,
                             filename=file.filename,
                             public_share_url=generate_url(),
                             private_share_url=generate_url(),
                             private_share_password=generate_password(),
                             open_public_share=False,
                             open_private_share=False)
            f2.save()
            return jsonify(message='OK'), 201

    if request.method == 'GET':
        files = File.select().where(File.folder == folder_name)
        items = [{
            'filename': x.filename,
            'public': x.public_share_url,
            'private': x.private_share_url,
            'password': x.private_share_password,
            'openPublic': x.open_public_share,
            'openPrivate': x.open_private_share
        } for x in files]

        return jsonify(message='OK', items=items)

    if request.method == 'DELETE':
        try:
            f.delete_instance()
        except peewee.IntegrityError:
            return jsonify(message='error'), 409
        return jsonify(message='OK')
开发者ID:kissthink,项目名称:MyCloud,代码行数:46,代码来源:app.py


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