From 59ade2b2081779a156c1719f57fb9606ba16c7fe Mon Sep 17 00:00:00 2001 From: AndreyTapekhin Date: Mon, 17 Apr 2017 21:19:35 +0300 Subject: [PATCH] sync groups --- lingvodoc/views/v2/sync.py | 2 +- pre_update.pyw | 20 ++++------ start.pyw | 11 +++--- update1.pyw | 80 +++++++++++++++++++------------------- update2.pyw | 15 +++---- 5 files changed, 61 insertions(+), 67 deletions(-) diff --git a/lingvodoc/views/v2/sync.py b/lingvodoc/views/v2/sync.py index cad8b0cc0..fb939b859 100644 --- a/lingvodoc/views/v2/sync.py +++ b/lingvodoc/views/v2/sync.py @@ -452,7 +452,7 @@ def diff_desk(request): for entry in upload_groups: group = DBSession.query(Group).filter_by(id=entry).first() - if group: + if group and group.subject_client_id and get_user_by_client_id(group.subject_client_id).id == user.id: path = central_server + 'group' gr_req = row2dict(group) gr_req['users']=[user.id] diff --git a/pre_update.pyw b/pre_update.pyw index 1800c3deb..94a5bda36 100644 --- a/pre_update.pyw +++ b/pre_update.pyw @@ -22,6 +22,7 @@ from PyQt5 import QtCore DETACHED_PROCESS = 8 cur_path = os.path.abspath(os.path.dirname(__file__)) +updater_path = cur_path + "\\updater" PG_DATA = "%s\\PostgreSQLPortable_9.6.1\\Data\\data" % cur_path @@ -87,11 +88,10 @@ class Worker(QObject): return status_code = 200 dump = file.raw - - with open('tmp.zip', 'wb') as file_type: + with open('updater\\tmp.zip', 'wb') as file_type: shutil.copyfileobj(dump, file_type) - with ZipFile('tmp.zip') as myzip: + with ZipFile('updater\\tmp.zip') as myzip: if myzip.testzip(): self.sig_err.emit( "Try again", @@ -249,9 +249,11 @@ class Example(QWidget): | QtCore.Qt.WindowMinimizeButtonHint | QtCore.Qt.WindowMaximizeButtonHint) self.changetext("Update in progress. Downloading sources.") + if not os.path.exists('updater'): + os.mkdir('updater') tag = 500353 # 0 - tag_path = "%s\\tag" % cur_path - new_tag_path = "%s\\new_tag" % cur_path + tag_path = "%s\\tag" % updater_path + new_tag_path = "%s\\new_tag" % updater_path if os.path.exists(tag_path): with open(tag_path, 'r') as tag_file: try: @@ -261,16 +263,8 @@ class Example(QWidget): else: with open(tag_path, 'w') as tag_file: tag_file.write(str(tag)) - postgres_backup = "%s\\postgres_data_backup" % cur_path - restore_lock = "%s\\restore_fail" % cur_path processes = [] try: - if os.path.exists(restore_lock): - if os.path.exists(postgres_backup): - restore(PG_DATA, postgres_backup) - os.remove(restore_lock) - remove(postgres_backup) - remove(PG_DATA + "_tmp") connection_string = "https://api.github.com/repos/ispras/lingvodoc/releases/latest" session = requests.Session() session.headers.update({'Connection': 'Keep-Alive'}) diff --git a/start.pyw b/start.pyw index 650d68391..e9ad058af 100644 --- a/start.pyw +++ b/start.pyw @@ -14,6 +14,7 @@ DETACHED_PROCESS = 8 DELAY = 2 cur_path = os.path.abspath(os.path.dirname(__file__)) +updater_path = cur_path + "\\updater" PG_DATA = "%s\\PostgreSQLPortable_9.6.1\\Data\\data" % cur_path PG_CTL = "%s\\PostgreSQLPortable_9.6.1\\App\\PgSQL\\bin\\pg_ctl.exe" % cur_path CHROME_PATH = "%s\\ChromiumPortable\\App\\Chromium\\32\\chrome.exe" % cur_path @@ -58,7 +59,7 @@ def main(): processes = list() try: # postgres_backup = "%s\\postgres_data_backup" % cur_path - restore_lock = "%s\\restore_fail" % cur_path + restore_lock = "%s\\restore_fail" % updater_path restore_fail = False processes = [] if os.path.exists(restore_lock): @@ -68,8 +69,8 @@ def main(): sys.exit(-1) python = cur_path + "\\env86\\python-3.4.4\\pythonw.exe" pserve = cur_path + "\\env86\\python-3.4.4\\Scripts\\pserve.exe" - memcached = cur_path + "\\new_memcached\\memcached.exe" - development = cur_path + "\\lingvodoc_desktop.ini" + memcached = cur_path + "\\memcached\\memcached.exe" + ini = cur_path + "\\lingvodoc_desktop.ini" venv = get_env() # if not os.path.exists(venv["PGDATA"]): # proc_0 = Popen('%s\\PostgreSQLPortable_9.6.1\\App\\PgSQL\\bin\\initdb.exe -U postgres -A trust -E utf8 --locale=C' % cur_path, env=venv, shell=True) @@ -85,8 +86,8 @@ def main(): # proc_2.terminate() sleep(5) my_env = os.environ.copy() - my_env["PATH"] = my_env["PATH"] + ";%s\\new_ffmpeg\\bin" % cur_path - proc_3 = Popen([python, pserve, development], env=my_env, creationflags=DETACHED_PROCESS) + my_env["PATH"] = my_env["PATH"] + ";%s\\ffmpeg\\bin" % cur_path + proc_3 = Popen([python, pserve, ini], env=my_env, creationflags=DETACHED_PROCESS) sleep(1) proc_4 = Popen([memcached], creationflags=DETACHED_PROCESS) sleep(1) diff --git a/update1.pyw b/update1.pyw index 869c1719e..10e068855 100644 --- a/update1.pyw +++ b/update1.pyw @@ -22,6 +22,7 @@ from PyQt5 import QtCore DETACHED_PROCESS = 8 cur_path = os.path.abspath(os.path.dirname(__file__)) +updater_path = cur_path + "\\updater" PG_DATA = "%s\\PostgreSQLPortable_9.6.1\\Data\\data" % cur_path @@ -65,10 +66,10 @@ class Worker(QObject): reunzip = True try: - file_type_hash_path = "%s_hash_%s" % (self.file_type, self.tag) - file_type_path = "%s_%s.zip" % (self.file_type, self.tag) - new_file_type_hash_path = "new_%s_hash" % self.file_type - new_file_type = 'new_%s' % self.file_type + file_type_hash_path = "%s\\%s_hash_%s" % (updater_path, self.file_type, self.tag) + file_type_path = "%s\\%s_%s.zip" % (updater_path, self.file_type, self.tag) + new_file_type_hash_path = "%s\\new_%s_hash" % (updater_path, self.file_type) + new_file_type = '%s\\new_%s' % (updater_path, self.file_type) if os.path.exists(file_type_hash_path) and os.path.exists(file_type_path): with open(file_type_hash_path, 'r') as file_type_hash: @@ -124,12 +125,12 @@ class Worker(QObject): ) status_code = -1 return - myzip.extractall() + myzip.extractall(path=updater_path) if os.path.exists(new_file_type): shutil.rmtree(new_file_type) - folder = cur_path + "\\" + folder.split('/')[0] + folder = updater_path + "\\" + folder.split('/')[0] # self.sig_progress.emit(50) - new_file_type = cur_path + "\\new_%s" % self.file_type + new_file_type = updater_path + "\\new_%s" % self.file_type # remove(new_file_type) os.rename(folder, new_file_type) @@ -138,10 +139,10 @@ class Worker(QObject): with open(new_file_type_hash_path, 'w') as file_type_hash: file_type_hash.write(folder_md5(new_file_type)) - for path in glob("%s_*.zip" % self.file_type): + for path in glob("%s\\%s_*.zip" % (updater_path, self.file_type)): if path != file_type_path: os.remove(path) - for path in glob("%s_hash_*" % self.file_type): + for path in glob("%s\\%s_hash_*" % (updater_path, self.file_type)): if path != file_type_hash_path: os.remove(path) # self.sig_msg.emit("Updating in progress. Sources Downloaded. Upgrading pip.") @@ -174,12 +175,11 @@ class Worker(QObject): self.sig_done.emit(status_code) return - def backup_control(filename): - if os.path.exists('new_source\\%s' % filename): + if os.path.exists('source\\%s' % filename): if os.path.exists(filename): - shutil.copy2(filename, 'backup_control\\%s' % filename) - shutil.copy2('new_source\\%s' % filename, filename) + shutil.copy2(filename, '%s\\backup_control\\%s' % (updater_path, filename)) + shutil.copy2('source\\%s' % filename, filename) class Example(QWidget): def __init__(self): @@ -309,8 +309,8 @@ class Example(QWidget): | QtCore.Qt.WindowMaximizeButtonHint) self.changetext("Update in progress. Downloading sources.") tag = 500353 # 0 - tag_path = "%s\\tag" % cur_path - new_tag_path = "%s\\new_tag" % cur_path + tag_path = "%s\\tag" % updater_path + new_tag_path = "%s\\new_tag" % updater_path if os.path.exists(tag_path): with open(tag_path, 'r') as tag_file: try: @@ -320,8 +320,8 @@ class Example(QWidget): else: with open(tag_path, 'w') as tag_file: tag_file.write(str(tag)) - postgres_backup = "%s\\postgres_data_backup" % cur_path - restore_lock = "%s\\restore_fail" % cur_path + postgres_backup = "%s\\postgres_data_backup" % updater_path + restore_lock = "%s\\restore_fail" % updater_path processes = [] try: if os.path.exists(restore_lock): @@ -387,26 +387,24 @@ class Example(QWidget): if ffmpeg: if self.workerLoop(ffmpeg, '3.2.4', 'ffmpeg', 'https://'): return - self.changetext("Updating in progress. Ffmpeg downloaded. Upgrading pip.") + self.changetext("Updating in progress. Ffmpeg downloaded. Updating packages") self.progress.setValue(50) - new_source = cur_path + "\\new_source" + if os.path.exists('ffmpeg'): + shutil.rmtree('ffmpeg') + shutil.copytree('%s\\new_ffmpeg' % updater_path, 'ffmpeg') + if os.path.exists('memcached'): + shutil.rmtree('memcached') + shutil.copytree('%s\\new_memcached' % updater_path, 'memcached') + if os.path.exists('source'): + shutil.rmtree('source') + shutil.copytree('%s\\new_source' % updater_path, 'source') + + new_source = cur_path + "\\source" pythonw = cur_path + "\\env86\\python-3.4.4\\pythonw.exe" setup = new_source + "\\desktop-setup.py" requirements = new_source + "\\desktop-requirements.txt" - proc = Popen([pythonw, '-m', 'pip', 'install', '--upgrade', 'pip'], stdout=PIPE, stderr=PIPE) - streamdata = proc.communicate()[1] - rc = proc.returncode - if rc != 0: - self.message( - "Try again", - "pip upgrade unsuccessful: %s" % streamdata.decode("utf-8") - ) - return - proc.terminate() - self.changetext("Updating in progress. Pip upgraded. Updating packages") - self.progress.setValue(55) self.loop.processEvents(QEventLoop.ExcludeUserInputEvents) proc = Popen([pythonw, '-m', 'pip', 'install', '-r', os.path.normpath(requirements)], stdout=PIPE, @@ -424,7 +422,7 @@ class Example(QWidget): self.progress.setValue(60) self.loop.processEvents(QEventLoop.ExcludeUserInputEvents) - proc = Popen([pythonw, setup, 'install'], stdout=PIPE, stderr=PIPE, cwd='%s\\new_source' % cur_path) + proc = Popen([pythonw, setup, 'install'], stdout=PIPE, stderr=PIPE, cwd='%s\\source' % cur_path) streamdata = proc.communicate()[1] rc = proc.returncode if rc != 0: @@ -438,20 +436,20 @@ class Example(QWidget): self.progress.setValue(65) self.loop.processEvents(QEventLoop.ExcludeUserInputEvents) - if not os.path.exists('backup_control'): - os.makedirs('backup_control') + if not os.path.exists('%s\\backup_control' % updater_path): + os.makedirs('%s\\backup_control' % updater_path) - if os.path.exists('new_source\\alembic.ini'): + if os.path.exists('%s\\alembic.ini' % new_source): backup_control('alembic.ini') - if os.path.exists('new_source\\alembic'): - if os.path.exists('new_source\\alembic'): + if os.path.exists('%s\\alembic' % new_source): + if os.path.exists('%s\\alembic' % new_source): if os.path.exists('alembic'): - if os.path.exists('backup_control\\%s' % 'alembic'): - shutil.rmtree('backup_control\\%s' % 'alembic') - shutil.copytree('alembic', 'backup_control\\%s' % 'alembic') + if os.path.exists('%s\\backup_control\\%s' % (updater_path, 'alembic')): + shutil.rmtree('%s\\backup_control\\%s' % (updater_path, 'alembic')) + shutil.copytree('alembic', '%s\\backup_control\\%s' % (updater_path, 'alembic')) shutil.rmtree('alembic') - shutil.copytree('new_source\\%s' % 'alembic', 'alembic') + shutil.copytree('%s\\%s' % (new_source, 'alembic'), 'alembic') proc = Popen([pythonw, "%s\\update2.pyw" % cur_path], creationflags=DETACHED_PROCESS, stdout=PIPE, stderr=PIPE) return diff --git a/update2.pyw b/update2.pyw index 666e80217..788e32ac0 100644 --- a/update2.pyw +++ b/update2.pyw @@ -34,6 +34,7 @@ DETACHED_PROCESS = 8 DELAY = 2 CUR_PATH = os.path.abspath(os.path.dirname(__file__)) +updater_path = CUR_PATH + "\\updater" PG_DATA = "%s\\PostgreSQLPortable_9.6.1\\Data\\data" % CUR_PATH PG_CTL = "%s\\PostgreSQLPortable_9.6.1\\App\\PgSQL\\bin\\pg_ctl.exe" % CUR_PATH CHROME_PATH = "%s\\ChromiumPortable\\App\\Chromium\\32\\chrome.exe" % CUR_PATH @@ -80,9 +81,9 @@ def remove(src): def backup_control(filename): - if os.path.exists('new_source\\%s' % filename): - shutil.copy2(filename, 'backup_control\\%s' % filename) - shutil.copy2('new_source\\%s' % filename, filename) + if os.path.exists('source\\%s' % filename): + shutil.copy2(filename, '%s\\backup_control\\%s' % (updater_path, filename)) + shutil.copy2('source\\%s' % filename, filename) class Example(QWidget): @@ -148,8 +149,8 @@ class Example(QWidget): info = STARTUPINFO() info.dwFlags = STARTF_USESHOWWINDOW info.wShowWindow = SW_HIDE - postgres_backup = "%s\\postgres_data_backup" % CUR_PATH - restore_lock = "%s\\restore_fail" % CUR_PATH + postgres_backup = "%s\\postgres_data_backup" % updater_path + restore_lock = "%s\\restore_fail" % updater_path restore_fail = False processes = [] try: @@ -172,7 +173,7 @@ class Example(QWidget): processes.append(proc) self.progress.setValue(75) self.loop.processEvents(QEventLoop.ExcludeUserInputEvents) - tag_path = "%s\\new_tag" % CUR_PATH + tag_path = "%s\\new_tag" % updater_path if os.path.exists(tag_path): with open(tag_path, 'r') as tag_file: try: @@ -227,7 +228,7 @@ class Example(QWidget): box = QMessageBox() box.move(50, 50) - with open("%s\\tag" % CUR_PATH, 'w') as tag_file: + with open("%s\\tag" % updater_path, 'w') as tag_file: tag_file.write(str(tag)) os.remove(tag_path) box = QMessageBox()