diff --git a/lib/net.c b/lib/net.c index c233d9823..464e212d2 100644 --- a/lib/net.c +++ b/lib/net.c @@ -1,6 +1,10 @@ /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ #ifdef WIN32 #define WINVER 0x0501 + #include + #include + #include + #include #endif #include "include.h" @@ -12,10 +16,6 @@ #ifdef WIN32 - #include - #include - #include - #include #define UNUSED #else #include diff --git a/scripts/upgrade/win32/py/gc.py b/scripts/upgrade/win32/py/gc.py index c436cb66b..c609f4a10 100644 --- a/scripts/upgrade/win32/py/gc.py +++ b/scripts/upgrade/win32/py/gc.py @@ -5,22 +5,18 @@ import traceback import ccnet -from upgrade_common import install_path, seafile_dir, ccnet_dir, run_argv +from upgrade_common import install_path, seafile_dir, ccnet_dir, run_argv, ensure_server_not_running, central_config_dir -def ensure_server_not_running(): - client = ccnet.SyncClient(ccnet_dir) - try: - client.connect_daemon() - except ccnet.NetworkError: - pass - else: - raise Exception('Seafile server is running! You must turn it off before gc!') def call_seafserv_gc(): args = [ os.path.join(install_path, 'seafile', 'bin', 'seafserv-gc.exe'), - '-c', ccnet_dir, - '-d', seafile_dir, + '-c', + ccnet_dir, + '-d', + seafile_dir, + '-F', + central_config_dir, ] print 'Starting gc...\n' @@ -39,5 +35,6 @@ def main(): print '\nprint ENTER to exit\n' raw_input() + if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/scripts/upgrade/win32/py/upgrade_4.3_4.4.py b/scripts/upgrade/win32/py/upgrade_4.3_4.4.py deleted file mode 100644 index 822ac6f93..000000000 --- a/scripts/upgrade/win32/py/upgrade_4.3_4.4.py +++ /dev/null @@ -1,19 +0,0 @@ -# coding: UTF-8 - -import os - -from upgrade_common import install_path, ccnet_dir, seafile_dir, upgrade_db, run_argv - -def main(): - try: - upgrade_db('4.4.0') - except Exception, e: - print 'Error:\n', e - else: - print '\ndone\n' - finally: - print '\nprint ENTER to exit\n' - raw_input() - -if __name__ == '__main__': - main() diff --git a/scripts/upgrade/win32/py/upgrade_4.3_5.0.py b/scripts/upgrade/win32/py/upgrade_4.3_5.0.py new file mode 100644 index 000000000..0c8073147 --- /dev/null +++ b/scripts/upgrade/win32/py/upgrade_4.3_5.0.py @@ -0,0 +1,49 @@ +# coding: UTF-8 + +import shutil +import os +import traceback +from os.path import abspath, basename, exists, dirname, join +from upgrade_common import (install_path, seafserv_dir, ccnet_dir, seafile_dir, + upgrade_db, run_argv) + + +def move_all_conf_to_central_config_dir(): + central_config_dir = join(seafserv_dir, 'conf') + if not exists(central_config_dir): + os.mkdir(central_config_dir) + files = [ + join(ccnet_dir, 'ccnet.conf'), + join(seafile_dir, 'seafile.conf'), + join(seafserv_dir, 'seahub_settings.py'), + ] + for fn in files: + if not exists(fn): + raise RuntimeError('file %s does not exist' % fn) + for fn in files: + with open(fn, 'r') as fp: + if 'This file has been moved' in fp.read(): + return + dstfile = join(central_config_dir, basename(fn)) + shutil.copyfile(fn, dstfile) + with open(fn, 'w') as fp: + content = '# This file has been moved to %s in seafile 5.0.0' % dstfile + fp.write(content) + + +def main(): + try: + upgrade_db('5.0.0') + move_all_conf_to_central_config_dir() + except Exception, e: + traceback.print_exc() + print 'Error:\n', e + else: + print '\ndone\n' + finally: + print '\nprint ENTER to exit\n' + raw_input() + + +if __name__ == '__main__': + main() diff --git a/scripts/upgrade/win32/py/upgrade_common.py b/scripts/upgrade/win32/py/upgrade_common.py index 4f8b6b0e5..7564cea45 100644 --- a/scripts/upgrade/win32/py/upgrade_common.py +++ b/scripts/upgrade/win32/py/upgrade_common.py @@ -7,6 +7,7 @@ import ccnet import glob + # Directory layout: # # - SeafileProgram/ @@ -36,6 +37,7 @@ seafserv_dir = '' ccnet_dir = '' seafile_dir = '' +central_config_dir = '' def run_argv(argv, cwd=None, env=None, suppress_stdout=False, suppress_stderr=False): '''Run a program and wait it to finish, and return its exit code. The @@ -65,7 +67,7 @@ def error(message): sys.exit(1) def read_seafserv_dir(): - global seafserv_dir, ccnet_dir, seafile_dir + global seafserv_dir, ccnet_dir, seafile_dir, central_config_dir seafserv_ini = os.path.join(program_top_dir, 'seafserv.ini') if not os.path.exists(seafserv_ini): error('%s not found' % seafserv_ini) @@ -75,6 +77,7 @@ def read_seafserv_dir(): ccnet_dir = os.path.join(seafserv_dir, 'ccnet') seafile_dir = os.path.join(seafserv_dir, 'seafile-data') + central_config_dir = os.path.join(seafserv_dir, 'conf') def apply_sqls(db_path, sql_path): with open(sql_path, 'r') as fp: @@ -132,8 +135,15 @@ def get_sql(prog): print ' upgrading seahub databases ...' apply_sqls(seahub_db, seahub_sql) +def get_current_version(): + return os.path.basename(install_path).split('-')[-1] + def ensure_server_not_running(): - client = ccnet.SyncClient(ccnet_dir) + if os.path.exists(os.path.join(central_config_dir, 'ccnet.conf')): + client = ccnet.SyncClient(ccnet_dir, + central_config_dir=central_config_dir) + else: + client = ccnet.SyncClient(ccnet_dir) try: client.connect_daemon() except ccnet.NetworkError: diff --git a/scripts/upgrade/win32/upgrade_4.3_4.4.bat b/scripts/upgrade/win32/upgrade_4.3_5.0.bat similarity index 68% rename from scripts/upgrade/win32/upgrade_4.3_4.4.bat rename to scripts/upgrade/win32/upgrade_4.3_5.0.bat index f4348f9a8..cb4d01d99 100644 --- a/scripts/upgrade/win32/upgrade_4.3_4.4.bat +++ b/scripts/upgrade/win32/upgrade_4.3_5.0.bat @@ -1,4 +1,4 @@ @echo off cd /d %~dp0 set PYTHONPATH=%PYTHONPATH%;%~dp0\..\seahub\thirdpart -start python py/upgrade_4.3_4.4.py +start python py/upgrade_4.3_5.0.py