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.ext.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
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):
193
207
210
211
213
214 "Copy backend data of the latest successful rawhide builds into a new chroot"
215
216 - def run(self, rawhide_chroot, dest_chroot):
238
240
241 "Activates or deactivates a chroot"
242
243 - def run(self, chroot_names, action):
254
255 option_list = ChrootCommand.option_list + (
256 Option("--action",
257 "-a",
258 dest="action",
259 help="Action to take - currently activate or deactivate",
260 choices=["activate", "deactivate"],
261 required=True),
262 )
263
264
266
267 "Activates or deactivates a chroot"
268
269 - def run(self, chroot_names):
278
279
281
282 "Displays current mock chroots"
283
284 - def run(self, active_only):
289
290 option_list = (
291 Option("--active-only",
292 "-a",
293 dest="active_only",
294 help="Display only active chroots",
295 required=False,
296 action="store_true",
297 default=False),
298 )
299
300
302
303 """
304 You should not use regularly as that user will not be related to FAS account.
305 This should be used only for testing or adding special accounts e.g. proxy user.
306 """
307
308 - def run(self, name, mail, **kwargs):
322
323 option_list = (
324 Option("name"),
325 Option("mail"),
326 Option("--api_token", default=None, required=False),
327 Option("--api_login", default=None, required=False),
328 )
329
330
332
333 - def run(self, name, **kwargs):
355
356 option_list = (
357 Option("name"),
358 Group(
359 Option("--admin",
360 action="store_true"),
361 Option("--no-admin",
362 action="store_true"),
363 exclusive=True
364 ),
365 Group(
366 Option("--proven",
367 action="store_true"),
368 Option("--no-proven",
369 action="store_true"),
370 exclusive=True
371 ),
372 Group(
373 Option("--proxy",
374 action="store_true"),
375 Option("--no-proxy",
376 action="store_true"),
377 exclusive=True
378 )
379 )
380
381
383
384 """
385 Marks build as failed on all its non-finished chroots
386 """
387
388 option_list = [Option("build_id")]
389
390 - def run(self, build_id, **kwargs):
391 try:
392 builds_logic.BuildsLogic.mark_as_failed(build_id)
393 print("Marking non-finished chroots of build {} as failed".format(build_id))
394 db.session.commit()
395
396 except (sqlalchemy.exc.DataError, sqlalchemy.orm.exc.NoResultFound) as e:
397 print("Error: No such build {}".format(build_id))
398 return 1
399
400
402 """
403 recreates whoosh indexes for all projects
404 """
405
422
423
425 """
426 Recreates whoosh indexes for projects for which
427 indexed data were updated in last n minutes.
428 Doesn't update schema.
429 """
430
431 option_list = [Option("minutes_passed")]
432
433 - def run(self, minutes_passed):
443
444
446 """
447 go through all coprs and create configuration rpm packages
448 for them, if they don't already have it
449 """
450
453
454
455 manager = Manager(app)
456 manager.add_command("test", TestCommand())
457 manager.add_command("create_sqlite_file", CreateSqliteFileCommand())
458 manager.add_command("create_db", CreateDBCommand())
459 manager.add_command("drop_db", DropDBCommand())
460 manager.add_command("create_chroot", CreateChrootCommand())
461 manager.add_command("alter_chroot", AlterChrootCommand())
462 manager.add_command("display_chroots", DisplayChrootsCommand())
463 manager.add_command("drop_chroot", DropChrootCommand())
464 manager.add_command("alter_user", AlterUserCommand())
465 manager.add_command("add_user", AddUserCommand())
466 manager.add_command("fail_build", FailBuildCommand())
467 manager.add_command("update_indexes", UpdateIndexesCommand())
468 manager.add_command("update_indexes_quick", UpdateIndexesQuickCommand())
469 manager.add_command("generate_repo_packages", GenerateRepoPackagesCommand())
470 manager.add_command("rawhide_to_release", RawhideToReleaseCommand())
471 manager.add_command("backend_rawhide_to_release", BackendRawhideToReleaseCommand())
472
473 if __name__ == "__main__":
474 manager.run()
475