Merge branch 'server-addr'

This commit is contained in:
lins05 2013-02-20 15:23:18 +08:00
commit cfe04ba245
11 changed files with 330 additions and 26 deletions

View File

@ -718,6 +718,84 @@ seafile_get_repo_property (const char *repo_id,
return value; return value;
} }
char *
seafile_get_repo_relay_address (const char *repo_id,
GError **error)
{
char *relay_addr = NULL;
if (!repo_id) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Arguments should not be empty");
return NULL;
}
seaf_repo_manager_get_repo_relay_info (seaf->repo_mgr, repo_id,
&relay_addr, NULL);
return relay_addr;
}
char *
seafile_get_repo_relay_port (const char *repo_id,
GError **error)
{
char *relay_port = NULL;
if (!repo_id) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Arguments should not be empty");
return NULL;
}
seaf_repo_manager_get_repo_relay_info (seaf->repo_mgr, repo_id,
NULL, &relay_port);
return relay_port;
}
int
seafile_update_repo_relay_info (const char *repo_id,
const char *new_addr,
const char *new_port,
GError **error)
{
if (!repo_id || !new_addr || !new_port) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Arguments should not be empty");
return -1;
}
int port = atoi(new_port);
if (port <= 0 || port > 65535) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Invalid port");
return -1;
}
SeafRepo *repo = seaf_repo_manager_get_repo (seaf->repo_mgr, repo_id);
if (!repo) {
return -1;
}
CcnetPeer *relay = ccnet_get_peer (seaf->ccnetrpc_client, repo->relay_id);
if (!relay) {
GString *buf = g_string_new(NULL);
g_string_append_printf (buf, "add-relay --id %s --addr %s:%s",
repo->relay_id, new_addr, new_port);
ccnet_send_command (seaf->session, buf->str, NULL, NULL);
g_string_free (buf, TRUE);
} else {
if (g_strcmp0(relay->public_addr, new_addr) != 0 ||
relay->public_port != (uint16_t)port) {
ccnet_update_peer_address (seaf->ccnetrpc_client, repo->relay_id,
new_addr, port);
}
g_object_unref (relay);
}
return seaf_repo_manager_update_repo_relay_info (seaf->repo_mgr, repo,
new_addr, new_port);
}
int int
seafile_calc_dir_size (const char *path, GError **error) seafile_calc_dir_size (const char *path, GError **error)
{ {

View File

@ -2688,3 +2688,35 @@ seaf_repo_manager_get_repo_relay_info (SeafRepoManager *mgr,
if (relay_port && port) if (relay_port && port)
*relay_port = port; *relay_port = port;
} }
int
seaf_repo_manager_update_repo_relay_info (SeafRepoManager *mgr,
SeafRepo *repo,
const char *new_addr,
const char *new_port)
{
GList *ptr, *repos = seaf_repo_manager_get_repo_list (seaf->repo_mgr, 0, -1);
SeafRepo *r;
for (ptr = repos; ptr; ptr = ptr->next) {
r = ptr->data;
if (g_strcmp0(r->relay_id, repo->relay_id) != 0)
continue;
char *relay_addr = NULL;
char *relay_port = NULL;
seaf_repo_manager_get_repo_relay_info (seaf->repo_mgr, r->id,
&relay_addr, &relay_port);
if (g_strcmp0(relay_addr, new_addr) != 0 ||
g_strcmp0(relay_port, new_port) != 0) {
seaf_repo_manager_set_repo_relay_info (seaf->repo_mgr, r->id,
new_addr, new_port);
}
g_free (relay_addr);
g_free (relay_port);
}
g_list_free (repos);
return 0;
}

View File

@ -343,5 +343,9 @@ seaf_repo_manager_add_recheckout_task (SeafRepoManager *mgr,
CheckoutTask * CheckoutTask *
seaf_repo_manager_get_checkout_task (SeafRepoManager *mgr, seaf_repo_manager_get_checkout_task (SeafRepoManager *mgr,
const char *repo_id); const char *repo_id);
int
seaf_repo_manager_update_repo_relay_info (SeafRepoManager *mgr,
SeafRepo *repo,
const char *new_addr,
const char *new_port);
#endif #endif

View File

@ -128,6 +128,21 @@ start_rpc_service (CcnetClient *client)
"seafile_get_repo_property", "seafile_get_repo_property",
searpc_signature_string__string_string()); searpc_signature_string__string_string());
searpc_server_register_function ("seafile-rpcserver",
seafile_get_repo_relay_address,
"seafile_get_repo_relay_address",
searpc_signature_string__string());
searpc_server_register_function ("seafile-rpcserver",
seafile_get_repo_relay_port,
"seafile_get_repo_relay_port",
searpc_signature_string__string());
searpc_server_register_function ("seafile-rpcserver",
seafile_update_repo_relay_info,
"seafile_update_repo_relay_info",
searpc_signature_int__string_string_string());
searpc_server_register_function ("seafile-rpcserver", searpc_server_register_function ("seafile-rpcserver",
seafile_disable_auto_sync, seafile_disable_auto_sync,
"seafile_disable_auto_sync", "seafile_disable_auto_sync",

View File

@ -179,6 +179,12 @@ handle_seafile_notification (char *type, char *content)
char buf[1024]; char buf[1024];
if (strcmp(type, "transfer") == 0) { if (strcmp(type, "transfer") == 0) {
if (applet->auto_sync_disabled) {
/* When auto sync is disabled but there is clone task running,
* applet can still get "transfer" notification, but we don't
* rotate the icon */
return;
}
trayicon_rotate (TRUE); trayicon_rotate (TRUE);
if (content == NULL) { if (content == NULL) {

View File

@ -124,6 +124,20 @@ seafile_get_repo_property (const char *repo_id,
const char *key, const char *key,
GError **error); GError **error);
char *
seafile_get_repo_relay_address (const char *repo_id,
GError **error);
char *
seafile_get_repo_relay_port (const char *repo_id,
GError **error);
int
seafile_update_repo_relay_info (const char *repo_id,
const char *new_addr,
const char *new_port,
GError **error);
int seafile_disable_auto_sync (GError **error); int seafile_disable_auto_sync (GError **error);
int seafile_enable_auto_sync (GError **error); int seafile_enable_auto_sync (GError **error);

View File

@ -168,6 +168,21 @@ class SeafileRpcClient(ccnet.RpcClientBase):
pass pass
get_repo_property = seafile_get_repo_property get_repo_property = seafile_get_repo_property
@searpc_func("string", ["string"])
def seafile_get_repo_relay_address(repo_id):
pass
get_repo_relay_address = seafile_get_repo_relay_address
@searpc_func("string", ["string"])
def seafile_get_repo_relay_port(repo_id):
pass
get_repo_relay_port = seafile_get_repo_relay_port
@searpc_func("int", ["string", "string", "string"])
def seafile_update_repo_relay_info(repo_id, addr, port):
pass
update_repo_relay_info = seafile_update_repo_relay_info
@searpc_func("int", ["string", "string"]) @searpc_func("int", ["string", "string"])
def seafile_set_repo_token(repo_id, token): def seafile_set_repo_token(repo_id, token):
pass pass

View File

@ -5,7 +5,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2013-01-16 20:21+CST\n" "POT-Creation-Date: 2013-02-01 10:10+CST\n"
"PO-Revision-Date: 2012-11-04 11:07+0800\n" "PO-Revision-Date: 2012-11-04 11:07+0800\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -15,44 +15,44 @@ msgstr ""
"Content-Transfer-Encoding: UTF-8\n" "Content-Transfer-Encoding: UTF-8\n"
"Generated-By: pygettext.py 1.5\n" "Generated-By: pygettext.py 1.5\n"
#: main.py:576 main.py:698 #: main.py:580 main.py:702
msgid "You must choose a local directory" msgid "You must choose a local directory"
msgstr "你必须指定一个本地目录" msgstr "你必须指定一个本地目录"
#: main.py:578 main.py:700 #: main.py:582 main.py:704
msgid "Password can not be empty" msgid "Password can not be empty"
msgstr "密码不能为空" msgstr "密码不能为空"
#: main.py:580 main.py:702 #: main.py:584 main.py:706
msgid "Invalid Repo ID" msgid "Invalid Repo ID"
msgstr "资料库ID格式不正确" msgstr "资料库ID格式不正确"
#: main.py:615 main.py:734 #: main.py:619 main.py:738
msgid "Invalid local directory" msgid "Invalid local directory"
msgstr "不是合法的本地目录" msgstr "不是合法的本地目录"
#: main.py:617 main.py:736 #: main.py:621 main.py:740
msgid "" msgid ""
"The local directory you chose is in sync with another repo. Please choose " "The local directory you chose is in sync with another repo. Please choose "
"another one." "another one."
msgstr "你所指定的本地目录已经与其他资料库同步,请指定其他本地目录" msgstr "你所指定的本地目录已经与其他资料库同步,请指定其他本地目录"
#: main.py:619 main.py:738 #: main.py:623 main.py:742
msgid "" msgid ""
"The local directory you chose cannot be under or includes a system directory " "The local directory you chose cannot be under or includes a system directory "
"of seafile." "of seafile."
msgstr "本地目录的路径不能处在 Seafile 系统目录下,或者包含 Seafile 系统目录" msgstr "本地目录的路径不能处在 Seafile 系统目录下,或者包含 Seafile 系统目录"
#: main.py:621 main.py:740 #: main.py:625 main.py:744
msgid "" msgid ""
"The local directory you chose cannot be under or includes another library." "The local directory you chose cannot be under or includes another library."
msgstr "本地目录的路径不能处在其他资料库目录下,或者包含其他资料库目录" msgstr "本地目录的路径不能处在其他资料库目录下,或者包含其他资料库目录"
#: main.py:623 main.py:742 #: main.py:627 main.py:746
msgid "Incorrect password." msgid "Incorrect password."
msgstr "密码错误" msgstr "密码错误"
#: main.py:625 main.py:744 templates/clone_tasks.html:69 #: main.py:629 main.py:748 templates/clone_tasks.html:69
msgid "Internal error." msgid "Internal error."
msgstr "内部错误" msgstr "内部错误"
@ -148,7 +148,7 @@ msgstr "合并更改失败"
msgid "Incorrect password. Please download again." msgid "Incorrect password. Please download again."
msgstr "密码错误。请重新下载。" msgstr "密码错误。请重新下载。"
#: templates/clone_tasks.html:76 templates/repo.html:93 #: templates/clone_tasks.html:76 templates/repo.html:94
msgid "Cancel" msgid "Cancel"
msgstr "取消" msgstr "取消"
@ -359,58 +359,92 @@ msgstr "操作"
msgid "Sync Now" msgid "Sync Now"
msgstr "立即同步" msgstr "立即同步"
#: templates/repo.html:19 templates/repo.html:92 #: templates/repo.html:19 templates/repo.html:93
msgid "Unsync" msgid "Unsync"
msgstr "解除同步" msgstr "解除同步"
#: templates/repo.html:31 #: templates/repo.html:20
msgid "Edit server address"
msgstr "编辑服务器地址"
#: templates/repo.html:32
msgid "Encrypted" msgid "Encrypted"
msgstr "已加密" msgstr "已加密"
#: templates/repo.html:39 #: templates/repo.html:40
msgid "Local Path:" msgid "Local Path:"
msgstr "本地路径:" msgstr "本地路径:"
#: templates/repo.html:42 #: templates/repo.html:43
msgid "Sync Info" msgid "Sync Info"
msgstr "同步信息" msgstr "同步信息"
#: templates/repo.html:46 #: templates/repo.html:47
msgid "Server: " msgid "Server: "
msgstr "服务器:" msgstr "服务器:"
#: templates/repo.html:52 #: templates/repo.html:53
msgid "Password: " msgid "Password: "
msgstr "密码:" msgstr "密码:"
#: templates/repo.html:53 #: templates/repo.html:54
msgid "Show" msgid "Show"
msgstr "显示" msgstr "显示"
#: templates/repo.html:59 templates/repo.html:61 #: templates/repo.html:60 templates/repo.html:62
msgid "Auto Sync: " msgid "Auto Sync: "
msgstr "自动同步:" msgstr "自动同步:"
#: templates/repo.html:74 templates/repo.html:76 #: templates/repo.html:75 templates/repo.html:77
msgid "transfered" msgid "transfered"
msgstr "已完成" msgstr "已完成"
#: templates/repo.html:79 #: templates/repo.html:80
msgid "rate" msgid "rate"
msgstr "速率" msgstr "速率"
#: templates/repo.html:79 #: templates/repo.html:80
msgid "s" msgid "s"
msgstr "秒" msgstr "秒"
#: templates/repo.html:85 #: templates/repo.html:86
msgid "Library transfer error:" msgid "Library transfer error:"
msgstr "资料库传输出错:" msgstr "资料库传输出错:"
#: templates/repo.html:91 #: templates/repo.html:92
msgid "Really want to unsync this library?" msgid "Really want to unsync this library?"
msgstr "确定要解除同步?" msgstr "确定要解除同步?"
#: templates/repo.html:98
msgid "Edit Server address"
msgstr "编辑服务器地址"
#: templates/repo.html:100
msgid "Warning:"
msgstr "警告:"
#: templates/repo.html:100
msgid ""
"You should only edit the server address when you're sure the server has used "
"a new address. Otherwise it may make the libraries unable to be "
"synchronized. After edit the address, you should restart seafile for the "
"changes to take effect."
msgstr ""
"仅当服务器的地址确实发生了改变时,你才应该在这里编辑它。否则将可能导致你的资"
"料库无法同步。修改地址后,请重启 Seafile 以使其生效。"
#: templates/repo.html:104
msgid "server name"
msgstr "服务器"
#: templates/repo.html:109
msgid "server address"
msgstr "地址"
#: templates/repo.html:113
msgid "server port"
msgstr "端口"
#: templates/repo_download.html:8 templates/repo_sync.html:8 #: templates/repo_download.html:8 templates/repo_sync.html:8
msgid "Library already exists." msgid "Library already exists."
msgstr "该资料库已存在。" msgstr "该资料库已存在。"

View File

@ -223,12 +223,16 @@ class repo:
relay = get_relay_of_repo(repo) relay = get_relay_of_repo(repo)
relay_addr = seafile_rpc.get_repo_relay_address(repo_id)
relay_port = seafile_rpc.get_repo_relay_port(repo_id)
return render.repo(repo=repo, return render.repo(repo=repo,
recent_commits=recent_commits, recent_commits=recent_commits,
relay=relay, relay=relay,
relay_addr=relay_addr,
relay_port=relay_port,
**default_options) **default_options)
def GET(self): def GET(self):
inputs = web.webapi.input(repo='') inputs = web.webapi.input(repo='')
return self.show_repo(inputs.repo) return self.show_repo(inputs.repo)
@ -431,6 +435,13 @@ class repo_operation:
if passwd: if passwd:
seafile_rpc.set_repo_passwd(repo.props.id, passwd) seafile_rpc.set_repo_passwd(repo.props.id, passwd)
elif op == 'edit-relay':
inputs = web.webapi.input(relay_addr='', relay_port='')
if inputs.relay_addr and inputs.relay_port:
seafile_rpc.update_repo_relay_info(repo_id,
inputs.relay_addr,
inputs.relay_port)
referer = web.ctx.env.get('HTTP_REFERER', '/home/') referer = web.ctx.env.get('HTTP_REFERER', '/home/')
raise web.seeother(referer) raise web.seeother(referer)

View File

@ -307,3 +307,33 @@ a.relay-link {
#set-sync-btn { #set-sync-btn {
vertical-align:middle; vertical-align:middle;
} }
#edit-relay-form h2 {
margin: 5px 0 10px 0;
}
#edit-relay-form .warning {
width: 400px;
margin-bottom: 10px;
}
#edit-relay-form label {
display: block;
float: left;
width: 7em;
text-align: right;
margin-right: 10px;
}
#edit-relay-form input {
padding: 3px;
}
#edit-relay-form .form-row {
margin-bottom: 5px;
}
#edit-relay-submit {
float: right;
margin-right: 20px;
}

