File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
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 = "Delete a project." )
18+ argument_parser .add_argument (
19+ "--project" , type = str , required = True ,
20+ help = "The name of the project to delete."
21+ )
22+ arguments = argument_parser .parse_args ()
23+
24+ # Find that project
25+ project_query = Project .query .filter (Project .name == arguments .project )
26+ if project_query .count () == 0 :
27+ print (f"Project '{ arguments .project } ' does not exist" , file = sys .stderr )
28+ exit (1 )
29+
30+ # Delete the project from the DB
31+ db .session .delete (project_query .first ())
32+ db .session .commit ()
33+
34+ print (f"Project '{ arguments .project } ' deleted successfully." )
35+ exit (0 )
36+
37+
38+ if __name__ == "__main__" :
39+ main ()
You can’t perform that action at this time.
0 commit comments