예제 #1
0
파일: renameapi.py 프로젝트: meastp/veefire
    def loadFiles(self):
        ## Load Databse (optionally with limits.)
        self.database = Database(self.dbDir, self.shows)
        self.database.loadDB()

        ## Add FileNames to folder.
        self.fileNames = []
        for afile in os.listdir(self.path):
            if os.path.isfile(os.path.join(self.path, afile)):
                aFileName = FileName(afile, self.database)

                self.fileNames.append(aFileName)
예제 #2
0
 def __init__( self, dbDir=None, shows=None ) :
     '''
     :param dbDir: Path to database directory
     :type dbDir: string or None
     :param shows: list of valid Shows in this database
     :type shows: list or None
     '''
     self.dbDir = dbDir
     self.shows = shows
     
     self.currentDB = Database(self.dbDir, self.shows)
     self.currentDB.loadDB()
     
     self.updateDB = Database(self.dbDir)
예제 #3
0
 def incrementalUpdate( self ) :
     """
     Updates Database incrementally, not overwriting unless allowed.
     
     :rtype: None
     """
     self.mergeDB = Database(self.dbDir)
     
     for newShow in self.updateDB.database :
         
         currentShow = self.currentDB.getShow( newShow )
         
         if currentShow == None :
             self.mergeDB.addShow( newShow )
         
         else :
             self.mergeDB.addShow( self.compareDetails( currentShow , newShow ) )
             
     return self.mergeDB
예제 #4
0
파일: renameapi.py 프로젝트: meastp/veefire
 def loadFiles( self ) :
     ## Load Databse (optionally with limits.)
     self.database = Database( self.dbDir , self.shows )
     self.database.loadDB()
     
     ## Add FileNames to folder.
     self.fileNames = []
     for afile in os.listdir( self.path ) :
         if os.path.isfile( os.path.join( self.path, afile) ) :
             aFileName = FileName( afile, self.database )
             
             self.fileNames.append( aFileName )
예제 #5
0
파일: renameapi.py 프로젝트: meastp/veefire
class Folder:
    """
    A Folder. Contains FileNames.
    """
    def __init__(self, path, dbDir=None, shows=None):
        """
        :param path: folder path to search in
        :type path: string
        :param dbDir: Path to database directory
        :type dbDir: string or None
        :param shows: limit shows to search through by passing a list of Show objects
        :type shows: list or none
        """
        self.dbDir = dbDir
        self.shows = shows
        self.path = path

    def __cmp__(self, other):
        """
        :param other: object to compare with
        :type other: :class:`api.renameapi.Folder` or None
        """
        if other == None:
            return False

        if self.dbDir != other.dbDir or self.path != other.path:
            return False

        if self.shows == None and other.shows == None:
            return True

        for i in xrange(0, len(self.shows)):
            if self.shows[i].fileName != other.shows[i].fileName:
                return False

        return True

    def loadFiles(self):
        ## Load Databse (optionally with limits.)
        self.database = Database(self.dbDir, self.shows)
        self.database.loadDB()

        ## Add FileNames to folder.
        self.fileNames = []
        for afile in os.listdir(self.path):
            if os.path.isfile(os.path.join(self.path, afile)):
                aFileName = FileName(afile, self.database)

                self.fileNames.append(aFileName)

    def getMatchingShows(self):
        """
        Get Possible show matches for every FileName.
        
        :returns: list of FileName objects
        :rtype: list
        """
        for FileName in self.fileNames:
            FileName.getMatchingShows()
        return self.fileNames

    def generatePreviews(self, filesystemDir, fileSystem, Style):
        """
        Generate previews for every FileName.
        
        :param filesystemDir: Path to filetypes.xml
        :type filesystemDir: string
        :param fileSystem: Filesystem to use
        :type fileSystem: string
        :param Style: Style to use for the new file name
        :type Style: string or None
        :returns: list of tuples (oldname, newname) for every FileName
        :rtype: list
        """
        previews = []
        for FileName in self.fileNames:
            previews.append(
                FileName.generatePreview(filesystemDir, fileSystem, Style))
        return previews

    def rename(self):
        for filename in self.fileNames:
            try:
                filename.renameFile(self.path)
            except:
                print "Not a valid filename"

    def revert(self):
        for filename in self.fileNames:
            try:
                filename.revertFile(self.path)
            except:
                print "not a valid filename"
예제 #6
0
f = "sonu monu manoj krishna mahesh ankit samarth".split()
l = "sharma verma singh kapoor chadhdha".split()
data = [[choice(f), choice(l), randint(20, 45)] for x in range(10)]
# ------LOCAL---------
# user = Database(
#     dbkind="local",
#     dbpath="mydb.db",
#     dbmodule="sqlite3",
#     querymodule = "query"
# )

