1
2
3 import argparse
4 import os
5 import subprocess
6
7 import flask
8 from flask.ext.script import Manager, Command, Option, Group
9
10 from coprs import app
11 from coprs import db
12 from coprs import exceptions
13 from coprs import models
14 from coprs.logic import coprs_logic
15
16
18
19 - def run(self, test_args):
20 os.environ["COPRS_ENVIRON_UNITTEST"] = "1"
21 if not (("COPR_CONFIG" in os.environ) and os.environ["COPR_CONFIG"]):
22 os.environ["COPR_CONFIG"] = "/etc/copr/copr_unit_test.conf"
23 os.environ["PYTHONPATH"] = "."
24 return subprocess.call(["py.test"] + (test_args or []))
25
26 option_list = (
27 Option("-a",
28 dest="test_args",
29 nargs=argparse.REMAINDER),
30 )
31
32
34
35 """
36 Create the sqlite DB file (not the tables).
37 Used for alembic, "create_db" does this automatically.
38 """
39
41 if flask.current_app.config["SQLALCHEMY_DATABASE_URI"].startswith("sqlite"):
42
43 datadir_name = os.path.dirname(
44 flask.current_app.config["SQLALCHEMY_DATABASE_URI"][10:])
45 if not os.path.exists(datadir_name):
46 os.makedirs(datadir_name)
47
48
50
51 """
52 Create the DB schema
53 """
54
55 - def run(self, alembic_ini=None):
65
66 option_list = (
67 Option("--alembic",
68 "-f",
69 dest="alembic_ini",
70 help="Path to the alembic configuration file (alembic.ini)",
71 required=True),
72 )
73
74
76
77 """
78 Delete DB
79 """
80
83
84
86
91
93 print("{0} - already exists.".format(chroot_name))
94
96 print("{0} - chroot doesn\"t exist.".format(chroot_name))
97
98 option_list = (
99 Option("chroot_names",
100 help="Chroot name, e.g. fedora-18-x86_64.",
101 nargs="+"),
102 )
103
104
106
107 "Creates a mock chroot in DB"
108
109 - def run(self, chroot_names):
118
119
121
122 "Activates or deactivates a chroot"
123
124 - def run(self, chroot_names, action):
135
136 option_list = ChrootCommand.option_list + (
137 Option("--action",
138 "-a",
139 dest="action",
140 help="Action to take - currently activate or deactivate",
141 choices=["activate", "deactivate"],
142 required=True),
143 )
144
145
147
148 "Activates or deactivates a chroot"
149
150 - def run(self, chroot_names):
159
160
162
163 "Displays current mock chroots"
164
165 - def run(self, active_only):
170
171 option_list = (
172 Option("--active-only",
173 "-a",
174 dest="active_only",
175 help="Display only active chroots",
176 required=False,
177 action="store_true",
178 default=False),
179 )
180
181
183
184 - def run(self, name, **kwargs):
201
202 option_list = (
203 Option("name"),
204 Group(
205 Option("--admin",
206 action="store_true"),
207 Option("--no-admin",
208 action="store_true"),
209 exclusive=True
210 ),
211 Group(
212 Option("--proven",
213 action="store_true"),
214 Option("--no-proven",
215 action="store_true"),
216 exclusive=True
217 )
218 )
219
220 manager = Manager(app)
221 manager.add_command("test", TestCommand())
222 manager.add_command("create_sqlite_file", CreateSqliteFileCommand())
223 manager.add_command("create_db", CreateDBCommand())
224 manager.add_command("drop_db", DropDBCommand())
225 manager.add_command("create_chroot", CreateChrootCommand())
226 manager.add_command("alter_chroot", AlterChrootCommand())
227 manager.add_command("display_chroots", DisplayChrootsCommand())
228 manager.add_command("drop_chroot", DropChrootCommand())
229 manager.add_command("alter_user", AlterUserCommand())
230
231 if __name__ == "__main__":
232 manager.run()
233