Changeset View
Changeset View
Standalone View
Standalone View
bin/InstallDB.py
Show First 20 Lines • Show All 111 Lines • ▼ Show 20 Line(s) | |||||
112 | class InstallDB(object): | 112 | class InstallDB(object): | ||
113 | """ a database object which provides the methods for adding and removing a package and | 113 | """ a database object which provides the methods for adding and removing a package and | ||
114 | checking its installation status. | 114 | checking its installation status. | ||
115 | In case the database doesn't exist if the constructor is called, a new database is constructed | 115 | In case the database doesn't exist if the constructor is called, a new database is constructed | ||
116 | """ | 116 | """ | ||
117 | 117 | | |||
118 | def __init__( self, filename = None ): | 118 | def __init__( self, filename = None ): | ||
119 | if filename == None: | 119 | if filename == None: | ||
120 | EmergeStandardDirs.allowShortpaths(False) | 120 | with TemporaryUseShortpath(False): | ||
121 | filename = os.path.join( EmergeStandardDirs.etcPortageDir(), 'install.db' ) | 121 | filename = os.path.join( EmergeStandardDirs.etcPortageDir(), 'install.db' ) | ||
122 | EmergeStandardDirs.allowShortpaths(True) | | |||
123 | 122 | | |||
124 | self.dbfilename = filename | 123 | self.dbfilename = filename | ||
125 | self._prepareDatabase() | 124 | self._prepareDatabase() | ||
126 | 125 | | |||
127 | def getLastId( self ): | 126 | def getLastId( self ): | ||
128 | """ returns the last id from a table, which is essentially the """ | 127 | """ returns the last id from a table, which is essentially the """ | ||
129 | cmd = '''SELECT max(packageId) FROM packageList;''' | 128 | cmd = '''SELECT max(packageId) FROM packageList;''' | ||
130 | 129 | | |||
▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Line(s) | 141 | # | |||
247 | 246 | | |||
248 | def getInstalledPackages( self, category, package, prefix = None ): | 247 | def getInstalledPackages( self, category, package, prefix = None ): | ||
249 | """ return an installed package """ | 248 | """ return an installed package """ | ||
250 | cursor = self.connection.cursor() | 249 | cursor = self.connection.cursor() | ||
251 | return [ InstallPackage( cursor, pId ) for pId in self.getPackageIds( category, package, prefix ) ] | 250 | return [ InstallPackage( cursor, pId ) for pId in self.getPackageIds( category, package, prefix ) ] | ||
252 | 251 | | |||
253 | def _prepareDatabase( self ): | 252 | def _prepareDatabase( self ): | ||
254 | """ prepare a new database and add the required table layout """ | 253 | """ prepare a new database and add the required table layout """ | ||
255 | if not os.path.exists( self.dbfilename ): | 254 | with TemporaryUseShortpath(False): | ||
256 | EmergeStandardDirs.allowShortpaths(False) | 255 | if not os.path.exists( self.dbfilename ): | ||
257 | if not os.path.exists( EmergeStandardDirs.etcPortageDir( ) ): | 256 | if not os.path.exists( EmergeStandardDirs.etcPortageDir( ) ): | ||
258 | os.makedirs( EmergeStandardDirs.etcPortageDir( ) ) | 257 | os.makedirs( EmergeStandardDirs.etcPortageDir( ) ) | ||
259 | print( "database does not exist yet: creating database", file = sys.stderr ) | 258 | print( "database does not exist yet: creating database", file = sys.stderr ) | ||
260 | self.connection = sqlite3.connect( self.dbfilename ) | 259 | self.connection = sqlite3.connect( self.dbfilename ) | ||
261 | cursor = self.connection.cursor() | 260 | cursor = self.connection.cursor() | ||
262 | 261 | | |||
263 | # first, create the required tables | 262 | # first, create the required tables | ||
264 | cursor.execute( '''CREATE TABLE packageList (packageId INTEGER PRIMARY KEY AUTOINCREMENT, | 263 | cursor.execute( '''CREATE TABLE packageList (packageId INTEGER PRIMARY KEY AUTOINCREMENT, | ||
265 | prefix TEXT, category TEXT, packageName TEXT, version TEXT, revision TEXT)''' ) | 264 | prefix TEXT, category TEXT, packageName TEXT, version TEXT, revision TEXT)''' ) | ||
266 | cursor.execute( '''CREATE TABLE fileList (fileId INTEGER PRIMARY KEY AUTOINCREMENT, | 265 | cursor.execute( '''CREATE TABLE fileList (fileId INTEGER PRIMARY KEY AUTOINCREMENT, | ||
267 | packageId INTEGER, filename TEXT, fileHash TEXT)''' ) | 266 | packageId INTEGER, filename TEXT, fileHash TEXT)''' ) | ||
268 | self.connection.commit() | 267 | self.connection.commit() | ||
269 | else: | 268 | else: | ||
270 | self.connection = sqlite3.connect( self.dbfilename ) | 269 | self.connection = sqlite3.connect( self.dbfilename ) | ||
271 | cursor = self.connection.cursor() | 270 | cursor = self.connection.cursor() | ||
272 | cursor.execute( '''PRAGMA table_info('packageList')''') | 271 | cursor.execute( '''PRAGMA table_info('packageList')''') | ||
273 | if not len(cursor.fetchall()) == 6: | 272 | if not len(cursor.fetchall()) == 6: | ||
274 | cursor.execute('''ALTER TABLE packageList ADD COLUMN revision TEXT''') | 273 | cursor.execute('''ALTER TABLE packageList ADD COLUMN revision TEXT''') | ||
275 | self.connection.commit() | 274 | self.connection.commit() | ||
276 | EmergeStandardDirs.allowShortpaths(True) | | |||
277 | 275 | | |||
278 | 276 | | |||
279 | # get a global object | 277 | # get a global object | ||
280 | installdb = InstallDB() | 278 | installdb = InstallDB() | ||
281 | 279 | | |||
282 | # an additional function from portage.py | 280 | # an additional function from portage.py | ||
283 | def printInstalled(): | 281 | def printInstalled(): | ||
284 | """get all the packages that are already installed""" | 282 | """get all the packages that are already installed""" | ||
▲ Show 20 Lines • Show All 101 Lines • Show Last 20 Lines |