def _sync_games(): # Get all installed games games = get_games() # Iterate over package names and modules for package in games.keys(): module = games[package] # Check if game is in database game = Game.query.filter_by(package=package, name=module.NAME, version=module.VERSION).first() # Create new object if nonexistent if game is None: game = Game() # Sync metadata to database class game.package = package game.name = module.NAME game.version = module.VERSION game.description = module.DESCRIPTION game.author = module.AUTHOR game.license = module.LICENSE # Write to database DB.session.add(game) DB.session.commit()
def _sync_games(): """ Find all installed games and sync them to the database. """ # Get all installed games games = get_games() # Iterate over package names and modules for package in games.keys(): module = games[package] # Check if game is in database game = Game.query.filter_by(package=package, name=module.NAME, version=module.VERSION).first() # Create new object if nonexistent if game is None: game = Game() # Sync metadata to database class game.package = package game.name = module.NAME game.version = module.VERSION game.description = module.DESCRIPTION game.author = module.AUTHOR game.license = module.LICENSE # Write to database DB.session.add(game) DB.session.commit()
def test_get_games(self): """ Test getting a list game modules """ from veripeditus.server.util import get_games # Get game module objects games = get_games() # Returned object should be a dict self.assertIsInstance(games, dict) # test should be a key self.assertIn("test", games)
# # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from glob import glob from io import BytesIO import os import sys import tarfile from veripeditus.server.util import get_games _RELEVANT_PATTERNS = ["*.py", os.path.join("data", "*")] _RELEVANT_MODULES = [ sys.modules["veripeditus.server"], sys.modules["veripeditus.framework"] ] + list(get_games().values()) def get_module_sources(module, patterns=_RELEVANT_PATTERNS): """ Get all sources for a Python module's package. """ # Find path to package path = os.path.dirname(module.__file__) # Find all relevant files files = [] for pattern in patterns: files += glob(os.path.join(path, pattern), recursive=True) # Build dictionary of file names and file contents res = {}