python api中文版_Python API

Python API

Seafile Python API

This tutorial show you how to use seafile-api, and will accomplish a "library copy" work under Ubuntu as example.

Install Seafile Server

First of all, make sure you have Download and Setup Seafile Server successfully. And your directory layout will be like this:

# tree . -L 3

.

├── ccnet

│ ├── ccnet.conf

│ ├── ......

│......

├── seafile-server-3.0.3

│ ├── seafile

│ ├── seafile.sh

│ ├── seahub

│ ├── seahub.sh

│ ├── setup-seafile.sh

│ ├── upgrade

│ ├── README

│ ├── seaf_migrate_3.py

│ ├── seaf_migrate_3.sh

│ ├── ......

│ ├── ......

│......

Example: Copy Library

In this example, two script files will be used: seaf_migrate_3.sh and seaf_migrate_3.py. We put them in the upgrade directory as you see above.

Set Environment Variable

If you want use Seafile-API, set environment variable first. That"s what seaf_migrate_3.sh does:

get ccnet/seafile config file path and export them;

export Python path;

call seaf_migrate_3.py.

Example code

#!/bin/bash

#get path of ccnet.conf

SCRIPT=$(readlink -f "$0") # haiwen/seafile-server-3.0.3/upgrade/seaf_migrate_3.sh

UPGRADE_DIR=$(dirname "$SCRIPT") # haiwen/seafile-server-3.0.3/upgrade/

INSTALLPATH=$(dirname "$UPGRADE_DIR") # haiwen/seafile-server-3.0.3/

TOPDIR=$(dirname "${INSTALLPATH}") # haiwen/

default_ccnet_conf_dir=${TOPDIR}/ccnet

#get path of seafile.conf

function read_seafile_data_dir () {

seafile_ini=${default_ccnet_conf_dir}/seafile.ini

if [[ ! -f ${seafile_ini} ]]; then

echo "${seafile_ini} not found. Now quit"

exit 1

fi

seafile_data_dir=$(cat "${seafile_ini}")

if [[ ! -d ${seafile_data_dir} ]]; then

echo "Your seafile server data directory "${seafile_data_dir}" is invalid or doesn"t exits."

echo "Please check it first, or create this directory yourself."

echo ""

exit 1;

fi

export SEAFILE_CONF_DIR=$seafile_data_dir

}

export CCNET_CONF_DIR=${default_ccnet_conf_dir}

read_seafile_data_dir;

export PYTHONPATH=${INSTALLPATH}/seafile/lib/python2.6/site-packages:${INSTALLPATH}/seafile/lib64/python2.6/site-packages:${INSTALLPATH}/seafile/lib/python2.7/site-packages:${INSTALLPATH}/seahub/thirdpart:$PYTHONPATH

export PYTHONPATH=${INSTALLPATH}/seafile/lib/python2.7/site-packages:${INSTALLPATH}/seafile/lib64/python2.7/site-packages:$PYTHONPATH

function usage () {

echo "Usage: `basename $0` "

echo "exit."

exit 1

}

