-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcheck-CPAN
executable file
·161 lines (125 loc) · 4.78 KB
/
check-CPAN
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version. Please read the COPYING file.
#
# Author:
# Serdar Dalgıç <serdar_at_pardus.org.tr>
#
"""
Script that checks daily cpan updates mail list
manually if there is an update on any perl packages
in Pardus repositories.
"""
import urllib2
import sys
import datetime as dt
try:
from BeautifulSoup import BeautifulSoup
except ImportError:
print "Please install python-beautifulsoup package"
sys.exit(1)
from optparse import OptionParser
from pisi.db.componentdb import ComponentDB
def get_perl_packages():
""" Return the list of perl packages in Pardus"""
return ComponentDB().get_union_packages( \
"programming.language.perl", walk=True)
def find_html_basename(_date):
""" Find the html basename for the cpan mail """
# Dec 29 2010 - 000983
# CPAN_URL for Dec 29 2010 is
# http://theoryx5.uwinnipeg.ca/pipermail/cpan-daily/2010-December/000983.html
reference = dt.datetime(2010, 12, 29)
difference = (reference - dt.datetime(_date.year, \
_date.month, \
_date.day)).days
# Shame on you CPAN, Sent two mails @ 7 November 2010
# This ugly hack is because of that.
if _date.year == 2010:
if _date.month < 11:
html_basename = "%0006d" % (983 - int(difference) - 1)
elif _date.month == 11 and _date.day < 7:
html_basename = "%0006d" % (983 - int(difference) - 1)
else:
html_basename = "%0006d" % (983 - int(difference) )
else:
html_basename = "%0006d" % (983 - int(difference) )
return html_basename
def create_cpan_url(days_before):
"""
creates and returns the cpan url
"""
url_body = "http://theoryx5.uwinnipeg.ca/pipermail/cpan-daily/"
target_date = dt.date.today() - dt.timedelta(days=days_before)
strdate = dt.datetime.strptime(str(target_date), "%Y-%m-%d")
month_name = strdate.strftime("%B")
return url_body + "%s-%s/%s.html" % (target_date.year, month_name, \
find_html_basename(target_date))
def get_pkg_infos(_page_element):
""" Return CPAN pkg names and whether
they are updated or not information.
returns orig_pkg_list and _updated_pkgs
"""
perl_pkgs = get_perl_packages()
orig_pkg_list = []
_updated_pkgs = {}
for url in _page_element.findAll():
orig_pkg_name = str(url.contents[0].split("/")[-1])
orig_pkg_list.append(orig_pkg_name)
if not orig_pkg_name.startswith("perl"):
pkg_name = "perl-" + orig_pkg_name
if pkg_name in perl_pkgs:
_updated_pkgs[orig_pkg_name] = url.contents[0]
return orig_pkg_list, _updated_pkgs
def argument():
"""Command line argument parsing"""
parser = OptionParser(usage = "Usage: %prog [-n days]", prog = sys.argv[0])
parser.add_option("-n", "--days_before",
action = "store",
type = "int",
dest = "days_before",
help = "Specify how many days before today you want to check")
return parser.parse_args()
if __name__ == "__main__":
'''
Python script that checks CPAN daily mail
for possible perl updates in Pardus.
'''
ARG = argument()
option = ARG[0]
if not option.days_before:
option.days_before = 0
print "Checking todays updates: %s" % dt.date.today()
else:
print "Checking %s days ago: %s" % (option.days_before, \
(dt.date.today() - \
dt.timedelta(days=option.days_before)))
CPAN_URL = create_cpan_url(option.days_before)
print "CPAN_URL: " + CPAN_URL + "\n"
try:
URLFILE = urllib2.urlopen(CPAN_URL)
except urllib2.HTTPError:
print "Cpan_URL can not be reached"
print "Double check your parameters"
sys.exit(1)
SOUP = BeautifulSoup(URLFILE.read())
# PAGE_ELEMENT consists of the part which includes
# daily CPAN Update information
PAGE_ELEMENT = SOUP.find('pre')
WHOLE_PKGS, UPDATED_PKGS = get_pkg_infos(PAGE_ELEMENT)
if not UPDATED_PKGS:
print "None of Pardus perl packages are updated" \
+ " according to CPAN daily update list"
sys.exit(1)
else:
print "These pkgs have updates:\n"
for pkg, p_url in UPDATED_PKGS.iteritems():
if not pkg.startswith("perl-"):
print "perl-" + pkg + " ----> " + p_url
else:
print pkg + " ----> " + p_url
print