Skip to content

Commit

Permalink
[packaging] removing setup.py and fixing pyproject.toml scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreDoneux committed Feb 20, 2024
1 parent 820571a commit e87079c
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 96 deletions.
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]",
]
Expand Down Expand Up @@ -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]
Expand Down
29 changes: 0 additions & 29 deletions setup.py

This file was deleted.

131 changes: 68 additions & 63 deletions utils/sync/inginious-synchronize
Original file line number Diff line number Diff line change
Expand Up @@ -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", "[email protected]")
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", "[email protected]")
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()

0 comments on commit e87079c

Please sign in to comment.