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 from coprs.whoosheers import CoprUserWhoosheer
16
17
19
20 - def run(self, test_args):
21 os.environ["COPRS_ENVIRON_UNITTEST"] = "1"
22 if not (("COPR_CONFIG" in os.environ) and os.environ["COPR_CONFIG"]):
23 os.environ["COPR_CONFIG"] = "/etc/copr/copr_unit_test.conf"
24 os.environ["PYTHONPATH"] = "."
25 return subprocess.call(["py.test"] + (test_args or []))
26
27 option_list = (
28 Option("-a",
29 dest="test_args",
30 nargs=argparse.REMAINDER),
31 )
32
33
35
36 """
37 Create the sqlite DB file (not the tables).
38 Used for alembic, "create_db" does this automatically.
39 """
40
42 if flask.current_app.config["SQLALCHEMY_DATABASE_URI"].startswith("sqlite"):
43
44 datadir_name = os.path.dirname(
45 flask.current_app.config["SQLALCHEMY_DATABASE_URI"][10:])
46 if not os.path.exists(datadir_name):
47 os.makedirs(datadir_name)
48
49
51
52 """
53 Create the DB schema
54 """
55
56 - def run(self, alembic_ini=None):
66
67 option_list = (
68 Option("--alembic",
69 "-f",
70 dest="alembic_ini",
71 help="Path to the alembic configuration file (alembic.ini)",
72 required=True),
73 )
74
75
77
78 """
79 Delete DB
80 """
81
84
85
87
92
94 print("{0} - already exists.".format(chroot_name))
95
97 print("{0} - chroot doesn\"t exist.".format(chroot_name))
98
99 option_list = (
100 Option("chroot_names",
101 help="Chroot name, e.g. fedora-18-x86_64.",
102 nargs="+"),
103 )
104
105
107
108 "Creates a mock chroot in DB"
109
110 - def run(self, chroot_names):
119
120
122
123 "Activates or deactivates a chroot"
124
125 - def run(self, chroot_names, action):
136
137 option_list = ChrootCommand.option_list + (
138 Option("--action",
139 "-a",
140 dest="action",
141 help="Action to take - currently activate or deactivate",
142 choices=["activate", "deactivate"],
143 required=True),
144 )
145
146
148
149 "Activates or deactivates a chroot"
150
151 - def run(self, chroot_names):
160
161
163
164 "Displays current mock chroots"
165
166 - def run(self, active_only):
171
172 option_list = (
173 Option("--active-only",
174 "-a",
175 dest="active_only",
176 help="Display only active chroots",
177 required=False,
178 action="store_true",
179 default=False),
180 )
181
182
184
185 - def run(self, name, **kwargs):
202
203 option_list = (
204 Option("name"),
205 Group(
206 Option("--admin",
207 action="store_true"),
208 Option("--no-admin",
209 action="store_true"),
210 exclusive=True
211 ),
212 Group(
213 Option("--proven",
214 action="store_true"),
215 Option("--no-proven",
216 action="store_true"),
217 exclusive=True
218 )
219 )
220
222 """
223 recreates whoosh indexes for all projects
224 """
225
240
241
242 manager = Manager(app)
243 manager.add_command("test", TestCommand())
244 manager.add_command("create_sqlite_file", CreateSqliteFileCommand())
245 manager.add_command("create_db", CreateDBCommand())
246 manager.add_command("drop_db", DropDBCommand())
247 manager.add_command("create_chroot", CreateChrootCommand())
248 manager.add_command("alter_chroot", AlterChrootCommand())
249 manager.add_command("display_chroots", DisplayChrootsCommand())
250 manager.add_command("drop_chroot", DropChrootCommand())
251 manager.add_command("alter_user", AlterUserCommand())
252 manager.add_command("update_indexes", UpdateIndexesCommand())
253
254 if __name__ == "__main__":
255 manager.run()
256