1
2
3
4 import os
5 import sys
6 import copy
7 from functools import wraps
8 import pipes
9 import importlib
10 import click
11 from commands.flask3_wrapper import get_flask_wrapper_command
12 import commands.test
13 import commands.create_sqlite_file
14 import commands.create_db
15 import commands.drop_db
16 import commands.create_chroot
17 import commands.alter_chroot
18 import commands.display_chroots
19 import commands.drop_chroot
20 import commands.branch_fedora
21 import commands.comment_chroot
22 import commands.alter_user
23 import commands.add_user
24 import commands.dump_user
25 import commands.update_indexes
26 import commands.update_indexes_quick
27 import commands.update_indexes_required
28 import commands.get_admins
29 import commands.fail_build
30 import commands.rawhide_to_release
31 import commands.update_graphs
32 import commands.vacuum_graphs
33 import commands.notify_outdated_chroots
34 import commands.delete_outdated_chroots
35 import commands.clean_expired_projects
36 import commands.clean_old_builds
37 import commands.delete_orphans
38
39 from coprs import app
40
41 if os.getuid() == 0:
42 sys.stderr.write("Please don't run this script as a 'root' user, use:\n")
43 sys.stderr.write("$ sudo -u copr-fe {}\n".format(
44 ' '.join([pipes.quote(arg) for arg in sys.argv])))
45 sys.exit(1)
46
47 commands_list = [
48
49 "test",
50
51
52 "create_sqlite_file",
53 "create_db",
54 "drop_db",
55
56
57 "create_chroot",
58 "alter_chroot",
59 "display_chroots",
60 "drop_chroot",
61 "branch_fedora",
62 "comment_chroot",
63
64
65 "alter_user",
66 "add_user",
67 "dump_user",
68
69
70 "update_indexes",
71 "update_indexes_quick",
72 "update_indexes_required",
73
74
75 "get_admins",
76 "fail_build",
77 "rawhide_to_release",
78 "update_graphs",
79 "vacuum_graphs",
80 "notify_outdated_chroots",
81 "delete_outdated_chroots",
82 "clean_expired_projects",
83 "clean_old_builds",
84 "delete_orphans",
85 ]
89 """
90 Decorate click command function so it always exits, so each 'return STATUS'
91 is actually propagated to shell.
92 """
93 @wraps(function)
94 def wrapper(*args, **kwargs):
95 sys.exit(bool(function(*args, **kwargs)))
96 return wrapper
97
98
99 for command in commands_list:
100 cmd_obj = getattr(getattr(commands, command), command)
101 cmd_obj.callback = always_exit(cmd_obj.callback)
102
103
104
105
106 if '_' in command and hasattr(cmd_obj, 'hidden'):
107
108 alias = copy.deepcopy(cmd_obj)
109 alias.hidden = True
110 app.cli.add_command(alias, command)
111
112 app.cli.add_command(cmd_obj)
113
114
115 app.cli.add_command(get_flask_wrapper_command('runserver'))
116 app.cli.add_command(get_flask_wrapper_command('run'))
117 app.cli.add_command(get_flask_wrapper_command('shell'))
118
119 if __name__ == "__main__":
120 app.cli()
121