|
| 1 | +#!/usr/bin/env python |
| 2 | +# coding=utf-8 |
| 3 | +# PYTHON_ARGCOMPLETE_OK |
| 4 | + |
| 5 | +import sys |
| 6 | +from argparse import ArgumentParser |
| 7 | + |
| 8 | +# Allow this script to be used from the parent directory |
| 9 | +sys.path.append(".") |
| 10 | + |
| 11 | +from app import db |
| 12 | +from app.models import Project |
| 13 | + |
| 14 | + |
| 15 | +def main(): |
| 16 | + # Parse arguments |
| 17 | + argument_parser = ArgumentParser(description="Create a new project.") |
| 18 | + argument_parser.add_argument( |
| 19 | + "--name", type=str, required=True, |
| 20 | + help="The name of the project." |
| 21 | + ) |
| 22 | + argument_parser.add_argument( |
| 23 | + "--workdir", type=str, required=True, |
| 24 | + help="The working directory in which all commands will be executed." |
| 25 | + ) |
| 26 | + argument_parser.add_argument( |
| 27 | + "--build-command", type=str, required=True, |
| 28 | + help="The build command to use." |
| 29 | + ) |
| 30 | + argument_parser.add_argument( |
| 31 | + "--quickcheck-command", type=str, required=False, default='', |
| 32 | + help="The quickcheck command to use." |
| 33 | + ) |
| 34 | + argument_parser.add_argument( |
| 35 | + "--quickcheck-timeout", type=int, required=False, |
| 36 | + help="The timeout of the quickcheck command." |
| 37 | + ) |
| 38 | + argument_parser.add_argument( |
| 39 | + "--test-command", type=str, required=True, |
| 40 | + help="The test command to use." |
| 41 | + ) |
| 42 | + argument_parser.add_argument( |
| 43 | + "--test-timeout", type=int, required=False, |
| 44 | + help="The timeout of the test command." |
| 45 | + ) |
| 46 | + argument_parser.add_argument( |
| 47 | + "--clean-command", type=str, required=False, default='', |
| 48 | + help="The clean command to use." |
| 49 | + ) |
| 50 | + arguments = argument_parser.parse_args() |
| 51 | + |
| 52 | + # Verify that a project with the same name doesn't exist yet |
| 53 | + if Project.query.filter(Project.name == arguments.name).count() > 0: |
| 54 | + print(f"Project '{arguments.name}' already exists", file=sys.stderr) |
| 55 | + exit(1) |
| 56 | + |
| 57 | + # Add the project to the DB |
| 58 | + project = Project( |
| 59 | + name=arguments.name, |
| 60 | + workdir=arguments.workdir, |
| 61 | + build_command=arguments.build_command, |
| 62 | + quickcheck_command=arguments.quickcheck_command, |
| 63 | + quickcheck_timeout=arguments.quickcheck_timeout, |
| 64 | + test_command=arguments.test_command, |
| 65 | + test_timeout=arguments.test_timeout, |
| 66 | + clean_command=arguments.clean_command |
| 67 | + ) |
| 68 | + db.session.add(project) |
| 69 | + db.session.commit() |
| 70 | + |
| 71 | + print(f"Project '{project.name}' created successfully.") |
| 72 | + exit(0) |
| 73 | + |
| 74 | + |
| 75 | +if __name__ == "__main__": |
| 76 | + main() |
0 commit comments