-
Notifications
You must be signed in to change notification settings - Fork 0
/
daily_checks
executable file
·125 lines (110 loc) · 4.02 KB
/
daily_checks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env python2
"""
Daily checks to be done on the repositories, including backups and dependency
checking. For best results, this should be run as a cron job; however it can
also be run manually via the command line.
Many settings used by these scripts are taken from the configuration file, which
by default is installed to /etc/rutgers-repotools.cfg. If needed, you can
specify your own custom configuration file as a command line argument.
Scripts run by this file:
- repocheck
- depcheck
- koji_backup
"""
import ConfigParser
import argparse
import os
import sys
class App():
"""
Helper class for executing the checks.
"""
def __init__(self, config_file, verbose, no_mail, check_unstable):
"""
Initialize variables and run preliminary checks.
"""
self.config_file = config_file
self.verbose = verbose
self.no_mail = no_mail
self.check_unstable = check_unstable
# Sanity checks
if config_file is None:
raise Exception("Failed to find a valid configuration file.")
elif not os.path.isfile(config_file):
raise Exception("No such config file: {0}".format(config_file))
# Now, load the configuration file
self.config = ConfigParser.ConfigParser()
self.config.read(config_file)
def run(self):
"""
Run the actual scripts.
"""
self.koji_backup()
self.repocheck()
self.depcheck()
def koji_backup(self):
"""
Runs the Koji backup script.
"""
cmd = ["koji-backup"]
cmd.append(self.config.get("koji", "pkgdir"))
cmd.append(self.config.get("koji", "backupdir"))
if not self.verbose:
cmd.append("> /dev/null 2>&1")
os.system(" ".join(cmd))
def depcheck(self):
"""
Runs depcheck to do dependency checking on the repositories.
"""
distname = self.config.get("repositories", "distname")
distvers = self.config.get("repositories", "alldistvers").split()
repos = self.config.get("repositories", "repostodebug").split()
redirect = "" if self.verbose else "> /dev/null 2>&1"
for repo in [distname + v + "-" + r for v in distvers for r in repos]:
os.system("depcheck {0} {1}".format(repo, redirect))
def repocheck(self):
"""
Runs repocheck, which checks the sanity of the repository hierarchy.
"""
cmd = ["repocheck"]
cmd.append("--config-file={0}".format(self.config_file))
if self.no_mail:
cmd.append("--no-mail")
if self.check_unstable:
cmd.append("--check-unstable")
redirect = "" if self.verbose else "> /dev/null 2>&1"
# Check the sanity of the repositories for each version
for version in self.config.get("repositories", "alldistvers").split():
os.system("{0} {1} {2}".format(" ".join(cmd), version, redirect))
if __name__ == "__main__":
# Set up command line options
parser = argparse.ArgumentParser(
prog="daily_checks",
description="daily_checks - Perform repository backups and checks",
epilog="Made by Rutgers Open System Solutions.")
parser.add_argument(
"--no-mail",
action="store_true",
help="Suppress sending mail after the check.")
parser.add_argument(
"-c",
"--config-file",
default="/etc/daily_checks.cfg",
help="The configuration file to use.")
parser.add_argument(
"-v",
"--verbose",
action="store_true",
help="Use verbose output.")
parser.add_argument(
"-u",
"--check-unstable",
action="store_true",
help="Check the unstable repository. Off by default.")
# Now, actually do work
app = App(**parser.parse_args().__dict__)
try:
app.run()
except Exception as e:
sys.stderr.write("Error: {0}".format(e.message))
sys.exit(1)