diff --git a/pyproject.toml b/pyproject.toml index c1e80606f..e50ade6f8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,7 +58,7 @@ dependencies = [ "WsgiDAV==4.3.0", "zipstream==1.1.4", "argon2-cffi == 23.1.0", - + # testing requirements and doc requirements "INGInious[doc]", ] @@ -91,9 +91,9 @@ inginious-webapp = "inginious.webapp:main" inginious-webdav = "inginious.webdav:main" inginious-install = "inginious.install:main" inginious-autotest = "inginious.autotest:main" -inginious-synchronize = "utils.sync.inginious-synchronize:main" -inginious-container-update = "utils.container_update.inginious-container-update:main" -inginious-database-update = "utils.database_updater.inginious-database-update:main" +inginious-synchronize = "utils.sync:main" +inginious-container-update = "utils.container_update:main" +inginious-database-update = "utils.database_updater:main" [project.urls] diff --git a/setup.py b/setup.py deleted file mode 100644 index 053691c18..000000000 --- a/setup.py +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -# -# This file is part of INGInious. See the LICENSE and the COPYRIGHTS files for -# more information about the licensing of this file. - -import sys -import os -from setuptools import setup, find_packages - - -scripts = [] if os.environ.get("INGINIOUS_COMPOSE") else [ - 'inginious-agent-docker', - 'inginious-agent-mcq', - 'inginious-backend', - 'inginious-webapp', - 'inginious-webdav', - 'inginious-install', - 'inginious-autotest', - 'utils/sync/inginious-synchronize', - 'utils/container_update/inginious-container-update', - 'utils/database_updater/inginious-database-update' -] - -# Setup -setup( - scripts=scripts, - test_suite='nose.collector', -) diff --git a/utils/sync/inginious-synchronize b/utils/sync/inginious-synchronize index 58d93feda..0d1658e7d 100755 --- a/utils/sync/inginious-synchronize +++ b/utils/sync/inginious-synchronize @@ -21,78 +21,83 @@ def print_output(text): for line in text.strip('\n').split('\n'): print('\t' + line) -# Change current dir for source file dir -scriptdir = os.path.dirname(os.path.abspath(__file__)) -os.chdir(scriptdir) - -# Open configuration file -try: - config = json.load(open(os.environ.get('INGINIOUS_SYNC_CONFIG', 'synchronize.json'), 'r')) - maindir = os.path.abspath(config['maindir']) - print('\x1b[33;1m-> Synchronization dir. : ' + maindir + ' \033[0m') -except: - print('\x1b[31;1mERROR: Failed to load configuration file\033[0m') - exit(1) - -# Configure git -try: - git.config("--global", "user.name", "INGInious") - git.config("--global", "user.email", "no-reply@inginious.info.ucl.ac.be") -except: - print('\x1b[31;1mERROR: Failed to configure Git. Is Git installed ?\033[0m') - exit(1) - -for repo in config['repos']: - print('\x1b[33;1m-> Synchronizing course repository : ' + repo['course'] + ' \033[0m') - # Add private key with ssh add - print('\x1b[1m--> Add private key with ssh-add \033[0m') + +def main(): + # Change current dir for source file dir + scriptdir = os.path.dirname(os.path.abspath(__file__)) os.chdir(scriptdir) + + # Open configuration file try: - out = ssh_add(os.path.abspath(repo['keyfile'])) - print_output(out.stderr.decode('utf-8')) + config = json.load(open(os.environ.get('INGINIOUS_SYNC_CONFIG', 'synchronize.json'), 'r')) + maindir = os.path.abspath(config['maindir']) + print('\x1b[33;1m-> Synchronization dir. : ' + maindir + ' \033[0m') except: - print('\x1b[31;1mERROR: Failed to load keyfile, or to add it with ssh-add\033[0m') + print('\x1b[31;1mERROR: Failed to load configuration file\033[0m') exit(1) - - - # Check if repo must be cloned - if not os.path.exists(maindir + "/" + repo['course']): - print('\x1b[33;1m--> Cloning repository\033[0m') - out = git.clone(repo['url'], maindir + "/" + repo['course']) - print_output(out.stdout.decode('utf-8')) - else: - print('\x1b[1m--> Synchronizing repository\033[0m') - - # Change working dir to the repo path - os.chdir(maindir + "/" + repo['course']) - - # Add all the files to git and commit - out = git.add("-A", '.') - - # Check for something to commit - if git.status('-s'): - out = git.commit("-a", "-m", "Automatic synchronization from INGInious") + + # Configure git + try: + git.config("--global", "user.name", "INGInious") + git.config("--global", "user.email", "no-reply@inginious.info.ucl.ac.be") + except: + print('\x1b[31;1mERROR: Failed to configure Git. Is Git installed ?\033[0m') + exit(1) + + for repo in config['repos']: + print('\x1b[33;1m-> Synchronizing course repository : ' + repo['course'] + ' \033[0m') + # Add private key with ssh add + print('\x1b[1m--> Add private key with ssh-add \033[0m') + os.chdir(scriptdir) + try: + out = ssh_add(os.path.abspath(repo['keyfile'])) + print_output(out.stderr.decode('utf-8')) + except: + print('\x1b[31;1mERROR: Failed to load keyfile, or to add it with ssh-add\033[0m') + exit(1) + + + # Check if repo must be cloned + if not os.path.exists(maindir + "/" + repo['course']): + print('\x1b[33;1m--> Cloning repository\033[0m') + out = git.clone(repo['url'], maindir + "/" + repo['course']) + print_output(out.stdout.decode('utf-8')) + else: + print('\x1b[1m--> Synchronizing repository\033[0m') + + # Change working dir to the repo path + os.chdir(maindir + "/" + repo['course']) + + # Add all the files to git and commit + out = git.add("-A", '.') + + # Check for something to commit + if git.status('-s'): + out = git.commit("-a", "-m", "Automatic synchronization from INGInious") + print_output(out.stdout.decode('utf-8')) + print_output(out.stderr.decode('utf-8')) + if not out.exit_code == 0: + exit(1) + + + # Pull recursively, keeping the INGInious version of changes + out = git.pull("--no-edit","-s", "recursive", "-X", "theirs") print_output(out.stdout.decode('utf-8')) print_output(out.stderr.decode('utf-8')) if not out.exit_code == 0: exit(1) - - # Pull recursively, keeping the INGInious version of changes - out = git.pull("--no-edit","-s", "recursive", "-X", "theirs") - print_output(out.stdout.decode('utf-8')) + # Push + if repo.get("push", True): + out = git.push() + + # Remove private key with ssh add + print('\x1b[1m--> Remove private key with ssh-add \033[0m') + os.chdir(scriptdir) + out = ssh_add("-d", os.path.abspath(repo['keyfile'])) print_output(out.stderr.decode('utf-8')) if not out.exit_code == 0: exit(1) - - # Push - if repo.get("push", True): - out = git.push() - - # Remove private key with ssh add - print('\x1b[1m--> Remove private key with ssh-add \033[0m') - os.chdir(scriptdir) - out = ssh_add("-d", os.path.abspath(repo['keyfile'])) - print_output(out.stderr.decode('utf-8')) - if not out.exit_code == 0: - exit(1) + +if __name__ == "__main__": + main()