Пример #1
0
   def _migrateExistingData(self):
      """ If we don't have any data, we may be using a sqlite interface for the first time.
      See if they have another database backend specified, and if they do, try to migrate the data."""
      
      if self._getTables(): return
      
      cursor = self.sqlConnection.cursor()
      cursor.execute("BEGIN TRANSACTION")
      for statement in self._getCreateStatements():
         cursor.execute(statement)

      if self._autoConvertDatabase:
         prevDBType = rdw_config.getConfigSetting("UserDB")
         if prevDBType.lower() == "mysql":
            print 'Converting database from mysql...'
            import db_mysql
            prevDB = db_mysql.mysqlUserDB()
            users = prevDB._executeQuery("SELECT UserID, Username, Password, UserRoot, IsAdmin, UserEmail, RestoreFormat FROM users")
            cursor.executemany("INSERT INTO users (UserID, Username, Password, UserRoot, IsAdmin, UserEmail, RestoreFormat) values (?, ?, ?, ?, ?, ?, ?)", users)
            
            repos = prevDB._executeQuery("SELECT UserID, RepoPath, MaxAge FROM repos")
            cursor.executemany("INSERT INTO repos (UserID, RepoPath, MaxAge) values (?, ?, ?)", repos)
         elif prevDBType.lower() == "file":
            print 'Converting database from file...'
            import db_file
            prevDB = db_file.fileUserDB()
            username = rdw_config.getConfigSetting("username")
            password = rdw_config.getConfigSetting("password")
            self.addUser(username)
            self.setUserPassword(username, password)
            self.setUserInfo(username, prevDB.getUserRoot(username), True)
            self.setUserRepos(username, prevDB.getUserRepoPaths(username))
         
      cursor.execute("COMMIT TRANSACTION")
Пример #2
0
 def getUserDBModule(self):
    authModuleSetting = rdw_config.getConfigSetting("UserDB");
    if authModuleSetting.lower() == "file":
       return db_file.fileUserDB()
    if authModuleSetting.lower() == "mysql":
       return db_mysql.mysqlUserDB()
    assert(False)
Пример #3
0
   def _migrateExistingData(self):
      """ If we don't have any data, we may be using a sqlite interface for the first time.
      See if they have another database backend specified, and if they do, try to migrate the data."""
      
      if self._getTables(): return
      
      cursor = self.sqlConnection.cursor()
      cursor.execute("BEGIN TRANSACTION")
      for statement in self._getCreateStatements():
         cursor.execute(statement)

      if self._autoConvertDatabase:
         prevDBType = rdw_config.getConfigSetting("UserDB")
         if prevDBType.lower() == "mysql":
            print 'Converting database from mysql...'
            import db_mysql
            prevDB = db_mysql.mysqlUserDB()
            users = prevDB._executeQuery("SELECT UserID, Username, Password, UserRoot, IsAdmin, UserEmail, RestoreFormat FROM users")
            cursor.executemany("INSERT INTO users (UserID, Username, Password, UserRoot, IsAdmin, UserEmail, RestoreFormat) values (?, ?, ?, ?, ?, ?, ?)", users)
            
            repos = prevDB._executeQuery("SELECT UserID, RepoPath, MaxAge FROM repos")
            cursor.executemany("INSERT INTO repos (UserID, RepoPath, MaxAge) values (?, ?, ?)", repos)
         elif prevDBType.lower() == "file":
            print 'Converting database from file...'
            import db_file
            prevDB = db_file.fileUserDB()
            username = rdw_config.getConfigSetting("username")
            password = rdw_config.getConfigSetting("password")
            self.addUser(username)
            self.setUserPassword(username, password)
            self.setUserInfo(username, prevDB.getUserRoot(username), True)
            self.setUserRepos(username, prevDB.getUserRepoPaths(username))
         
      cursor.execute("COMMIT TRANSACTION")
Пример #4
0
 def get_userdb_module(self):
     # Return a different implementation according to UserDB configuration.
     prevDBType = rdw_config.get_config("UserDB")
     if prevDBType.lower() == "ldap":
         import db_ldap
         import db_sqlite
         return db_ldap.ldapUserDB(db_sqlite.sqliteUserDB())
     elif prevDBType.lower() == "mysql":
         import db_mysql
         return db_mysql.mysqlUserDB()
     elif prevDBType.lower() == "file":
         import db_file
         return db_file.fileUserDB()
     elif prevDBType == "" or prevDBType.lower() == "sqlite":
         import db_sqlite
         return db_sqlite.sqliteUserDB()
     else:
         raise ValueError(
             "Invalid user database type. Re-configure rdiffweb.")
def main():
   userDBModule = db_mysql.mysqlUserDB()
   users = userDBModule.getUserList()
   for user in users:
      print "Adding repos for user %s..." % user
      findReposForUsers(user, userDBModule)