#-------SERVER----------
user = Database(
    dbkind="server",
    dbmodule="mysql.connector",
    querymodule="query",
    host="remotemysql.com",
    port=3306,
    database="kmeSJcz0Au",
    user="******",
    password="******",
)

#user.info()

print('TABLE CREATED') if user.createtable() else print('TABLE NOT CREATED')

#print('DATA INSERTED') if user.insertdata(data) else print('DATA NOT INSERTED')

print(user.readdata(5))
예제 #7
0
from dbapi import Database



dbapi = Database()

boards = [Board(name) for name in dbapi.boards()]

threads = [Thread(id, title, text, board) for (id, title, text, board) in dbapi.threads()]

posts = [Post(id, text, thread_id) for (id, text, thread_id) in dbapi.posts()]




예제 #8
0
from dbapi import Database

user=Database(
dbkind="local"
dbpath="mypath.db"
dbmodule="sqlite3"

)
예제 #9
0
class BackendInterface :
    """
    Common methods to interface with the backends.
    """
    def __init__( self, dbDir=None, shows=None ) :
        '''
        :param dbDir: Path to database directory
        :type dbDir: string or None
        :param shows: list of valid Shows in this database
        :type shows: list or None
        '''
        self.dbDir = dbDir
        self.shows = shows
        
        self.currentDB = Database(self.dbDir, self.shows)
        self.currentDB.loadDB()
        
        self.updateDB = Database(self.dbDir)
    
    def addNewShow ( self, Show ) :
        """
        Add show to database.
        
        :param Show: a Show object to add to Database
        :type Show: :class:`api.dbapi.Show`
        :rtype: :class:`api.dbapi.Show` or None
        """
        return self.currentDB.addShow( Show )
    
    def updateDatabase ( self ) :
        """
        Update database.
        
        :rtype: None
        """
        newdb = self.fillUpdateDB()
        
        #self.mergeDB.printDb()
        
        newdb.write()
    
    def fillUpdateDB( self ) :
        """
        Copies the Shows from the database to a temporary database, for determining what shows to update.
        
        :rtype: None
        """
        self.updateDB = copy.deepcopy( self.currentDB )
        
        
        backends = dict()
        
        ## Group every Show into the backend used.
        for Show in self.updateDB.database :
            Show.clearEpisodes()
            if backends.has_key( Show.backend ) == False :
                backends[ Show.backend ] = [ copy.deepcopy(Show) ]
            else :
                backends[ Show.backend ].append( copy.deepcopy(Show) )
        
        
        for backend, Shows in backends.iteritems() :
            exec( 'backend = ' + backend + '()' )
            
            ## Download every Show in one backend before moving on to another backend.
            dictionary = backend.downloadShowList( Shows )
            DB = backend.getShowDetails( dictionary )
            
            ## Populate the updateDB
            for Show in DB.database :
                show = self.updateDB.getShow( Show )
                for Season in Show.seasons :
                    show.addSeason( Season )
        
        
        return self.incrementalUpdate()
        
    def incrementalUpdate( self ) :
        """
        Updates Database incrementally, not overwriting unless allowed.
        
        :rtype: None
        """
        self.mergeDB = Database(self.dbDir)
        
        for newShow in self.updateDB.database :
            
            currentShow = self.currentDB.getShow( newShow )
            
            if currentShow == None :
                self.mergeDB.addShow( newShow )
            
            else :
                self.mergeDB.addShow( self.compareDetails( currentShow , newShow ) )
                
        return self.mergeDB
    
    def compareDetails( self, currentShow, newShow ) :
        """
        Compares two Shows for differences.
        
        :param currentShow: Old show
        :type currentShow: :class:`api.dbapi.Show`
        :param newShow: New show
        :type newShow: :class:`api.dbapi.Show`
        :returns: Updated show.
        :rtype: :class:`api.dbapi.Show`
        """
        editedShow = Show( currentShow.name, currentShow.duration, currentShow.backend, currentShow.url )
        
        for newSeason in newShow.seasons :
            
            currentSeason = currentShow.getSeason( newSeason )
            
            if currentSeason == None :
                editedShow.addSeason( newSeason )
            
            else :
                editedShow.addSeason( self.compareSeasons( currentSeason, newSeason ) )
                
        return editedShow
        
    def compareSeasons( self, currentSeason, newSeason) :
        """
        Compares two Seasons for differences.
        
        :param currentSeason: Old season
        :type currentSeason: :class:`api.dbapi.Season`
        :param newSeason: New season
        :type newSeason: :class:`api.dbapi.Seson`
        :returns: Updated season.
        :rtype: :class:`api.dbapi.Season`
        """
        editedSeason = Season(currentSeason.name)
        
        for newEpisode in newSeason.episodes :
            
            currentEpisode = currentSeason.getEpisode( newEpisode )
            
