summaryrefslogtreecommitdiffstats
path: root/check-external/unknown-packages.py
blob: 5156e99968b3f0d481bcf5dfa5ab5ce6016f1024 (plain) (blame)
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
#!/usr/bin/python
import urllib2
import SOAPpy
import os
import string
import sys
import json

cache_file=os.path.join(os.path.dirname(os.path.abspath(__file__)),'known-unknown-packages.cache')
db_file=os.path.join(os.path.dirname(os.path.abspath(__file__)),'../data/security.db')

def setup_paths():
    check_file = 'lib/python/debian_support.py'
    path = os.getcwd()
    while 1:
        if os.path.exists("%s/%s" % (path, check_file)):
            sys.path = [path + '/lib/python'] + sys.path
            return path
        idx = string.rfind(path, '/')
        if idx == -1:
            raise ImportError, "could not setup paths"
        path = path[0:idx]
os.chdir(setup_paths())

import security_db

try:
    db = security_db.DB(db_file)
    new_file = False
except security_db.SchemaMismatch:
    os.unlink(db_file)
    db = security_db.DB(db_file, verbose=True)
    new_file = True
    
ws = SOAPpy.SOAPProxy('https://packages.qa.debian.org/cgi-bin/soap-alpha.cgi')

def checkInPTS(pkg):
    try:
       ws.versions(source=pkg)
    except SOAPpy.faultType:
       return False
    else:
       return True

def fromSources(pkg):
    try: 
       data = json.load(urllib2.urlopen('http://sources.debian.net/api/src/%s/latest/' %pkg))
    except urllib2.HTTPError as e:
       return []
    if 'error' in data: return []
    else: return data['pkg_infos']['suites']

def updateAs(pkg,suite,cursor):
    kind = 'experimental' if suite == 'experimental' else 'gone:'+suite
    print pkg,kind
    cursor.execute("""UPDATE package_notes SET package_kind = ? WHERE package = ?""", (kind,pkg))

c=db.cursor()
pkgs=set([ i[0] for i in db.getUnknownPackages(c)])
pkgs.add('whatpackage');

for pkg in pkgs:
    suites = fromSources(pkg)
    if len(suites) >0:
       updateAs(pkg,suites[-1],c)
    else:
       if checkInPTS(pkg): updateAs(pkg,'n/a',c)
       else: print 'UNKNOWN'

© 2014-2024 Faster IT GmbH | imprint | privacy policy