def _get_office_converter_rpc(): global office_converter_rpc if office_converter_rpc is None: pool = ccnet.ClientPool(CCNET_CONF_PATH) office_converter_rpc = OfficeConverterRpcClient(pool) return office_converter_rpc
def _get_office_converter_rpc(): global office_converter_rpc if office_converter_rpc is None: pool = ccnet.ClientPool( seaserv.CCNET_CONF_PATH, central_config_dir=seaserv.SEAFILE_CENTRAL_CONF_DIR) office_converter_rpc = OfficeConverterRpcClient(pool) return office_converter_rpc
def stop_ser(): conf_dir = DEFAULT_CONF_DIR pool = ccnet.ClientPool(conf_dir) client = pool.get_client() try: client.send_cmd("shutdown") print 'stop ccnet and daemon' except Exception: # ignore NetworkError("Failed to read from socket") # print "Error: Failed to read from socket" pass
def seaf_stop(conf_dir): '''stop seafile daemon ''' pool = ccnet.ClientPool(conf_dir) client = pool.get_client() try: client.send_cmd("shutdown") except: # ignore NetworkError("Failed to read from socket") pass print 'Stop ccnet, seafile daemon success.'
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
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.'
def get_peer_id(): pool = ccnet.ClientPool(DEFAULT_CONF_DIR) ccnet_rpc = ccnet.CcnetRpcClient(pool) info = ccnet_rpc.get_session_info() return info.id
if check: raise ImportError( "Synserv cannot be imported, because environment variable %s is undefined." % key) return None if _DEBUG: print "Loading %s from %s" % (key, v) return os.path.normpath(os.path.expanduser(v)) CCNET_CONF_PATH = _load_path_from_env('CCNET_CONF_DIR') SYNCWERK_CONF_DIR = _load_path_from_env('SYNCWERK_CONF_DIR') SYNCWERK_CENTRAL_CONF_DIR = _load_path_from_env('SYNCWERK_CENTRAL_CONF_DIR', check=False) pool = ccnet.ClientPool(CCNET_CONF_PATH, central_config_dir=SYNCWERK_CENTRAL_CONF_DIR) ccnet_rpc = ccnet.CcnetRpcClient(pool, req_pool=True) ccnet_threaded_rpc = ccnet.CcnetThreadedRpcClient(pool, req_pool=True) syncwserv_rpc = syncwerk.ServerRpcClient(pool, req_pool=True) syncwserv_threaded_rpc = syncwerk.ServerThreadedRpcClient(pool, req_pool=True) # load ccnet server addr and port from ccnet.conf. # 'addr:port' is used when downloading a repo config = ConfigParser.ConfigParser() config.read( os.path.join( SYNCWERK_CENTRAL_CONF_DIR if SYNCWERK_CENTRAL_CONF_DIR else CCNET_CONF_PATH, 'ccnet.conf')) if config.has_option('General', 'SERVICE_URL'): service_url = config.get('General', 'SERVICE_URL')
import ccnet import wingufile pool = ccnet.ClientPool("basic/conf1") wingufile_rpc = wingufile.RpcClient(pool) repos = wingufile_rpc.get_repo_list("", 100) for repo in repos: print repo
seaf_daemon2.start("-r") seaf_daemon3 = SeafileDaemon("basic/conf3") 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)
def __init__(self): ccnet_conf_dir = os.path.normpath(os.path.expanduser(CCNET_CONF_DIR)) pool = ccnet.ClientPool(ccnet_conf_dir) self.ccnet_threaded_rpc = ccnet.CcnetThreadedRpcClient(pool, req_pool=True)
winguf_daemon2.start("-r") winguf_daemon3 = WingufileDaemon("basic/conf3") winguf_daemon3.start("-w", "basic/worktree/wt3") winguf_daemon4 = WingufileDaemon("basic/conf4") winguf_daemon4.start("-w", "basic/worktree/wt4") print_cmsg("sleep") time.sleep(15) os.system(""" cd basic; ./wingufserv-tool -c conf2 add-server server ./wingufserv-tool -c conf2 add-server server2 """) pool1 = ccnet.ClientPool("basic/conf1") ccnet_rpc1 = ccnet.CcnetRpcClient(pool1) winguf_rpc1 = wingufile.RpcClient(pool1) winguf_rpc3 = wingufile.RpcClient(ccnet.ClientPool("basic/conf3")) repo_id = winguf_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)
def get_searpc_client(): pool = ccnet.ClientPool(DEFAULT_CONF_DIR) seafile_rpc = seafile.RpcClient(pool, req_pool=False) return seafile_rpc
def __init__(self): pool = ccnet.ClientPool(CCNET_CONF_DIR, central_config_dir=SEAFILE_CENTRAL_CONF_DIR) self.ccnet_threaded_rpc = ccnet.CcnetThreadedRpcClient(pool, req_pool=True)
#!/usr/bin/env python #coding: UTF-8 import sys if len(sys.argv) != 3: print 'Usage: %s [email] [password]' % (sys.argv[0]) sys.exit(1) ccnet_dir = "{{ seafile_ccnet_config_dir }}" email = sys.argv[1] password = sys.argv[2] import ccnet rpc_client = ccnet.CcnetThreadedRpcClient(ccnet.ClientPool(ccnet_dir)) users = rpc_client.get_emailusers('DB', 0, 1) if len(users) != 0: print "Admin user already exists!" sys.exit(2) rpc_client.add_emailuser(email, password, 1, 1) lock = open('{{ seafile_home }}/seahub_admin_created.lock', 'w') lock.write('do not remove') lock.close()
### Loading ccnet and seafile configurations ### '''ccnet''' try: CCNET_CONF_PATH = os.environ[ENVIRONMENT_VARIABLES[0]] if not CCNET_CONF_PATH: # If it's set but is an empty string. raise KeyError except KeyError: raise ImportError( "Seaserv cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLES[0]) else: print "Loading ccnet config from " + CCNET_CONF_PATH CCNET_CONF_PATH = os.path.normpath(os.path.expanduser(CCNET_CONF_PATH)) pool = ccnet.ClientPool(CCNET_CONF_PATH) ccnet_rpc = ccnet.CcnetRpcClient(pool, req_pool=True) ccnet_threaded_rpc = ccnet.CcnetThreadedRpcClient(pool, req_pool=True) monitor_rpc = seafile.MonitorRpcClient(pool) seafserv_rpc = seafile.ServerRpcClient(pool, req_pool=True) seafserv_threaded_rpc = seafile.ServerThreadedRpcClient(pool, req_pool=True) # load ccnet server addr and port from ccnet.conf. # 'addr:port' is used when downloading a repo config = ConfigParser.ConfigParser() config.read(os.path.join(CCNET_CONF_PATH, 'ccnet.conf')) if config.has_option('General', 'SERVICE_URL') and \ config.has_option('Network', 'PORT'): service_url = config.get('General', 'SERVICE_URL') hostname = urlparse(service_url).hostname
CCNET_CONF_PATH = DEFAULT_CCNET_CONF_PATH CCNET_CONF_PATH = os.path.normpath(os.path.expanduser(CCNET_CONF_PATH)) 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()
def _load_path_from_env(key, check=True): v = os.environ.get(key, '') if not v: if check: raise ImportError("Seaserv cannot be imported, because environment variable %s is undefined." % key) return None if _DEBUG: print "Loading %s from %s" % (key, v) return os.path.normpath(os.path.expanduser(v)) CCNET_CONF_PATH = _load_path_from_env('CCNET_CONF_DIR') SEAFILE_CONF_DIR = _load_path_from_env('SEAFILE_CONF_DIR') SEAFILE_CENTRAL_CONF_DIR = _load_path_from_env('SEAFILE_CENTRAL_CONF_DIR', check=False) pool = ccnet.ClientPool(CCNET_CONF_PATH, central_config_dir=SEAFILE_CENTRAL_CONF_DIR) ccnet_rpc = ccnet.CcnetRpcClient(pool, req_pool=True) ccnet_threaded_rpc = ccnet.CcnetThreadedRpcClient(pool, req_pool=True) seafserv_rpc = seafile.ServerRpcClient(pool, req_pool=True) seafserv_threaded_rpc = seafile.ServerThreadedRpcClient(pool, req_pool=True) # load ccnet server addr and port from ccnet.conf. # 'addr:port' is used when downloading a repo config = ConfigParser.ConfigParser() config.read(os.path.join(SEAFILE_CENTRAL_CONF_DIR if SEAFILE_CENTRAL_CONF_DIR else CCNET_CONF_PATH, 'ccnet.conf')) if config.has_option('General', 'SERVICE_URL'): service_url = config.get('General', 'SERVICE_URL') hostname = urlparse(service_url).hostname
def __init__(self): pool = ccnet.ClientPool(CCNET_CONF_DIR, central_config_dir=SEAFILE_CENTRAL_CONF_DIR) self.ccnet_threaded_rpc = ccnet.CcnetThreadedRpcClient(pool, req_pool=True) self.session_cls = seahub_db.init_db_session_class()
def __init__(self): import ccnet ccnet_dir = os.environ['CCNET_CONF_DIR'] central_config_dir = os.environ['SEAFILE_CENTRAL_CONF_DIR'] self.rpc_client = ccnet.CcnetThreadedRpcClient( ccnet.ClientPool(ccnet_dir, central_config_dir=central_config_dir))
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)
def __init__(self): import ccnet ccnet_dir = os.environ['CCNET_CONF_DIR'] self.rpc_client = ccnet.CcnetThreadedRpcClient( ccnet.ClientPool(ccnet_dir))