#            print '##S'
#            print currentEpisode.title
#            print currentEpisode
#            print '##E'
            
            if currentEpisode == None :
                editedSeason.addEpisode( newEpisode )
#                print '## ## None'
            else :
                ny = editedSeason.addEpisode( self.compareEpisodes( currentEpisode, newEpisode ) )
#                print '  ###'
#            print '     ' + ny.title
#            print '     ' + str(ny)
#            print '  ###'
            
        return editedSeason
        
    def compareEpisodes ( self, currentEpisode, newEpisode ) :
        """
        Compares two Episodes for differences.
        
        :param currentEpisode: Old episode
        :type currentEpisode: :class:`api.dbapi.Episode`
        :param newEpisode: New episode
        :type newEpisode: :class:`api.dbapi.Episode`
        :returns: Updated episode or None, if there are no differences.
        :rtype: :class:`api.dbapi.Season` or None
        """
        conflict = False
        
        if currentEpisode.title != newEpisode.title :
            conflict = True
        
        #FIXME: Airdates
        #if currentEpisode.airdate != newEpisode.airdate :
        #    conflict = True
        
        #FIXME: Arcs
        #if currentEpisode.arc != newEpisode.arc :
        #    conflict = True
        
        if conflict == True :
            return self.solveEpisodeConflicts( currentEpisode, newEpisode )
        else :
            return currentEpisode
        
    def solveEpisodeConflicts ( self, firstEpisode, secondEpisode ) :
        """
        Choose which episode details to keep.
        
        .. warning::
            This function is abstract. It raises an exception.
        
        :param firstEpisode: Old episode
        :type firstEpisode: :class:`api.dbapi.Episode`
        :param secondEpisode: New episode
        :type secondEpisode: :class:`api.dbapi.Episode`
        :rtype: :class:`api.dbapi.Episode`
        """
        
#        print '          conflict: ' + str(firstEpisode) + ':' + firstEpisode.title + ' vs. ' + str(secondEpisode) + ':' + secondEpisode.title
#        return secondEpisode
        
        raise NotImplementedError
예제 #10
0
파일: renameapi.py 프로젝트: meastp/veefire
class Folder :
    """
    A Folder. Contains FileNames.
    """
    def __init__ (self, path, dbDir=None, shows=None) :
        """
        :param path: folder path to search in
        :type path: string
        :param dbDir: Path to database directory
        :type dbDir: string or None
        :param shows: limit shows to search through by passing a list of Show objects
        :type shows: list or none
        """
        self.dbDir = dbDir
        self.shows = shows
        self.path = path
        
    def __cmp__(self, other):
        """
        :param other: object to compare with
        :type other: :class:`api.renameapi.Folder` or None
        """
        if other == None :
            return False
        
        if self.dbDir != other.dbDir or self.path != other.path :
            return False
        
        if self.shows == None and other.shows == None :
            return True
        
        for i in xrange(0, len(self.shows)) :
            if self.shows[i].fileName != other.shows[i].fileName :
                return False
        
        return True
        
    def loadFiles( self ) :
        ## Load Databse (optionally with limits.)
        self.database = Database( self.dbDir , self.shows )
        self.database.loadDB()
        
        ## Add FileNames to folder.
        self.fileNames = []
        for afile in os.listdir( self.path ) :
            if os.path.isfile( os.path.join( self.path, afile) ) :
                aFileName = FileName( afile, self.database )
                
                self.fileNames.append( aFileName )
    
    def getMatchingShows(self) :
        """
        Get Possible show matches for every FileName.
        
        :returns: list of FileName objects
        :rtype: list
        """
        for FileName in self.fileNames :
            FileName.getMatchingShows()
        return self.fileNames
        
    def generatePreviews(self, filesystemDir, fileSystem, Style) :
        """
        Generate previews for every FileName.
        
        :param filesystemDir: Path to filetypes.xml
        :type filesystemDir: string
        :param fileSystem: Filesystem to use
        :type fileSystem: string
        :param Style: Style to use for the new file name
        :type Style: string or None
        :returns: list of tuples (oldname, newname) for every FileName
        :rtype: list
        """
        previews = []
        for FileName in self.fileNames :
            previews.append(FileName.generatePreview(filesystemDir, fileSystem, Style))
        return previews
        
    def rename(self):
        for filename in self.fileNames:
            try:
                filename.renameFile( self.path )
            except:
                print "Not a valid filename"
                
    def revert(self):
        for filename in self.fileNames:
            try:
                filename.revertFile( self.path )
            except:
                print "not a valid filename"