mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-01 23:20:51 +00:00
Added SEAFILE_CONF_DIR environment var, and remove max_upload_file_size and http_server_root from settings
This commit is contained in:
@@ -169,7 +169,6 @@ REST_FRAMEWORK = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# file and path
|
# file and path
|
||||||
MAX_UPLOAD_FILE_SIZE = 100 * 1024 * 1024 # 100 MB
|
|
||||||
MAX_UPLOAD_FILE_NAME_LEN = 255
|
MAX_UPLOAD_FILE_NAME_LEN = 255
|
||||||
MAX_FILE_NAME = MAX_UPLOAD_FILE_NAME_LEN
|
MAX_FILE_NAME = MAX_UPLOAD_FILE_NAME_LEN
|
||||||
MAX_PATH = 4096
|
MAX_PATH = 4096
|
||||||
@@ -180,9 +179,6 @@ ACTIVATE_AFTER_REGISTRATION = True
|
|||||||
# In order to use email sending, `ACTIVATE_AFTER_REGISTRATION` must set to False
|
# In order to use email sending, `ACTIVATE_AFTER_REGISTRATION` must set to False
|
||||||
REGISTRATION_SEND_MAIL = False
|
REGISTRATION_SEND_MAIL = False
|
||||||
|
|
||||||
# Seafile httpserver address and port
|
|
||||||
HTTP_SERVER_ROOT = "http://localhost:8082"
|
|
||||||
|
|
||||||
# Seafile-applet address and port, used in repo download
|
# Seafile-applet address and port, used in repo download
|
||||||
CCNET_APPLET_ROOT = "http://localhost:13420"
|
CCNET_APPLET_ROOT = "http://localhost:13420"
|
||||||
|
|
||||||
|
@@ -28,7 +28,8 @@ from service import create_org, get_orgs_by_user, get_org_by_url_prefix, \
|
|||||||
|
|
||||||
from service import get_related_users_by_repo, get_related_users_by_org_repo
|
from service import get_related_users_by_repo, get_related_users_by_org_repo
|
||||||
|
|
||||||
from service import CCNET_CONF_PATH, CCNET_SERVER_ADDR, CCNET_SERVER_PORT
|
from service import CCNET_CONF_PATH, CCNET_SERVER_ADDR, CCNET_SERVER_PORT, \
|
||||||
|
MAX_UPLOAD_FILE_SIZE, HTTP_SERVER_ROOT
|
||||||
|
|
||||||
from htmldiff import HtmlDiff
|
from htmldiff import HtmlDiff
|
||||||
|
|
||||||
|
@@ -42,20 +42,24 @@ import ccnet
|
|||||||
import seafile
|
import seafile
|
||||||
from pysearpc import SearpcError
|
from pysearpc import SearpcError
|
||||||
|
|
||||||
if 'win' in sys.platform:
|
ENVIRONMENT_VARIABLES = ('CCNET_CONF_DIR', 'SEAFILE_CONF_DIR')
|
||||||
DEFAULT_CCNET_CONF_PATH = "~/ccnet"
|
|
||||||
else:
|
|
||||||
DEFAULT_CCNET_CONF_PATH = "~/.ccnet"
|
|
||||||
|
|
||||||
if 'CCNET_CONF_DIR' in os.environ:
|
# Used to fix bug in some rpc calls, will be removed in near future.
|
||||||
CCNET_CONF_PATH = os.environ['CCNET_CONF_DIR']
|
|
||||||
else:
|
|
||||||
CCNET_CONF_PATH = DEFAULT_CCNET_CONF_PATH
|
|
||||||
|
|
||||||
print "Load config from " + CCNET_CONF_PATH
|
|
||||||
CCNET_CONF_PATH = os.path.normpath(os.path.expanduser(CCNET_CONF_PATH))
|
|
||||||
MAX_INT = 2147483647
|
MAX_INT = 2147483647
|
||||||
|
|
||||||
|
### 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)
|
pool = ccnet.ClientPool(CCNET_CONF_PATH)
|
||||||
ccnet_rpc = ccnet.CcnetRpcClient(pool, req_pool=True)
|
ccnet_rpc = ccnet.CcnetRpcClient(pool, req_pool=True)
|
||||||
ccnet_threaded_rpc = ccnet.CcnetThreadedRpcClient(pool, req_pool=True)
|
ccnet_threaded_rpc = ccnet.CcnetThreadedRpcClient(pool, req_pool=True)
|
||||||
@@ -65,12 +69,12 @@ seafserv_threaded_rpc = seafile.ServerThreadedRpcClient(pool, req_pool=True)
|
|||||||
|
|
||||||
# load ccnet server addr and port from ccnet.conf.
|
# load ccnet server addr and port from ccnet.conf.
|
||||||
# 'addr:port' is used when downloading a repo
|
# 'addr:port' is used when downloading a repo
|
||||||
ccnet_config = ConfigParser.ConfigParser()
|
config = ConfigParser.ConfigParser()
|
||||||
ccnet_config.read(os.path.join(CCNET_CONF_PATH, 'ccnet.conf'))
|
config.read(os.path.join(CCNET_CONF_PATH, 'ccnet.conf'))
|
||||||
|
|
||||||
if ccnet_config.has_option('General', 'SERVICE_URL') and \
|
if config.has_option('General', 'SERVICE_URL') and \
|
||||||
ccnet_config.has_option('Network', 'PORT'):
|
config.has_option('Network', 'PORT'):
|
||||||
service_url = ccnet_config.get('General', 'SERVICE_URL')
|
service_url = config.get('General', 'SERVICE_URL')
|
||||||
service_url = service_url.lstrip('http://').lstrip('https://')
|
service_url = service_url.lstrip('http://').lstrip('https://')
|
||||||
if ':' in service_url:
|
if ':' in service_url:
|
||||||
# strip http port such as ':8000' in 'http://192.168.1.101:8000'
|
# strip http port such as ':8000' in 'http://192.168.1.101:8000'
|
||||||
@@ -82,12 +86,40 @@ if ccnet_config.has_option('General', 'SERVICE_URL') and \
|
|||||||
service_url = service_url[:idx]
|
service_url = service_url[:idx]
|
||||||
|
|
||||||
CCNET_SERVER_ADDR = service_url
|
CCNET_SERVER_ADDR = service_url
|
||||||
CCNET_SERVER_PORT = ccnet_config.get('Network', 'PORT')
|
CCNET_SERVER_PORT = config.get('Network', 'PORT')
|
||||||
else:
|
else:
|
||||||
print "Warning: SERVICE_URL not set in ccnet.conf"
|
print "Warning: SERVICE_URL not set in ccnet.conf"
|
||||||
CCNET_SERVER_ADDR = None
|
CCNET_SERVER_ADDR = None
|
||||||
CCNET_SERVER_PORT = None
|
CCNET_SERVER_PORT = None
|
||||||
|
|
||||||
|
'''seafile'''
|
||||||
|
try:
|
||||||
|
SEAFILE_CONF_DIR = os.environ[ENVIRONMENT_VARIABLES[1]]
|
||||||
|
if not SEAFILE_CONF_DIR: # 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[1])
|
||||||
|
else:
|
||||||
|
print "Loading seafile config from " + SEAFILE_CONF_DIR
|
||||||
|
|
||||||
|
SEAFILE_CONF_DIR = os.path.normpath(os.path.expanduser(SEAFILE_CONF_DIR))
|
||||||
|
config.read(os.path.join(SEAFILE_CONF_DIR, 'seafile.conf'))
|
||||||
|
|
||||||
|
MAX_UPLOAD_FILE_SIZE = 100 * (2 ** 20) # Default max upload size, set in httpserver.c
|
||||||
|
if config.has_option('httpserver', 'max_upload_size'):
|
||||||
|
try:
|
||||||
|
max_upload_size_mb = config.getint('httpserver', 'max_upload_size')
|
||||||
|
if max_upload_size_mb > 0:
|
||||||
|
MAX_UPLOAD_FILE_SIZE = max_upload_size_mb * (2 ** 20)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if CCNET_SERVER_ADDR:
|
||||||
|
port = config.get('httpserver', 'port') if \
|
||||||
|
config.has_option('httpserver', 'port') else '8082'
|
||||||
|
HTTP_SERVER_ROOT = CCNET_SERVER_ADDR + ':' + port
|
||||||
|
else:
|
||||||
|
HTTP_SERVER_ROOT = None
|
||||||
|
|
||||||
#### Basic ccnet API ####
|
#### Basic ccnet API ####
|
||||||
|
|
||||||
|
@@ -22,7 +22,8 @@ from seaserv import seafserv_rpc, ccnet_threaded_rpc, seafserv_threaded_rpc, \
|
|||||||
CCNET_SERVER_PORT, get_org_id_by_repo_id, get_org_by_id, is_org_staff, \
|
CCNET_SERVER_PORT, get_org_id_by_repo_id, get_org_by_id, is_org_staff, \
|
||||||
get_org_id_by_group, list_personal_shared_repos, get_org_group_repos,\
|
get_org_id_by_group, list_personal_shared_repos, get_org_group_repos,\
|
||||||
get_personal_groups_by_user, list_personal_repos_by_owner, get_group_repos, \
|
get_personal_groups_by_user, list_personal_repos_by_owner, get_group_repos, \
|
||||||
list_org_repos_by_owner, get_org_groups_by_user, check_permission
|
list_org_repos_by_owner, get_org_groups_by_user, check_permission, \
|
||||||
|
HTTP_SERVER_ROOT
|
||||||
try:
|
try:
|
||||||
from settings import DOCUMENT_CONVERTOR_ROOT
|
from settings import DOCUMENT_CONVERTOR_ROOT
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@@ -95,15 +96,10 @@ def list_to_string(l):
|
|||||||
|
|
||||||
def get_httpserver_root():
|
def get_httpserver_root():
|
||||||
"""
|
"""
|
||||||
Get seafile http server address and port from settings.py,
|
Get seafile http server address and port from seaserv.
|
||||||
and cut out last '/'.
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if settings.HTTP_SERVER_ROOT[-1] == '/':
|
return HTTP_SERVER_ROOT if HTTP_SERVER_ROOT else ''
|
||||||
http_server_root = settings.HTTP_SERVER_ROOT[:-1]
|
|
||||||
else:
|
|
||||||
http_server_root = settings.HTTP_SERVER_ROOT
|
|
||||||
return http_server_root
|
|
||||||
|
|
||||||
def get_ccnetapplet_root():
|
def get_ccnetapplet_root():
|
||||||
"""
|
"""
|
||||||
|
4
views.py
4
views.py
@@ -45,7 +45,7 @@ from seaserv import ccnet_rpc, ccnet_threaded_rpc, get_repos, get_emailusers, \
|
|||||||
get_org_repo_owner, is_passwd_set, get_file_size, check_quota, \
|
get_org_repo_owner, is_passwd_set, get_file_size, check_quota, \
|
||||||
get_related_users_by_repo, get_related_users_by_org_repo, HtmlDiff, \
|
get_related_users_by_repo, get_related_users_by_org_repo, HtmlDiff, \
|
||||||
get_session_info, get_group_repoids, get_repo_owner, get_file_id_by_path, \
|
get_session_info, get_group_repoids, get_repo_owner, get_file_id_by_path, \
|
||||||
get_repo_history_limit, set_repo_history_limit
|
get_repo_history_limit, set_repo_history_limit, MAX_UPLOAD_FILE_SIZE
|
||||||
from pysearpc import SearpcError
|
from pysearpc import SearpcError
|
||||||
|
|
||||||
from signals import repo_created, repo_deleted
|
from signals import repo_created, repo_deleted
|
||||||
@@ -333,7 +333,7 @@ class RepoView(LoginRequiredMixin, CtxSwitchRequiredMixin, RepoMixin,
|
|||||||
return True if check_quota(self.repo_id) < 0 else False
|
return True if check_quota(self.repo_id) < 0 else False
|
||||||
|
|
||||||
def get_max_upload_file_size(self):
|
def get_max_upload_file_size(self):
|
||||||
return settings.MAX_UPLOAD_FILE_SIZE
|
return MAX_UPLOAD_FILE_SIZE
|
||||||
|
|
||||||
def get_upload_url(self):
|
def get_upload_url(self):
|
||||||
if get_user_permission(self.request, self.repo_id) == 'rw':
|
if get_user_permission(self.request, self.repo_id) == 'rw':
|
||||||
|
Reference in New Issue
Block a user