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 from flask_whooshee import Whooshee
13
14 from copr_common.enums import StatusEnum
15 from coprs import app
16 from coprs import db
17 from coprs import exceptions
18 from coprs import models
19 from coprs.logic import coprs_logic, packages_logic, actions_logic, builds_logic, users_logic
20 from coprs.views.misc import create_user_wrapper
21 from coprs.whoosheers import CoprWhoosheer
22 from sqlalchemy import and_, or_
23 from coprs.helpers import chroot_to_branch
24
25
27
28 - def run(self, coverage, test_args):
29 os.environ["COPRS_ENVIRON_UNITTEST"] = "1"
30 if not (("COPR_CONFIG" in os.environ) and os.environ["COPR_CONFIG"]):
31 os.environ["COPR_CONFIG"] = "/etc/copr/copr_unit_test.conf"
32
33 if 'PYTHONPATH' in os.environ:
34 os.environ['PYTHONPATH'] = os.environ['PYTHONPATH'] + ':.'
35 else:
36 os.environ['PYTHONPATH'] = '.'
37
38 additional_args = []
39
40 if coverage:
41 additional_args.extend([
42 '--cov-report', 'term-missing', '--cov', 'coprs'
43 ])
44
45 return subprocess.call(["/usr/bin/python3", "-m", "pytest"] + additional_args)
46
47 option_list = (
48 Option("-a",
49 dest="test_args",
50 nargs=argparse.REMAINDER),
51 Option("--coverage",
52 dest="coverage",
53 required=False,
54 action='store_true',
55 default=False),
56 )
57
58
60
61 """
62 Create the sqlite DB file (not the tables).
63 Used for alembic, "create_db" does this automatically.
64 """
65
67 if flask.current_app.config["SQLALCHEMY_DATABASE_URI"].startswith("sqlite"):
68
69 datadir_name = os.path.dirname(
70 flask.current_app.config["SQLALCHEMY_DATABASE_URI"][10:])
71 if not os.path.exists(datadir_name):
72 os.makedirs(datadir_name)
73
74
76
77 """
78 Create the DB schema
79 """
80
81 - def run(self, alembic_ini=None):
95
96 option_list = (
97 Option("--alembic",
98 "-f",
99 dest="alembic_ini",
100 help="Path to the alembic configuration file (alembic.ini)",
101 required=True),
102 )
103
104
106
107 """
108 Delete DB
109 """
110
113
114
116
121
124
126 print("{0} - chroot doesn\"t exist.".format(chroot_name))
127
128 option_list = (
129 Option("chroot_names",
130 help="Chroot name, e.g. fedora-18-x86_64.",
131 nargs="+"),
132 )
133
134
136
137 "Creates a mock chroot in DB"
138
140 self.option_list += Option(
141 "--dist-git-branch",
142 "-b",
143 dest="branch",
144 help="Branch name for this set of new chroots"),
145
146 - def run(self, chroot_names, branch=None):
159
160
162
163 option_list = (
164 Option("rawhide_chroot", help="Rawhide chroot name, e.g. fedora-rawhide-x86_64."),
165 Option("dest_chroot", help="Destination chroot, e.g. fedora-24-x86_64."),
166 )
167
168 - def run(self, rawhide_chroot, dest_chroot):
214
228
231
232
234
235 "Copy backend data of the latest successful rawhide builds into a new chroot"
236
237 - def run(self, rawhide_chroot, dest_chroot):
259
260
262
263 "Activates or deactivates a chroot"
264
265 - def run(self, chroot_names, action):
276
277 option_list = ChrootCommand.option_list + (
278 Option("--action",
279 "-a",
280 dest="action",
281 help="Action to take - currently activate or deactivate",
282 choices=["activate", "deactivate"],
283 required=True),
284 )
285
286
288
289 "Activates or deactivates a chroot"
290
291 - def run(self, chroot_names):
300
301
303
304 "Displays current mock chroots"
305
306 - def run(self, active_only):
311
312 option_list = (
313 Option("--active-only",
314 "-a",
315 dest="active_only",
316 help="Display only active chroots",
317 required=False,
318 action="store_true",
319 default=False),
320 )
321
322
324
325 """
326 You should not use regularly as that user will not be related to FAS account.
327 This should be used only for testing or adding special accounts e.g. proxy user.
328 """
329
330 - def run(self, name, mail, **kwargs):
344
345 option_list = (
346 Option("name"),
347 Option("mail"),
348 Option("--api_token", default=None, required=False),
349 Option("--api_login", default=None, required=False),
350 )
351
352
354
355 - def run(self, username):
362
363 option_list = (
364 Option("username"),
365 )
366
367
369
370 - def run(self, name, **kwargs):
392
393 option_list = (
394 Option("name"),
395 Group(
396 Option("--admin",
397 action="store_true"),
398 Option("--no-admin",
399 action="store_true"),
400 exclusive=True
401 ),
402 Group(
403 Option("--proven",
404 action="store_true"),
405 Option("--no-proven",
406 action="store_true"),
407 exclusive=True
408 ),
409 Group(
410 Option("--proxy",
411 action="store_true"),
412 Option("--no-proxy",
413 action="store_true"),
414 exclusive=True
415 )
416 )
417
418
420
421 """
422 Marks build as failed on all its non-finished chroots
423 """
424
425 option_list = [Option("build_id")]
426
427 - def run(self, build_id, **kwargs):
428 try:
429 builds_logic.BuildsLogic.mark_as_failed(build_id)
430 print("Marking non-finished chroots of build {} as failed".format(build_id))
431 db.session.commit()
432
433 except (sqlalchemy.exc.DataError, sqlalchemy.orm.exc.NoResultFound) as e:
434 print("Error: No such build {}".format(build_id))
435 return 1
436
437
439 """
440 recreates whoosh indexes for all projects
441 """
442
459
460
462 """
463 Recreates whoosh indexes for projects for which
464 indexed data were updated in last n minutes.
465 Doesn't update schema.
466 """
467
468 option_list = [Option("minutes_passed")]
469
470 - def run(self, minutes_passed):
480
481
483 """
484 Generates newest graph data.
485 """
486
491
492
494 """
495 Removes old cached graph data that is no longer used.
496 """
497
509
510
511 manager = Manager(app)
512 manager.add_command("test", TestCommand())
513 manager.add_command("create_sqlite_file", CreateSqliteFileCommand())
514 manager.add_command("create_db", CreateDBCommand())
515 manager.add_command("drop_db", DropDBCommand())
516 manager.add_command("create_chroot", CreateChrootCommand())
517 manager.add_command("alter_chroot", AlterChrootCommand())
518 manager.add_command("display_chroots", DisplayChrootsCommand())
519 manager.add_command("drop_chroot", DropChrootCommand())
520 manager.add_command("alter_user", AlterUserCommand())
521 manager.add_command("add_user", AddUserCommand())
522 manager.add_command("dump_user", DumpUserCommand())
523 manager.add_command("fail_build", FailBuildCommand())
524 manager.add_command("update_indexes", UpdateIndexesCommand())
525 manager.add_command("update_indexes_quick", UpdateIndexesQuickCommand())
526 manager.add_command("rawhide_to_release", RawhideToReleaseCommand())
527 manager.add_command("backend_rawhide_to_release", BackendRawhideToReleaseCommand())
528 manager.add_command("update_graphs", UpdateGraphsDataCommand())
529 manager.add_command("vacuum_graphs", RemoveGraphsDataCommand())
530
531 if __name__ == "__main__":
532 manager.run()
533