View File

@ -17,6 +17,7 @@
<ul> <ul>
<li><a id="do-sync-link" href="/repos/operation/?repo=${repo.props.id}&op=sync">${_("Sync Now")}</a></li> <li><a id="do-sync-link" href="/repos/operation/?repo=${repo.props.id}&op=sync">${_("Sync Now")}</a></li>
<li><a href="#" id="delete">${_("Unsync")}</a></li> <li><a href="#" id="delete">${_("Unsync")}</a></li>
<li><a href="#" id="edit-relay">${_("Edit server address")}</a></li>
</ul> </ul>
</div> </div>
</div> <!-- nav-panel --> </div> <!-- nav-panel -->
@ -92,6 +93,29 @@
<button id="remove-repo-btn" data="/repos/operation/?repo=${repo.props.id}&op=remove">${_("Unsync")}</button> <button id="remove-repo-btn" data="/repos/operation/?repo=${repo.props.id}&op=remove">${_("Unsync")}</button>
<button class="simplemodal-close">${_("Cancel")}</button> <button class="simplemodal-close">${_("Cancel")}</button>
</div> </div>
<form id="edit-relay-form" method="POST" action="/repos/operation/?repo=${repo.props.id}&op=edit-relay" class="hide">
<h2>${_("Edit Server address")}</h2>
<p class="warning">
<strong>${_("Warning:")}</strong> ${_("You should only edit the server address when you're sure the server has used a new address. Otherwise it may make the libraries unable to be synchronized. After edit the address, you should restart seafile for the changes to take effect.")}
</p>
% if relay and relay.name:
<div class="form-row">
<label for="relay_name">${_("server name")}</label>
<span>${relay.name}</span>
</div>
% endif
<div class="form-row">
<label for="relay_addr">${_("server address")}</label>
<input type="text" name="relay_addr" value="${relay_addr}" maxlength="40" />
</div>
<div class="form-row">
<label for="relay_port">${_("server port")}</label>
<input type="text" name="relay_port" value="${relay_port}" maxlength="5" />
</div>
<p id="edit-relay-error" class="error"></p>
<input type="submit" id="edit-relay-submit" value="${_("Submit")}" />
</div>
</div> </div>
</div> </div>
</%def> </%def>
@ -108,6 +132,47 @@ $("#delete").click(function() {
return false; return false;
}); });
$('#edit-relay').click(function() {
$("#edit-relay-form").modal({appendTo: "#main"});
return false;
});
$('#edit-relay-form').submit(function() {
var addr = $('input[name="relay_addr"]').val();
var port = $('input[name="relay_port"]').val();
var addr_re = /^[a-z0-9-]+(\.[a-z0-9-]+)+$/;
var port_re = /^[\d]+$/;
var show_error = function(msg) {
$('#edit-relay-error').html(msg);
$("#simplemodal-container").css({'height':'auto'});
};
if (!addr) {
show_error('${_("server address can not be empty")}');
return false;
} else if (!addr_re.test(addr)) {
show_error('${_("server address is invalid")}');
return false;
}
if (!port) {
show_error('${_("server port can not be empty")}');
return false;
} else if (!port_re.test(port)) {
show_error('${_("server port is invalid")}');
return false;
} else {
port = Number(port);
if (isNaN(port) || port < 0 || port > 65535) {
show_error('${_("server port is invalid")}');
return false;
}
}
return true;
});
// revert dialog // revert dialog
var revert_commit = ""; var revert_commit = "";
$("a.revert-link").bind('click', function() { $("a.revert-link").bind('click', function() {