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
19 from coprs.views.misc import create_user_wrapper
20 from coprs.whoosheers import CoprWhoosheer
21 from run import generate_repo_packages
22 from sqlalchemy import or_
23 from coprs.helpers import chroot_to_branch,StatusEnum
24
25
27
28 - def run(self, 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 os.environ["PYTHONPATH"] = "."
33 return subprocess.call(["/usr/bin/python", "-m", "pytest"] + (test_args or []))
34
35 option_list = (
36 Option("-a",
37 dest="test_args",
38 nargs=argparse.REMAINDER),
39 )
40
41
43
44 """
45 Create the sqlite DB file (not the tables).
46 Used for alembic, "create_db" does this automatically.
47 """
48
50 if flask.current_app.config["SQLALCHEMY_DATABASE_URI"].startswith("sqlite"):
51
52 datadir_name = os.path.dirname(
53 flask.current_app.config["SQLALCHEMY_DATABASE_URI"][10:])
54 if not os.path.exists(datadir_name):
55 os.makedirs(datadir_name)
56
57
59
60 """
61 Create the DB schema
62 """
63
64 - def run(self, alembic_ini=None):
78
79 option_list = (
80 Option("--alembic",
81 "-f",
82 dest="alembic_ini",
83 help="Path to the alembic configuration file (alembic.ini)",
84 required=True),
85 )
86
87
89
90 """
91 Delete DB
92 """
93
96
97
99
104
107
109 print("{0} - chroot doesn\"t exist.".format(chroot_name))
110
111 option_list = (
112 Option("chroot_names",
113 help="Chroot name, e.g. fedora-18-x86_64.",
114 nargs="+"),
115 )
116
117
119
120 "Creates a mock chroot in DB"
121
123 self.option_list += Option(
124 "--dist-git-branch",
125 "-b",
126 dest="branch",
127 help="Branch name for this set of new chroots"),
128
129 - def run(self, chroot_names, branch=None):
142
143
145
146 option_list = (
147 Option("rawhide_chroot", help="Rawhide chroot name, e.g. fedora-rawhide-x86_64."),
148 Option("dest_chroot", help="Destination chroot, e.g. fedora-24-x86_64."),
149 )
150
151 - def run(self, rawhide_chroot, dest_chroot):
195
209
212
213
215
216 "Copy backend data of the latest successful rawhide builds into a new chroot"
217
218 - def run(self, rawhide_chroot, dest_chroot):
240
242
243 "Activates or deactivates a chroot"
244
245 - def run(self, chroot_names, action):
256
257 option_list = ChrootCommand.option_list + (
258 Option("--action",
259 "-a",
260 dest="action",
261 help="Action to take - currently activate or deactivate",
262 choices=["activate", "deactivate"],
263 required=True),
264 )
265
266
268
269 "Activates or deactivates a chroot"
270
271 - def run(self, chroot_names):
280
281
283
284 "Displays current mock chroots"
285
286 - def run(self, active_only):
291
292 option_list = (
293 Option("--active-only",
294 "-a",
295 dest="active_only",
296 help="Display only active chroots",
297 required=False,
298 action="store_true",
299 default=False),
300 )
301
302
304
305 """
306 You should not use regularly as that user will not be related to FAS account.
307 This should be used only for testing or adding special accounts e.g. proxy user.
308 """
309
310 - def run(self, name, mail, **kwargs):
324
325 option_list = (
326 Option("name"),
327 Option("mail"),
328 Option("--api_token", default=None, required=False),
329 Option("--api_login", default=None, required=False),
330 )
331
332
334
335 - def run(self, name, **kwargs):
357
358 option_list = (
359 Option("name"),
360 Group(
361 Option("--admin",
362 action="store_true"),
363 Option("--no-admin",
364 action="store_true"),
365 exclusive=True
366 ),
367 Group(
368 Option("--proven",
369 action="store_true"),
370 Option("--no-proven",
371 action="store_true"),
372 exclusive=True
373 ),
374 Group(
375 Option("--proxy",
376 action="store_true"),
377 Option("--no-proxy",
378 action="store_true"),
379 exclusive=True
380 )
381 )
382
383
385
386 """
387 Marks build as failed on all its non-finished chroots
388 """
389
390 option_list = [Option("build_id")]
391
392 - def run(self, build_id, **kwargs):
393 try:
394 builds_logic.BuildsLogic.mark_as_failed(build_id)
395 print("Marking non-finished chroots of build {} as failed".format(build_id))
396 db.session.commit()
397
398 except (sqlalchemy.exc.DataError, sqlalchemy.orm.exc.NoResultFound) as e:
399 print("Error: No such build {}".format(build_id))
400 return 1
401
402
404 """
405 recreates whoosh indexes for all projects
406 """
407
424
425
427 """
428 Recreates whoosh indexes for projects for which
429 indexed data were updated in last n minutes.
430 Doesn't update schema.
431 """
432
433 option_list = [Option("minutes_passed")]
434
435 - def run(self, minutes_passed):
445
446
448 """
449 go through all coprs and create configuration rpm packages
450 for them, if they don't already have it
451 """
452
455
456
457 manager = Manager(app)
458 manager.add_command("test", TestCommand())
459 manager.add_command("create_sqlite_file", CreateSqliteFileCommand())
460 manager.add_command("create_db", CreateDBCommand())
461 manager.add_command("drop_db", DropDBCommand())
462 manager.add_command("create_chroot", CreateChrootCommand())
463 manager.add_command("alter_chroot", AlterChrootCommand())
464 manager.add_command("display_chroots", DisplayChrootsCommand())
465 manager.add_command("drop_chroot", DropChrootCommand())
466 manager.add_command("alter_user", AlterUserCommand())
467 manager.add_command("add_user", AddUserCommand())
468 manager.add_command("fail_build", FailBuildCommand())
469 manager.add_command("update_indexes", UpdateIndexesCommand())
470 manager.add_command("update_indexes_quick", UpdateIndexesQuickCommand())
471 manager.add_command("generate_repo_packages", GenerateRepoPackagesCommand())
472 manager.add_command("rawhide_to_release", RawhideToReleaseCommand())
473 manager.add_command("backend_rawhide_to_release", BackendRawhideToReleaseCommand())
474
475 if __name__ == "__main__":
476 manager.run()
477