Beispiel #1
0
def seaf_desync(conf_dir, repo_path):
    '''Desynchronize a library from seafile server'''

    pool = ccnet.ClientPool(conf_dir)
    seafile_rpc = seafile.RpcClient(pool, req_pool=False)

    repos = seafile_rpc.get_repo_list(-1, -1)
    repo = None
    for r in repos:
        if r.worktree.replace('/', '\\') == repo_path.decode('utf-8').replace(
                '/', '\\'):
            repo = r
            break

    if repo:
        print "Desynchronize repo test success."
        seafile_rpc.remove_repo(repo.id)
    else:
        print "%s is not a library worktree" % repo_path
Beispiel #2
0
def seaf_sync(conf_dir, server_url, repo_id, worktree, username, passwd):
    ''' synchronize a library from seafile server '''

    pool = ccnet.ClientPool(conf_dir)
    seafile_rpc = seafile.RpcClient(pool, req_pool=False)

    token = get_token(server_url, username, passwd)
    tmp = get_repo_downlod_info(
        "%s/api2/repos/%s/download-info/" % (server_url, repo_id), token)

    encrypted = tmp['encrypted']
    magic = tmp.get('magic', None)
    enc_version = tmp.get('enc_version', None)
    random_key = tmp.get('random_key', None)

    clone_token = tmp['token']
    relay_id = tmp['relay_id']
    relay_addr = tmp['relay_addr']
    relay_port = str(tmp['relay_port'])
    email = tmp['email']
    repo_name = tmp['repo_name']
    version = tmp.get('repo_version', 0)

    more_info = None
    base_url = get_base_url(server_url)
    if base_url:
        more_info = json.dumps({'server_url': base_url})

    if encrypted == 1:
        repo_passwd = 's123'
    else:
        repo_passwd = None

    seafile_rpc.clone(repo_id, version, relay_id, repo_name.encode('utf-8'),
                      worktree, clone_token, repo_passwd, magic, relay_addr,
                      relay_port, email, random_key, enc_version, more_info)

    print 'Synchronize repo test success.'
Beispiel #3
0
def seaf_get_repo(conf_dir, repo_id):
    pool = ccnet.ClientPool(conf_dir)
    seafile_rpc = seafile.RpcClient(pool, req_pool=False)
    return seafile_rpc.seafile_get_repo(repo_id)
Beispiel #4
0
if sys.platform == "darwin" and "LANG" not in os.environ:
    os.environ["LANG"] = "en_US.UTF-8"
    os.environ["LC_ALL"] = "en_US.UTF-8"

# lang code will be used to set default language in main.py
lang_code, system_encoding = locale.getdefaultlocale()

CCNET_CONF_PATH = CCNET_CONF_PATH.decode(system_encoding)

print "Load config from " + CCNET_CONF_PATH

pool = ccnet.ClientPool(CCNET_CONF_PATH.encode('utf-8'))
ccnet_rpc = ccnet.CcnetRpcClient(pool, req_pool=True)
applet_rpc = AppletRpcClient(pool, req_pool=True)
seafile_rpc = seafile.RpcClient(pool, req_pool=True)
seafile_threaded_rpc = seafile.ThreadedRpcClient(pool)
monitor_rpc = seafile.MonitorRpcClient(pool)

#### Basic ccnet API ####


def get_peers_by_role(role):
    return ccnet_rpc.get_peers_by_role(role)


def get_peers():
    peer_ids = ccnet_rpc.list_peers()
    if not peer_ids:
        return []
    peers = []
Beispiel #5
0
                        type=str,
                        help="Repository ID to check the status of.")
    parser.add_argument(
        '-c',
        '--confdir',
        type=str,
        required=True,
        help="Seafile configuration directory to load the Socket from.")
    args = parser.parse_args()

    # Instanciate Seafile RPC.
    seafile_socket = os.path.join(args.confdir, "seafile.sock")
    if not os.path.exists(seafile_socket):
        raise Exception("Could not find a Seafile socket at {}".format(
            args.confdir))
    seafile_rpc = seafile.RpcClient(seafile_socket)

    # Fetch the sync task of the repository.
    repository_sync_task = seafile_rpc.get_repo_sync_task(args.repository_id)
    if repository_sync_task is not None:
        sync_state = repository_sync_task.state
        msg = "Repository synchronization state: {}".format(sync_state)
        if sync_state == "error":
            raise Exception(msg)
        else:
            print(msg)
            sys.exit(0)

    # Fetch the transfer task of the repository.
    repository_transfer_task = seafile_rpc.find_transfer_task(
        args.repository_id)
Beispiel #6
0
seaf_daemon3.start("-w", "basic/worktree/wt3")
seaf_daemon4 = SeafileDaemon("basic/conf4")
seaf_daemon4.start("-w", "basic/worktree/wt4")

print_cmsg("sleep")
time.sleep(15)

os.system("""
cd basic;
./seafserv-tool -c conf2 add-server server
./seafserv-tool -c conf2 add-server server2
""")

pool1 = ccnet.ClientPool("basic/conf1")
ccnet_rpc1 = ccnet.CcnetRpcClient(pool1)
seaf_rpc1 = seafile.RpcClient(pool1)
seaf_rpc3 = seafile.RpcClient(ccnet.ClientPool("basic/conf3"))

repo_id = seaf_rpc1.create_repo("test-repo", "test")
if not repo_id:
    print_cmsg("Failed to create repo")
    cleanup_and_exit()

print_cmsg("Created repo " + repo_id)

print_cmsg("Copy data into basic/worktree/wt1")
try:
    if not os.access("basic/worktree/wt1/%s/data" % repo_id, os.F_OK):
        shutil.copytree("basic/data", "basic/worktree/wt1/%s/data" % repo_id)
except OSError as e:
    print_cmsg("Failed to copy data: " + e.strerror)
Beispiel #7
0
def get_searpc_client():
    pool = ccnet.ClientPool(DEFAULT_CONF_DIR)
    seafile_rpc = seafile.RpcClient(pool, req_pool=False)
    return seafile_rpc
Beispiel #8
0
def get_rpc_client(confdir):
    return seafile.RpcClient(join(seafile_datadir, 'seafile.sock'))
 def client(self):
     return seafile.RpcClient(self.seaf_sock)