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 coprs import app
15 from coprs import db
16 from coprs import exceptions
17 from coprs import models
18 from coprs.logic import coprs_logic, packages_logic, actions_logic, builds_logic, users_logic
19 from coprs.views.misc import create_user_wrapper
20 from coprs.whoosheers import CoprWhoosheer
21 from sqlalchemy import or_
22 from coprs.helpers import chroot_to_branch,StatusEnum
23
24
26
27 - def run(self, test_args):
28 os.environ["COPRS_ENVIRON_UNITTEST"] = "1"
29 if not (("COPR_CONFIG" in os.environ) and os.environ["COPR_CONFIG"]):
30 os.environ["COPR_CONFIG"] = "/etc/copr/copr_unit_test.conf"
31 os.environ["PYTHONPATH"] = "."
32 return subprocess.call(["/usr/bin/python3", "-m", "pytest"] + (test_args or []))
33
34 option_list = (
35 Option("-a",
36 dest="test_args",
37 nargs=argparse.REMAINDER),
38 )
39
40
42
43 """
44 Create the sqlite DB file (not the tables).
45 Used for alembic, "create_db" does this automatically.
46 """
47
49 if flask.current_app.config["SQLALCHEMY_DATABASE_URI"].startswith("sqlite"):
50
51 datadir_name = os.path.dirname(
52 flask.current_app.config["SQLALCHEMY_DATABASE_URI"][10:])
53 if not os.path.exists(datadir_name):
54 os.makedirs(datadir_name)
55
56
58
59 """
60 Create the DB schema
61 """
62
63 - def run(self, alembic_ini=None):
77
78 option_list = (
79 Option("--alembic",
80 "-f",
81 dest="alembic_ini",
82 help="Path to the alembic configuration file (alembic.ini)",
83 required=True),
84 )
85
86
88
89 """
90 Delete DB
91 """
92
95
96
98
103
106
108 print("{0} - chroot doesn\"t exist.".format(chroot_name))
109
110 option_list = (
111 Option("chroot_names",
112 help="Chroot name, e.g. fedora-18-x86_64.",
113 nargs="+"),
114 )
115
116
118
119 "Creates a mock chroot in DB"
120
122 self.option_list += Option(
123 "--dist-git-branch",
124 "-b",
125 dest="branch",
126 help="Branch name for this set of new chroots"),
127
128 - def run(self, chroot_names, branch=None):
141
142
144
145 option_list = (
146 Option("rawhide_chroot", help="Rawhide chroot name, e.g. fedora-rawhide-x86_64."),
147 Option("dest_chroot", help="Destination chroot, e.g. fedora-24-x86_64."),
148 )
149
150 - def run(self, rawhide_chroot, dest_chroot):
196
210
213
214
216
217 "Copy backend data of the latest successful rawhide builds into a new chroot"
218
219 - def run(self, rawhide_chroot, dest_chroot):
241
242
244
245 "Activates or deactivates a chroot"
246
247 - def run(self, chroot_names, action):
258
259 option_list = ChrootCommand.option_list + (
260 Option("--action",
261 "-a",
262 dest="action",
263 help="Action to take - currently activate or deactivate",
264 choices=["activate", "deactivate"],
265 required=True),
266 )
267
268
270
271 "Activates or deactivates a chroot"
272
273 - def run(self, chroot_names):
282
283
285
286 "Displays current mock chroots"
287
288 - def run(self, active_only):
293
294 option_list = (
295 Option("--active-only",
296 "-a",
297 dest="active_only",
298 help="Display only active chroots",
299 required=False,
300 action="store_true",
301 default=False),
302 )
303
304
306
307 """
308 You should not use regularly as that user will not be related to FAS account.
309 This should be used only for testing or adding special accounts e.g. proxy user.
310 """
311
312 - def run(self, name, mail, **kwargs):
326
327 option_list = (
328 Option("name"),
329 Option("mail"),
330 Option("--api_token", default=None, required=False),
331 Option("--api_login", default=None, required=False),
332 )
333
334
336
337 - def run(self, username):
344
345 option_list = (
346 Option("username"),
347 )
348
349
351
352 - def run(self, name, **kwargs):
374
375 option_list = (
376 Option("name"),
377 Group(
378 Option("--admin",
379 action="store_true"),
380 Option("--no-admin",
381 action="store_true"),
382 exclusive=True
383 ),
384 Group(
385 Option("--proven",
386 action="store_true"),
387 Option("--no-proven",
388 action="store_true"),
389 exclusive=True
390 ),
391 Group(
392 Option("--proxy",
393 action="store_true"),
394 Option("--no-proxy",
395 action="store_true"),
396 exclusive=True
397 )
398 )
399
400
402
403 """
404 Marks build as failed on all its non-finished chroots
405 """
406
407 option_list = [Option("build_id")]
408
409 - def run(self, build_id, **kwargs):
410 try:
411 builds_logic.BuildsLogic.mark_as_failed(build_id)
412 print("Marking non-finished chroots of build {} as failed".format(build_id))
413 db.session.commit()
414
415 except (sqlalchemy.exc.DataError, sqlalchemy.orm.exc.NoResultFound) as e:
416 print("Error: No such build {}".format(build_id))
417 return 1
418
419
421 """
422 recreates whoosh indexes for all projects
423 """
424
441
442
444 """
445 Recreates whoosh indexes for projects for which
446 indexed data were updated in last n minutes.
447 Doesn't update schema.
448 """
449
450 option_list = [Option("minutes_passed")]
451
452 - def run(self, minutes_passed):
462
463
464 manager = Manager(app)
465 manager.add_command("test", TestCommand())
466 manager.add_command("create_sqlite_file", CreateSqliteFileCommand())
467 manager.add_command("create_db", CreateDBCommand())
468 manager.add_command("drop_db", DropDBCommand())
469 manager.add_command("create_chroot", CreateChrootCommand())
470 manager.add_command("alter_chroot", AlterChrootCommand())
471 manager.add_command("display_chroots", DisplayChrootsCommand())
472 manager.add_command("drop_chroot", DropChrootCommand())
473 manager.add_command("alter_user", AlterUserCommand())
474 manager.add_command("add_user", AddUserCommand())
475 manager.add_command("dump_user", DumpUserCommand())
476 manager.add_command("fail_build", FailBuildCommand())
477 manager.add_command("update_indexes", UpdateIndexesCommand())
478 manager.add_command("update_indexes_quick", UpdateIndexesQuickCommand())
479 manager.add_command("rawhide_to_release", RawhideToReleaseCommand())
480 manager.add_command("backend_rawhide_to_release", BackendRawhideToReleaseCommand())
481
482 if __name__ == "__main__":
483 manager.run()
484