if [ $# != 1 ]; then

usage

fi

python seaf_migrate_3.py $1

NOTE:You can get repo_id at address bar of Seahub or through Seafile web API

Copy Library

Then seaf_migrate_3.py will call Seafile-API to copy library:

Get library ID from input.

Get origin_repo object.

Create a new library, set name, desc and owner.

Copy stuffs from old library to new library.

Example code

#!/usr/bin/env python

import os

import stat

import sys

from seaserv import seafile_api

def count_files_recursive(repo_id, path="/"):

num_files = 0

for e in seafile_api.list_dir_by_path(repo_id, path):

if stat.S_ISDIR(e.mode):

num_files += count_files_recursive(repo_id,

os.path.join(path, e.obj_name))

else:

num_files += 1

return num_files

#Get library ID from input

origin_repo_id = sys.argv[1]

#Get origin_repo object

origin_repo = seafile_api.get_repo(origin_repo_id)

username = seafile_api.get_repo_owner(origin_repo_id)

#Create a new library, set name, desc and owner

new_repo_id = seafile_api.create_repo(name=origin_repo.name,

desc=origin_repo.desc,

username=username, passwd=None)

#Copy stuffs from old library to new library

dirents = seafile_api.list_dir_by_path(origin_repo_id, "/")

for e in dirents:

print "copying: " + e.obj_name

obj_name = e.obj_name

seafile_api.copy_file(origin_repo_id, "/", obj_name, new_repo_id, "/",

obj_name, username, 0, 1)

print "*" * 60

print "OK, verifying..."

print "Origin library(%s): %d files. New Library(%s): %d files." % (

origin_repo_id[:8], count_files_recursive(origin_repo_id),

new_repo_id[:8], count_files_recursive(new_repo_id))

print "*" * 60

If you execute script file successfully, you will see these output, and of course a new library at myhome page of Seahub.

foo@foo:~/haiwen/seafile-server-3.0.3/upgrade$ ./seaf_migrate_test.sh c8bbb088-cbaf-411d-8bd8-9870763f0e5f

Loading ccnet config from /home/foo/haiwen/ccnet

Loading seafile config from /home/foo/haiwen/seafile-data

copying: test.html

copying: test-dir-2

copying: test-dir

copying: solar.html

copying: examples.desktop

************************************************************

OK, verifying...

Origin library(c8bbb088): 10 files. New Library(4d6f4837): 10 files.

************************************************************

List Of Seafile-API

This list is based on seafile-server-3.0.3, and parameter was omitted.

For more infomation about Seafile-API, please see api.py.

seafile_api.add_inner_pub_repo()

seafile_api.cancel_copy_task()

seafile_api.change_repo_passwd()

seafile_api.check_passwd()

seafile_api.check_permission()

seafile_api.check_quota()

seafile_api.check_repo_access_permission()

seafile_api.copy_file()

seafile_api.count_inner_pub_repos()

seafile_api.create_enc_repo()

seafile_api.create_repo()

seafile_api.create_virtual_repo()

seafile_api.del_file()

seafile_api.delete_repo_token()

seafile_api.delete_repo_tokens_by_peer_id()

seafile_api.diff_commits()

seafile_api.edit_repo()

seafile_api.generate_repo_token()

seafile_api.get_commit_list()

seafile_api.get_copy_task()

seafile_api.get_decrypt_key()

seafile_api.get_deleted()

seafile_api.get_dir_id_by_commit_and_path()

seafile_api.get_dir_id_by_path()

seafile_api.get_file_id_by_commit_and_path()

seafile_api.get_file_id_by_path()

seafile_api.get_file_revisions()

seafile_api.get_file_size()

seafile_api.get_files_last_modified()

seafile_api.get_group_repo_list()

seafile_api.get_group_repoids()

seafile_api.get_group_repos_by_owner()

seafile_api.get_fileserver_access_token()

seafile_api.get_inner_pub_repo_list()

seafile_api.get_orphan_repo_list()

seafile_api.get_owned_repo_list()

seafile_api.get_repo()

seafile_api.get_repo_list()

seafile_api.get_repo_owner()

seafile_api.get_repo_size()

seafile_api.get_share_in_repo_list()

seafile_api.get_share_out_repo_list()

seafile_api.get_shared_groups_by_repo()

seafile_api.get_user_quota()

seafile_api.get_user_self_usage()

seafile_api.get_user_share_usage()

seafile_api.get_virtual_repo()

seafile_api.get_virtual_repos_by_owner()

seafile_api.group_share_repo()

seafile_api.group_unshare_repo()

seafile_api.is_inner_pub_repo()

seafile_api.is_password_set()

seafile_api.is_repo_owner()

seafile_api.is_valid_filename()

seafile_api.list_dir_by_commit_and_path()

seafile_api.list_dir_by_dir_id()

seafile_api.list_dir_by_path()

seafile_api.list_file_by_file_id()

seafile_api.list_repo_tokens()

seafile_api.list_repo_tokens_by_email()

seafile_api.move_file()

seafile_api.post_dir()

seafile_api.post_empty_file()

seafile_api.post_file()

seafile_api.put_file()

seafile_api.query_fileserver_access_token()

seafile_api.remove_inner_pub_repo()

seafile_api.remove_repo()

seafile_api.remove_share()

seafile_api.rename_file()

seafile_api.revert_dir()

seafile_api.revert_file()

seafile_api.revert_repo()

seafile_api.set_group_repo_permission()

seafile_api.set_passwd()

seafile_api.set_repo_owner()

seafile_api.set_share_permission()

seafile_api.set_user_quota()

seafile_api.share_repo()

seafile_api.unset_passwd()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Python API文档中文是指将Python官方的API文档翻译成中文的版本。Python API文档中文的目的是为了方便中国的开发者使用Python编程语言。 Python API文档中文包含了Python编程语言的各种模块、函数、类和方法的详细说明。它提供了对Python标准库的全面覆盖,方便开发者快速了解和使用各种Python的功能和特性。 Python API文档中文通常按照模块的方式组织,每个模块都有详细的介绍和示例代码,以及各个函数和类的参数、用法和返回值的说明。这样有助于开发者理解和运用Python中的各个模块和功能,能够更加高效地编写代码。 Python API文档中文的翻译工作通常由一些Python的社区和开发者共同完成,他们致力于将Python官方文档翻译成中文版本,并及时进行更新和维护,以保证文档的准确性和完整性。 对于中文开发者来说,Python API文档中文是学习和使用Python编程语言的重要工具之一。通过阅读Python API文档中文,开发者可以快速上手Python,了解各种模块和功能的使用方法,提高编程效率和质量。 总的来说,Python API文档中文为中国的开发者提供了一个便捷的学习和使用Python的渠道,使得开发者能够更好地掌握Python编程语言,实现各种应用和项目。 ### 回答2: Python API文档中文翻译了Python编程语言的应用程序编程接口文档,并将其转化为中文版本。这个文档是为了帮助中文用户更好地理解和使用Python编程语言而编写的。 Python API文档中文版详细介绍了Python语言中各个模块、函数和类的用法、参数和返回值等相关信息。它包含了Python标准库中的各种模块,如`math`、`os`、`sys`等,以及第三方库中常用的模块,如`requests`、`numpy`等。这样,用户可以通过阅读该文档来了解各个模块的具体功能和使用方法。 Python API文档中文版还提供了一些示例代码,以展示如何使用不同模块和函数来实现各种功能。这些示例代码有助于用户更好地了解Python编程语言的基本语法和面向对象编程的概念。 通过阅读Python API文档中文版,用户可以更加便捷地查找所需的函数和模块,并了解它们的功能和用法。这对于开发各种Python应用程序和解决实际问题非常有帮助。 总之,Python API文档中文版是一本详细介绍Python编程语言应用程序编程接口的文档,它为中文用户提供了理解和使用Python编程语言的重要参考资料。无论是初学者还是有经验的程序员都可以通过阅读该文档来提升他们的Python编程技能。 ### 回答3: Python API文档中文主要是指将Python编程语言的官方API文档翻译成中文的工作。Python作为一种广泛使用的编程语言,拥有强大的标准库和大量第三方库,这些库包含了各种功能模块和工具,供开发者使用。官方API文档对于学习和使用Python来说非常重要,它提供了详细的函数说明、参数说明和示例代码,帮助开发者理解库的使用方法。 将Python API文档翻译成中文的作用主要有几个方面。首先,对于非英语母语的开发者来说,中文翻译能够解决语言障碍问题,提高开发效率。其次,对于刚刚接触Python的初学者来说,中文翻译可以降低学习的难度,更快地入门。此外,中文翻译还能促进Python在中国的普及和推广,吸引更多的开发者加入Python社区。 Python API文档的中文翻译工作通常由社区成员、第三方机构或志愿者组织来完成。他们通过认领、翻译和校对的方式,逐步将官方API文档翻译成中文,并发布在相关的网站或在线平台上供开发者查询使用。这些翻译工作需要对Python语言有深刻的理解,并具备较强的中英双语能力。 总而言之,Python API文档的中文翻译工作对于推动Python的使用和普及具有重要意义。它不仅方便了中文用户的学习和使用,同时也为Python社区的发展提供了积极的支持和贡献。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值