/[gentoo]/src/packages/ebuilddb.py
Gentoo

Diff of /src/packages/ebuilddb.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.2 Revision 1.3
6import time 6import time
7import re 7import re
8import changelogs 8import changelogs
9import MySQLdb 9import MySQLdb
10 10
11FINDVER = re.compile('-[0-9]') 11# import portage, but temporarily redirect stderr
12if 'portage' not in dir():
13 null = open('/dev/null', 'w')
14 tmp = sys.stderr
15 sys.stderr = null
16 sys.path = ["/usr/lib/portage/pym"]+sys.path
17 import portage
18 sys.stderr = tmp
19 sys.path = sys.path[1:]
12 20
13def db_connect(): 21def db_connect():
14 return MySQLdb.connect(host = config.HOST, 22 return MySQLdb.connect(host = config.HOST,
15 user = config.USER, 23 user = config.USER,
16 passwd = config.PASSWD, 24 passwd = config.PASSWD,
29 """Parse ebuild info based on path name""" 37 """Parse ebuild info based on path name"""
30 parsed = {} 38 parsed = {}
31 s=s.split('/') 39 s=s.split('/')
32 parsed['category'] = s[-3] 40 parsed['category'] = s[-3]
33 package = s[-1].split('.ebuild')[0] 41 package = s[-1].split('.ebuild')[0]
34 pos=FINDVER.search(package).start() 42 pieces = portage.pkgsplit(package)
43 if not pieces:
44 return None
35 parsed['name'] = package[:pos] 45 parsed['name'] = pieces[0]
46 if pieces[2] == 'r0':
36 parsed['version'] = package[pos+1:] 47 parsed['version'] = pieces[1]
48 else:
49 parsed['version'] = '-'.join(pieces[1:])
37 50
38 return parsed 51 return parsed
39 52
40def get_ebuild_record(db,ebinfo): 53def get_ebuild_record(db,ebinfo):
41 c = db.cursor() 54 c = db.cursor()
64 d.execute(query) 77 d.execute(query)
65 78
66def update_ebuild_record(db,ebinfo): 79def update_ebuild_record(db,ebinfo):
67 c = db.cursor() 80 c = db.cursor()
68 escaped = dict([(x,MySQLdb.escape_string(y)) for (x,y) in ebinfo.items()]) 81 escaped = dict([(x,MySQLdb.escape_string(y)) for (x,y) in ebinfo.items()])
82 query="""REPLACE INTO package VALUES ("%(category)s","%(name)s",\
83 "%(homepage)s","%(description)s","%(license)s");""" % escaped
84 c.execute(query)
85
69 query = ('UPDATE ebuild ' 86 query = ('UPDATE ebuild '
70 'SET when_found="%(time)s",' 87 'SET when_found="%(time)s",'
71 'arch="%(archs)s",' 88 'arch="%(archs)s",'
72 'changelog="%(changelog)s",' 89 'changelog="%(changelog)s",'
73 'prevarch="%(prevarch)s" ' 90 'prevarch="%(prevarch)s" '
74 'WHERE category="%(category)s" ' 91 'WHERE category="%(category)s" '
75 'AND name="%(name)s" ' 92 'AND name="%(name)s" '
76 'AND version="%(version)s" ' % escaped) 93 'AND version="%(version)s" ' % escaped)
94 try:
77 c.execute(query) 95 c.execute(query)
96 except MySQLdb.MySQLError, data:
97 print 'error occurred: '
98 print 'query: %s' % query
99 print 'error: %s' % data
100
78 101
79def get_extended_info(ebuild): 102def get_extended_info(ebuild):
80 filename = os.path.join(config.PORTAGE_DIR,'metadata/cache', 103 filename = os.path.join(config.PORTAGE_DIR,'metadata/cache',
81 ebuild['category'],'%s-%s' % (ebuild['name'],ebuild['version'])) 104 ebuild['category'],'%s-%s' % (ebuild['name'],ebuild['version']))
82 try: 105 try:
114def main(): 137def main():
115 ebuilds = find_ebuilds() 138 ebuilds = find_ebuilds()
116 db = db_connect() 139 db = db_connect()
117 140
118 for s in ebuilds: 141 for s in ebuilds:
119 try:
120 fields = parse_ebuild(s) 142 fields = parse_ebuild(s)
121 except: 143 if not fields:
122 continue 144 continue
123 result = get_ebuild_record(db,fields) 145 result = get_ebuild_record(db,fields)
124 fields = get_extended_info(fields) 146 fields = get_extended_info(fields)
125 fields['changelog'] = changelogs.changelog('%s/ChangeLog' 147 fields['changelog'] = changelogs.changelog('%s/ChangeLog'
126 % os.path.dirname(s)) 148 % os.path.dirname(s))
132 #print 'db archs=',result[4] 154 #print 'db archs=',result[4]
133 #print 155 #print
134 # keywords change, update db 156 # keywords change, update db
135 fields['prevarch'] = result[4] 157 fields['prevarch'] = result[4]
136 update_ebuild_record(db,fields) 158 update_ebuild_record(db,fields)
137
138 159
139if __name__ == '__main__': 160if __name__ == '__main__':
140 main() 161 main()

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.20