1
2
3 import argparse
4 import os
5 import subprocess
6 import datetime
7 import sqlalchemy
8 import time
9
10 import flask
11 from flask_script import Manager, Command, Option, Group
12
13 from coprs import app
14 from coprs import db
15 from coprs import exceptions
16 from coprs import models
17 from coprs.logic import coprs_logic, packages_logic, actions_logic, builds_logic
18 from coprs.views.misc import create_user_wrapper
19 from coprs.whoosheers import CoprWhoosheer
20 from run import generate_repo_packages
21 from sqlalchemy import or_
22
23
25
26 - def run(self, test_args):
27 os.environ["COPRS_ENVIRON_UNITTEST"] = "1"
28 if not (("COPR_CONFIG" in os.environ) and os.environ["COPR_CONFIG"]):
29 os.environ["COPR_CONFIG"] = "/etc/copr/copr_unit_test.conf"
30 os.environ["PYTHONPATH"] = "."
31 return subprocess.call(["/usr/bin/python", "-m", "pytest"] + (test_args or []))
32
33 option_list = (
34 Option("-a",
35 dest="test_args",
36 nargs=argparse.REMAINDER),
37 )
38
39
41
42 """
43 Create the sqlite DB file (not the tables).
44 Used for alembic, "create_db" does this automatically.
45 """
46
48 if flask.current_app.config["SQLALCHEMY_DATABASE_URI"].startswith("sqlite"):
49
50 datadir_name = os.path.dirname(
51 flask.current_app.config["SQLALCHEMY_DATABASE_URI"][10:])
52 if not os.path.exists(datadir_name):
53 os.makedirs(datadir_name)
54
55
57
58 """
59 Create the DB schema
60 """
61
62 - def run(self, alembic_ini=None):
72
73 option_list = (
74 Option("--alembic",
75 "-f",
76 dest="alembic_ini",
77 help="Path to the alembic configuration file (alembic.ini)",
78 required=True),
79 )
80
81
83
84 """
85 Delete DB
86 """
87
90
91
93
98
101
103 print("{0} - chroot doesn\"t exist.".format(chroot_name))
104
105 option_list = (
106 Option("chroot_names",
107 help="Chroot name, e.g. fedora-18-x86_64.",
108 nargs="+"),
109 )
110
111
113
114 "Creates a mock chroot in DB"
115
116 - def run(self, chroot_names):
125
126
128
129 option_list = (
130 Option("rawhide_chroot", help="Rawhide chroot name, e.g. fedora-rawhide-x86_64."),
131 Option("dest_chroot", help="Destination chroot, e.g. fedora-24-x86_64."),
132 )
133
134 - def run(self, rawhide_chroot, dest_chroot):
176
190
193
194
196
197 "Activates or deactivates a chroot"
198
199 - def run(self, chroot_names, action):
210
211 option_list = ChrootCommand.option_list + (
212 Option("--action",
213 "-a",
214 dest="action",
215 help="Action to take - currently activate or deactivate",
216 choices=["activate", "deactivate"],
217 required=True),
218 )
219
220
222
223 "Activates or deactivates a chroot"
224
225 - def run(self, chroot_names):
234
235
237
238 "Displays current mock chroots"
239
240 - def run(self, active_only):
245
246 option_list = (
247 Option("--active-only",
248 "-a",
249 dest="active_only",
250 help="Display only active chroots",
251 required=False,
252 action="store_true",
253 default=False),
254 )
255
256
258
259 """
260 Adds user for debug/testing purpose.
261 You shouldn't use this on production instance
262 """
263
264 - def run(self, name, mail, **kwargs):
285
286 option_list = (
287 Option("name"),
288 Option("mail"),
289 Option("--api_token", default=None, required=False),
290 Option("--api_login", default=None, required=False),
291 Group(
292 Option("--admin",
293 action="store_true"),
294 Option("--no-admin",
295 action="store_true"),
296 exclusive=True
297 ),
298 Group(
299 Option("--proven",
300 action="store_true"),
301 Option("--no-proven",
302 action="store_true"),
303 exclusive=True
304 ),
305 )
306
307
309
310 - def run(self, name, **kwargs):
328
329 option_list = (
330 Option("name"),
331 Group(
332 Option("--admin",
333 action="store_true"),
334 Option("--no-admin",
335 action="store_true"),
336 exclusive=True
337 ),
338 Group(
339 Option("--proven",
340 action="store_true"),
341 Option("--no-proven",
342 action="store_true"),
343 exclusive=True
344 )
345 )
346
347
349
350 """
351 Marks build as failed on all its non-finished chroots
352 """
353
354 option_list = [Option("build_id")]
355
356 - def run(self, build_id, **kwargs):
357 try:
358 builds_logic.BuildsLogic.mark_as_failed(build_id)
359 print("Marking non-finished chroots of build {} as failed".format(build_id))
360 db.session.commit()
361
362 except (sqlalchemy.exc.DataError, sqlalchemy.orm.exc.NoResultFound) as e:
363 print("Error: No such build {}".format(build_id))
364 return 1
365
366
368 """
369 recreates whoosh indexes for all projects
370 """
371
386
387
389 """
390 Recreates whoosh indexes for projects for which
391 indexed data were updated in last n minutes.
392 Doesn't update schema.
393 """
394
395 option_list = [Option("minutes_passed")]
396
397 - def run(self, minutes_passed):
405
406
408 """
409 go through all coprs and create configuration rpm packages
410 for them, if they don't already have it
411 """
412
415
416
417 manager = Manager(app)
418 manager.add_command("test", TestCommand())
419 manager.add_command("create_sqlite_file", CreateSqliteFileCommand())
420 manager.add_command("create_db", CreateDBCommand())
421 manager.add_command("drop_db", DropDBCommand())
422 manager.add_command("create_chroot", CreateChrootCommand())
423 manager.add_command("alter_chroot", AlterChrootCommand())
424 manager.add_command("display_chroots", DisplayChrootsCommand())
425 manager.add_command("drop_chroot", DropChrootCommand())
426 manager.add_command("alter_user", AlterUserCommand())
427 manager.add_command("add_debug_user", AddDebugUserCommand())
428 manager.add_command("fail_build", FailBuildCommand())
429 manager.add_command("update_indexes", UpdateIndexesCommand())
430 manager.add_command("update_indexes_quick", UpdateIndexesQuickCommand())
431 manager.add_command("generate_repo_packages", GenerateRepoPackagesCommand())
432 manager.add_command("rawhide_to_release", RawhideToReleaseCommand())
433
434 if __name__ == "__main__":
435 manager.run()
436