3 from optparse
import OptionParser
4 import sys
, shutil
, tempfile
, urlparse
7 from logging
import info
9 from zeroinstall
import SafeException
10 from zeroinstall
.injector
import model
, gpg
, reader
14 parser
= OptionParser(usage
="usage: %prog [options] feed.xml")
15 parser
.add_option("-v", "--verbose", help="more verbose output", action
='count')
16 parser
.add_option("-V", "--version", help="display version information", action
='store_true')
18 (options
, args
) = parser
.parse_args()
21 print "FeedLint (zero-install) " + version
22 print "Copyright (C) 2007 Thomas Leonard"
23 print "This program comes with ABSOLUTELY NO WARRANTY,"
24 print "to the extent permitted by law."
25 print "You may redistribute copies of this program"
26 print "under the terms of the GNU General Public License."
27 print "For more information about these matters, see the file named COPYING."
31 logger
= logging
.getLogger()
32 if options
.verbose
== 1:
33 logger
.setLevel(logging
.INFO
)
35 logger
.setLevel(logging
.DEBUG
)
44 to_check
= [model
.canonical_iface_uri(a
) for a
in args
]
45 except SafeException
, ex
:
46 if options
.verbose
: raise
47 print >>sys
.stderr
, ex
50 def check_key(feed
, fingerprint
):
51 for line
in os
.popen('gpg --with-colons --list-keys %s' % s
.fingerprint
):
52 if line
.startswith('pub:'):
53 key_id
= line
.split(':')[4]
56 raise SafeException('Failed to find key with fingerprint %s on your keyring' % fingerprint
)
58 key_url
= urlparse
.urljoin(feed
, '%s.gpg' % key_id
)
59 print "Checking", key_url
61 if key_url
in checked
:
62 info("(already checked key URL)")
64 urllib2
.urlopen(key_url
).read()
72 info("Already checked feed %s", feed
)
77 print "Checking", feed
80 tmp
= tempfile
.TemporaryFile(prefix
= 'feedlint-')
82 stream
= urllib2
.urlopen(feed
)
83 shutil
.copyfileobj(stream
, tmp
)
84 data
, sigs
= gpg
.check_stream(tmp
)
87 if isinstance(s
, gpg
.ValidSig
):
88 check_key(feed
, s
.fingerprint
)
90 raise SafeException("Can't check sig: %s" % s
)
92 feed_tmp
= tempfile
.NamedTemporaryFile(prefix
= 'feedlint-')
94 shutil
.copyfileobj(data
, feed_tmp
)
96 iface
= model
.Interface(feed
)
97 reader
.update(iface
, feed_tmp
.name
)
100 info("Will check feed %s", f
.uri
)
101 to_check
.append(f
.uri
)
106 except urllib2
.HTTPError
, ex
:
107 print >>sys
.stderr
, ex
109 except SafeException
, ex
:
110 if options
.verbose
: raise
111 print >>sys
.stderr
, ex
117 print "\nERRORS FOUND:", n_errors