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

Contents of /src/packages/purge_db.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download) (as text)
Fri Feb 20 00:01:42 2004 UTC (10 years, 8 months ago) by marduk
Branch: MAIN
CVS Tags: release_1-5, v1_3_1, HEAD
Branch point for: pre_2-0, v1_3
Changes since 1.1: +1 -1 lines
File MIME type: text/x-python
Had name and category reversed in delete_package

1 #!/usr/bin/python -OO
2
3 import os
4 import config
5 import ebuilddb
6
7 def delete_ebuild(db,ebuild):
8 category, name, version = ebuild[:3]
9 c = db.cursor()
10 query = ('DELETE FROM ebuild WHERE category="%s" AND name="%s" '
11 'AND version="%s"' % (category,name,version))
12 #print query
13 c.execute(query)
14
15 def delete_package(db,package):
16 category, name = package[:2]
17 c = db.cursor()
18 query = ('DELETE FROM package WHERE name="%s" AND category="%s"' %
19 (name,category))
20 #print query
21 c.execute(query)
22
23 def get_path(ebuild):
24 category, name, version = ebuild[:3]
25 ebuild_fname = os.path.join(config.PORTAGE_DIR,category,name,
26 '%s-%s.ebuild' % (name,version))
27 return ebuild_fname
28
29 def ebuilds_in_package(db,package):
30 """using db database, return ebuilds in package"""
31 category, name = package[:2]
32 c = db.cursor()
33 query =('SELECT * FROM ebuild WHERE category="%s" AND NAME="%s"'
34 % (category,name))
35 c.execute(query)
36 results = c.fetchall()
37 return results
38
39 def purge_ebuilds(db):
40 """Purge the ebuild table"""
41 c = db.cursor()
42 query = ('SELECT * FROM ebuild')
43 c.execute(query)
44
45 while 1:
46 ebuild = c.fetchone()
47 if not ebuild: break
48 path = get_path(ebuild)
49
50 if not os.path.exists(path):
51 print path,' does not exist.'
52 delete_ebuild(db,ebuild)
53
54
55 def purge_packages(db):
56 """Purge the package table"""
57 c = db.cursor()
58 query = ('SELECT * FROM package')
59 c.execute(query)
60
61 while 1:
62 package = c.fetchone()
63 if not package: break
64 count = len(ebuilds_in_package(db,package))
65 if not count:
66 delete_package(db,package)
67
68 def main():
69 db = ebuilddb.db_connect()
70 purge_ebuilds(db)
71 purge_packages(db)
72
73
74 if __name__ == '__main__':
75 main()

  ViewVC Help
Powered by ViewVC 1.1.20