예제 #1
0
    def _start_scan(self):
        try:
            db = DbInterface.DbInterface(self.db._dbfile)

            self.db2 = db

            self._scan(self.libraryLocation, '')

            db.close()

            wx.CallAfter(self._done_scan)

        except wx._core.PyDeadObjectError, e:
            db.close()

            print "Window destroyed uncleanly"
            print e
예제 #2
0
def createListingDb(dbFilePath):

    directory, filename = os.path.split(dbFilePath)
    if not os.path.isdir(directory):
        raise Exception("dir %s does not exist" % directory)

    if os.path.isfile(dbFilePath):
        raise Exception("file %s already exists" % dbFilePath)

    DbInterface.DbInterface.CreateEmptyDbFile(dbFilePath)
    newDb = DbInterface.DbInterface(dbFilePath)

    newDb.OpenConnection()

    createTableCommand = "create table %s (%s);" % (objectStoresTable,
                                                    objectStoresSchema)
    newDb.ExecuteNonQuerySql(createTableCommand)

    createTableCommand = "create table %s (%s);" % (FileListingTable,
                                                    FileListingSchema)
    newDb.ExecuteNonQuerySql(createTableCommand)

    newDb.CloseConnection()
예제 #3
0
    def _init_db(self):
        if self.libraryPath == '':
            print "No library path set"
            return False

        try:
            if os.path.isdir(self.libraryPath):
                self.metadataPath = os.path.join(self.libraryPath, 'metadata')
                if not os.path.isdir(self.metadataPath):
                    os.mkdir(self.metadataPath)

                self.postersPath = os.path.join(self.metadataPath, 'posters')
                if not os.path.isdir(self.postersPath):
                    os.mkdir(self.postersPath)

                self.catchPath = os.path.join(self.metadataPath, 'catch')
                if not os.path.isdir(self.catchPath):
                    os.mkdir(self.catchPath)

                self.db = DbInterface(
                    os.path.join(self.metadataPath, 'metadata.db'))

                if not self.db.isConnected():
                    print "Cannot connect to the metadata database"
                    return False

                print "Library Opened"
                return True

            else:
                print "Library path is invalid"
                return False

        except OSError, e:
            print "Cannot access the library"
            return False
예제 #4
0
        c = sortLater.getCountOfFilesInDepot(db, depotId)
        print "depot %d has %d entries" % (depotId, c)
        sum += c
    print "total is %d " % sum


def countFilesInDepotNotInPrimaryFilesTable(db, depotId):
    t1 = DepotInterface.FileListingTable
    t2 = TempPrimaryFilesTable
    command = "select count(*) from %s where depotId = %d and not exists (select filehash from %s where %s.filehash = %s.filehash); " % (
        t1, depotId, t2, t1, t2)
    return db.ExecuteSqlQueryReturningSingleInt(command)


databaseFilePathName = "C:\\depotListing\\listingDb.sqlite"
db = DbInterface.DbInterface(databaseFilePathName)

sortLater.printDepotInfo(db)

#sortLater.backupSingleLocationFilesInDepot(db, 8, 2)

#DepotInterface.ReInitializeLocationCounts(db)

#countFilesInDepotNotInPrimaryFilesTable(db, 8)

#command = "select * from %s where filehash = '%s'; " % (t1, "00000AA1E899DA256B7B6BC0C08AFCFEA9D78FEF")
command = "select * from %s where filehash = '%s'; " % (
    DepotInterface.LocationCountTable,
    "00000AA1E899DA256B7B6BC0C08AFCFEA9D78FEF")
command = "select * from %s where filehash = '%s'; " % (
    DepotInterface.OriginalDirectoryForFileTable,
예제 #5
0
import DbHelper
import DbInterface
import os.path
import SHA1HashUtilities

if os.path.isfile("trythis.sqlite"):
    os.remove("trythis.sqlite")

DbHelper.DbHelper.CreateDb("trythis.sqlite")

db = DbHelper.DbHelper("trythis.sqlite")
db.OpenConnection()
db.AddFile("0a4d55a8d778e5022fab701977c5d840bbc486d0", 1045)
db.AddFile("0000000000001111111111111111111111111110", -1)

dbInterface = DbInterface.DbInterface("trythis.sqlite")
query = "select * from FilesV2;"
print dbInterface.ExecuteSqlQueryReturningMultipleRows(query)
print ""

print "check if file 0a4d55a8d778e5022fab701977c5d840bbc486d0 found: should get True"
print db.FileAlreadyInDatabase("0a4d55a8d778e5022fab701977c5d840bbc486d0",
                               1045)
print ""

print "check if file 00001111 found: should get False"
print db.FileAlreadyInDatabase("00001111", 1045)
print ""

print "check if file 0a4d55a8d778e5022fab701977c5d840bbc486d0 with wrong filesize found: should get exception"
try:
예제 #6
0
		else:
			countOther += 1
			if (countOther) % 1000 == 0:
				print "countOther = %d" % countOther
		row = reader.next()

	print count0
	print count1
	print countOther


# copied from depotListing. Obviously TODO: put in common file.

oldDatabaseFilePathName = "C:\\depot\\db.sqlite"
oldDb = DbInterface.DbInterface(oldDatabaseFilePathName)
databaseFilePathName = "C:\\depotListing\\listingDb.sqlite"
db = DbInterface.DbInterface(databaseFilePathName)

#tempCheckInBoth(oldDb, db)
#portFiles(oldDb, db)
#portFilenames(oldDb, db)

#portFileStatus(oldDb, db)
#portFileLink(oldDb, db)

#portOriginalDirectories(oldDb, db)

#portOriginalDirectoriesForFile(oldDb, db)
#portOldOriginalRootDirectoryTable(oldDb, db)
#DepotInterface.printAllOldRootDirs(db)
예제 #7
0
import DbInterface

dbfile = "trythis.db"

db = DbInterface.DbInterface(dbfile)

db.ExecuteNonQuerySql("DROP TABLE IF EXISTS Cars")
db.ExecuteNonQuerySql("CREATE TABLE Cars(Id INT, Name TEXT, Price INT)")
db.ExecuteNonQuerySql("INSERT INTO Cars VALUES(1,'Audi',52642)")
db.ExecuteNonQuerySql("INSERT INTO Cars VALUES(2,'Mercedes',57127)")
db.ExecuteNonQuerySql("INSERT INTO Cars VALUES(3,'Skoda',9000)")
db.ExecuteNonQuerySql("INSERT INTO Cars VALUES(4,'Volvo',29000)")
db.ExecuteNonQuerySql("INSERT INTO Cars VALUES(5,'Bentley',350000)")
db.ExecuteNonQuerySql("INSERT INTO Cars VALUES(6,'Citroen',21000)")

row = db.ExecuteSqlQueryReturningSingleRow(
    "SELECT Name, Price FROM Cars WHERE Id=1")
print "row = %s" % str(row)

rows = db.ExecuteSqlQueryReturningMultipleRows("SELECT * FROM Cars")
print "rows = %s" % str(rows)

value = db.ExecuteSqlQueryReturningSingleInt(
    "SELECT Price FROM Cars WHERE Id=2")
print "value = %d" % value

values = db.ExecuteSqlQueryForStrings("SELECT Name FROM Cars")
print "values = %s" % str(values)

value = db.ExecuteSqlQueryForSingleString("SELECT Name FROM Cars WHERE Id=2")
print "value = %s" % value