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):
76
77 option_list = (
78 Option("--alembic",
79 "-f",
80 dest="alembic_ini",
81 help="Path to the alembic configuration file (alembic.ini)",
82 required=True),
83 )
84
85
87
88 """
89 Delete DB
90 """
91
94
95
97
102
105
107 print("{0} - chroot doesn\"t exist.".format(chroot_name))
108
109 option_list = (
110 Option("chroot_names",
111 help="Chroot name, e.g. fedora-18-x86_64.",
112 nargs="+"),
113 )
114
115
117
118 "Creates a mock chroot in DB"
119
120 - def run(self, chroot_names):
129
130
132
133 option_list = (
134 Option("rawhide_chroot", help="Rawhide chroot name, e.g. fedora-rawhide-x86_64."),
135 Option("dest_chroot", help="Destination chroot, e.g. fedora-24-x86_64."),
136 )
137
138 - def run(self, rawhide_chroot, dest_chroot):
180
194
197
198
200
201 "Copy backend data of the latest successful rawhide builds into a new chroot"
202
203 - def run(self, rawhide_chroot, dest_chroot):
225
227
228 "Activates or deactivates a chroot"
229
230 - def run(self, chroot_names, action):
241
242 option_list = ChrootCommand.option_list + (
243 Option("--action",
244 "-a",
245 dest="action",
246 help="Action to take - currently activate or deactivate",
247 choices=["activate", "deactivate"],
248 required=True),
249 )
250
251
253
254 "Activates or deactivates a chroot"
255
256 - def run(self, chroot_names):
265
266
268
269 "Displays current mock chroots"
270
271 - def run(self, active_only):
276
277 option_list = (
278 Option("--active-only",
279 "-a",
280 dest="active_only",
281 help="Display only active chroots",
282 required=False,
283 action="store_true",
284 default=False),
285 )
286
287
289
290 """
291 Adds user for debug/testing purpose.
292 You shouldn't use this on production instance
293 """
294
295 - def run(self, name, mail, **kwargs):
316
317 option_list = (
318 Option("name"),
319 Option("mail"),
320 Option("--api_token", default=None, required=False),
321 Option("--api_login", default=None, required=False),
322 Group(
323 Option("--admin",
324 action="store_true"),
325 Option("--no-admin",
326 action="store_true"),
327 exclusive=True
328 ),
329 Group(
330 Option("--proven",
331 action="store_true"),
332 Option("--no-proven",
333 action="store_true"),
334 exclusive=True
335 ),
336 )
337
338
340
341 - def run(self, name, **kwargs):
359
360 option_list = (
361 Option("name"),
362 Group(
363 Option("--admin",
364 action="store_true"),
365 Option("--no-admin",
366 action="store_true"),
367 exclusive=True
368 ),
369 Group(
370 Option("--proven",
371 action="store_true"),
372 Option("--no-proven",
373 action="store_true"),
374 exclusive=True
375 )
376 )
377
378
380
381 """
382 Marks build as failed on all its non-finished chroots
383 """
384
385 option_list = [Option("build_id")]
386
387 - def run(self, build_id, **kwargs):
388 try:
389 builds_logic.BuildsLogic.mark_as_failed(build_id)
390 print("Marking non-finished chroots of build {} as failed".format(build_id))
391 db.session.commit()
392
393 except (sqlalchemy.exc.DataError, sqlalchemy.orm.exc.NoResultFound) as e:
394 print("Error: No such build {}".format(build_id))
395 return 1
396
397
399 """
400 recreates whoosh indexes for all projects
401 """
402
417
418
420 """
421 Recreates whoosh indexes for projects for which
422 indexed data were updated in last n minutes.
423 Doesn't update schema.
424 """
425
426 option_list = [Option("minutes_passed")]
427
428 - def run(self, minutes_passed):
436
437
439 """
440 go through all coprs and create configuration rpm packages
441 for them, if they don't already have it
442 """
443
446
447
448 manager = Manager(app)
449 manager.add_command("test", TestCommand())
450 manager.add_command("create_sqlite_file", CreateSqliteFileCommand())
451 manager.add_command("create_db", CreateDBCommand())
452 manager.add_command("drop_db", DropDBCommand())
453 manager.add_command("create_chroot", CreateChrootCommand())
454 manager.add_command("alter_chroot", AlterChrootCommand())
455 manager.add_command("display_chroots", DisplayChrootsCommand())
456 manager.add_command("drop_chroot", DropChrootCommand())
457 manager.add_command("alter_user", AlterUserCommand())
458 manager.add_command("add_debug_user", AddDebugUserCommand())
459 manager.add_command("fail_build", FailBuildCommand())
460 manager.add_command("update_indexes", UpdateIndexesCommand())
461 manager.add_command("update_indexes_quick", UpdateIndexesQuickCommand())
462 manager.add_command("generate_repo_packages", GenerateRepoPackagesCommand())
463 manager.add_command("rawhide_to_release", RawhideToReleaseCommand())
464 manager.add_command("backend_rawhide_to_release", BackendRawhideToReleaseCommand())
465
466 if __name__ == "__main__":
467 manager.run()
468