summaryrefslogtreecommitdiff
blob: 55336aff277ba0f4925c95e2b28cad4b8254bd65 (plain)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/python
# Purpose  : Script to automatically check new Gentoo rsync and distfile mirrors
# Author(s): Shyam Mani <fox2mike@gentoo.org>
#          : Arun Raghavan <ford_prefect@gentoo.org>
#          : Robin H. Johnson <robbat2@gentoo.org>
# Created  : 05 Jul 2008

# Dedicated to robbat2 aka Robin, for sparking off the idea ;)

import sys
import time
import os
import datetime
import subprocess
import logging
import urllib2

import check

rmaxlag = 45 * 60
dmaxlag = 5.5 * 3600
relmaxlag = 2 * 3600

HOME = os.getenv('HOME')
reportpath = HOME + "/gentoo/mirrors/gard/reports"
bugurl = "http://bugs.gentoo.org/buglist.cgi?query_format=advanced&product=Mirrors&status_whiteboard_type=allwordssubstr&status_whiteboard=due&bug_status=ASSIGNED&columnlist=bug_id,opendate,bug_status,resolution,short_desc,status_whiteboard&ctype=csv"

logformat = '%(levelname)s:\t%(message)s'
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG, format=logformat)

def add_handler(logfile):
	file = logging.FileHandler(logfile)
	file.setLevel(logging.INFO)
	formatter = logging.Formatter(logformat)
	file.setFormatter(formatter)
	logging.getLogger('').addHandler(file)
	return file

def remove_handler(handler):
	logging.getLogger('').removeHandler(handler)

# TODO: Add a timeout
_ = urllib2.urlopen(bugurl)
file = _.readlines()
_.close()

logging.debug("Initializing G(entoo)A(utomated)R(sync)D(istfiles) checker script, version 2 (Katrina) - kicking mirror ass for Gentoo")

# Format of CSV = 234083,"2008-08-06 13:01:32","ASSIGNED",,"[rsync,distfiles|all] New mirror Cambrium BV (The Netherlands)","due:2008/09/01;dist:http://mirror.cambrium.nl/pub/os/linux/gentoo/|ftp://mirror.cambrium.nl/pub/os/linux/gentoo/|rsync://mirror.cambrium.nl/gentoo/;portage:mirror.cambrium.nl"

for line in file:
	line=line.replace("\n","")
	data=line.split(',')
	bugnum=data[0]
	swboard=data[5]
	if bugnum == "bug_id":
		continue
	else:
		details=swboard.split(';')
		duedate=details[0]
		duedate=duedate.replace("\"","")
		#print duedate
		urls=details[1].replace("dist:","")
		port=details[2].split(':')
		grsync=port[1].replace("\"","")
		temp=urls.split('|')
		http=temp[0]
		ftp=temp[1]
		drsync=temp[2]
		#print http
		#print ftp
		#print drsync
		#print grsync
		if len(http) > 0:
			boo=http.split('/')
			addy=boo[2]
		elif len(ftp) > 0:
			boo=ftp.split('/')
			addy=boo[2]
		else:
			addy=grsync
		#hdomain='/'+addy[2]
		if len(grsync) > 0:
			fname=reportpath+"/"+grsync
			if os.path.isdir(reportpath):
				pass
	        	else:
        	        	os.makedirs(reportpath)
			handler = add_handler(fname)
			info4=grsync+" wants to be a gentoo-portage mirror and is being checked as per Bug #"+bugnum
			logging.info(info4)
			addy = 'rsync://%s/' % addy
			check.PortageCheck(addy).check(rmaxlag)

			bugurl1 = "Bug URL : https://bugs.gentoo.org/"+bugnum+" , "+duedate
			logging.info(bugurl1)

			# New line for the prettiness
			logging.info('')
			remove_handler(handler)
		if len(http) > 0:
			fname=reportpath+"/"+addy
			if os.path.isdir(reportpath):
      				pass
        		else:
       				os.makedirs(reportpath)
			handler = add_handler(fname)
			info5 = addy+" wants to be source mirror and is being checked as per Bug #"+bugnum+ " over http"
			logging.info(info5)

			synced = True
			if check.DistfilesCheck(http).check(dmaxlag) is not True:
				synced = False
			if check.ReleasesCheck(http).check(relmaxlag) is not True:
				synced = False
			if synced:
				logging.info(addy + ' is in sync')
			else:
				logging.info(addy + ' is out of sync')

			bugurl1 = "Bug URL : https://bugs.gentoo.org/"+bugnum+" , "+duedate
			logging.info(bugurl1)

			# New line for the prettiness
			logging.info('')
			remove_handler(handler)
		if len(ftp) > 0:
			fname=reportpath+"/"+addy
			if os.path.isdir(reportpath):
       				pass
       			else:
       				os.makedirs(reportpath)
			add_handler(fname)
			info6 = addy+" wants to be an source mirror and is being checked as per Bug #"+bugnum+ " over ftp"
			logging.info(info6)

			synced = True
			if check.DistfilesCheck(ftp).check(dmaxlag) is not True:
				synced = False
			if check.ReleasesCheck(ftp).check(relmaxlag) is not True:
				synced = False
			if synced:
				logging.info(addy + ' is in sync')
			else:
				logging.info(addy + ' is out of sync')

			bugurl1 = "Bug URL : https://bugs.gentoo.org/"+bugnum+" , "+duedate
			logging.info(bugurl1)

			# New line for the prettiness
			logging.info('')
			remove_handler(handler)
		if len(drsync) > 0:
			# Replace with check.DistfilesCheck(drsyync).check()
			# after testing
			fname=reportpath+"/"+addy
			if os.path.isdir(reportpath):
	       			pass
      			else:
               			os.makedirs(reportpath)
			add_handler(fname)

			info7 = addy+" wants to be an source mirror and is being checked as per Bug #"+bugnum+ " over rsync"
			logging.info(info7)

			check.DistfilesCheck(drsync).check(dmaxlag)

			# Now common lines
			bugurl7 = "Bug URL : https://bugs.gentoo.org/"+bugnum+" , "+duedate
			logging.info(bugurl7)

			# New line for the prettiness
			logging.info('')
			remove_handler(handler)