Analisador de pacotes da Sala de jogos
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Nesta página, mostramos como usar o analisador de pacotes da Sala de jogos.
Instruções
O analisador de pacotes da Sala de jogos pode ser executado em um pacote da Sala de jogos para realizar
várias validações no pacote do jogo antes de fazer upload dos recursos no Google.
Google Drive.
Pré-requisitos
Criar o script
- Identifique um diretório na sua máquina para criar o script (exemplo:
~/scripts
).
- Usando o exemplo de código fornecido, crie um arquivo na sua máquina
chamada
playables_bundle_analyzer.py
.
Executar o script para analisar o pacote do jogo
- Abra uma janela do terminal na sua máquina e navegue até o diretório.
que contém o script
playables_bundle_analyzer.py
.
Execute este comando para executar o script, substituindo [GAME_DIRECTORY_PATH]
pelo caminho real do diretório do pacote de jogos:
python3 playables_bundle_analyzer.py [GAME_DIRECTORY_PATH]
Um relatório de análise de pacotes será gerado no diretório do script. Ele vai
chamado playable_bundle_analysis_report.txt
.
Consulte os Requisitos de estabilidade e desempenho para mais informações.
sobre o requisito de tamanho de pacote e nomes de arquivo.
Código
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Contains functions to analyze the Playable game bundles."""
import argparse
import os
import re
from typing import Dict, List, Union
SIZE_LIMITS = {
"file": 31457280, # 30 MiB
"bundle": 262144000, # 250 MiB
}
class BundleAnalyzer:
"""Class for analyzing Playable game bundles."""
def __init__(self, directory_path):
"""Initializes the BundleAnalyzer object with the specified directory path.
Args:
directory_path: The path to the directory to analyze.
"""
self.directory_path = directory_path
self.total_size = 0
self.filenames_with_issues = []
self.files_too_large = []
def analyze(self):
"""Analyzes the Playable game bundle and stores the results.
This function iterates through the directory and its subdirectories,
calculating the total size, and identifying files with
issues like unsupported characters, duplicates, and exceeding size limits.
"""
for root, _, files in os.walk(self.directory_path):
for filename in files:
file_path = os.path.join(root, filename)
file_size = os.path.getsize(file_path)
self.total_size += file_size
if file_size > SIZE_LIMITS["file"]:
self.files_too_large.append(file_path)
if not is_valid_filename(filename):
self.filenames_with_issues.append(file_path)
def get_results(self) -> Dict[str, Union[List[str], List[str], int]]:
"""Returns a dictionary containing the analysis results.
The dictionary includes information about the total number of files,
files with issues, files exceeding size limits,
and the total size of the bundle.
"""
return {
"filenames_with_issues": self.filenames_with_issues,
"files_too_large": self.files_too_large,
"total_size": self.total_size,
}
def is_valid_filename(filename: str) -> bool:
"""Checks if the filename contains valid characters.
Create a regular expression that matches allowed bundle file characters
Args:
filename: The filename to be validated.
Returns:
True if the filename is valid, False otherwise.
"""
pattern = r"^[a-zA-Z0-9\-\._]+$"
return bool(re.fullmatch(pattern, filename))
def main():
"""Main function that runs the BundleAnalyzer.
Parses command line arguments, creates a BundleAnalyzer instance,
runs the analysis, and output the results.
"""
parser = argparse.ArgumentParser(description="Analyze file size")
parser.add_argument("path", help="Path to file or directory")
args = parser.parse_args()
analyzer = BundleAnalyzer(args.path)
analyzer.analyze()
analysis_result = analyzer.get_results()
with open("playable_bundle_analysis_report.txt", "w") as f:
if analysis_result["filenames_with_issues"]:
print(
"Files with unsupported characters:"
f" {analysis_result['filenames_with_issues']}",
file=f,
)
if analysis_result["files_too_large"]:
print(
f"Files too large: {analysis_result['files_too_large']}",
file=f,
)
if analysis_result["total_size"] > SIZE_LIMITS["bundle"]:
print(
f"Total bundle is too large:: {analysis_result['total_size']} bytes",
file=f,
)
if __name__ == "__main__":
main()
Exceto em caso de indicação contrária, o conteúdo desta página é licenciado de acordo com a Licença de atribuição 4.0 do Creative Commons, e as amostras de código são licenciadas de acordo com a Licença Apache 2.0. Para mais detalhes, consulte as políticas do site do Google Developers. Java é uma marca registrada da Oracle e/ou afiliadas.
Última atualização 2025-07-27 UTC.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Não contém as informações de que eu preciso","missingTheInformationINeed","thumb-down"],["Muito complicado / etapas demais","tooComplicatedTooManySteps","thumb-down"],["Desatualizado","outOfDate","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Problema com as amostras / o código","samplesCodeIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-07-27 UTC."],[[["\u003cp\u003eThis page explains how to use the Playables bundle analyzer to validate a game bundle before uploading it to Google Drive.\u003c/p\u003e\n"],["\u003cp\u003eThe analyzer script, \u003ccode\u003eplayables_bundle_analyzer.py\u003c/code\u003e, can be created using the provided sample code after installing Python 3.\u003c/p\u003e\n"],["\u003cp\u003eTo run the analyzer, you must navigate to the directory of the script in a terminal and execute \u003ccode\u003epython3 playables_bundle_analyzer.py [GAME_DIRECTORY_PATH]\u003c/code\u003e, replacing \u003ccode\u003e[GAME_DIRECTORY_PATH]\u003c/code\u003e with the game bundle's directory.\u003c/p\u003e\n"],["\u003cp\u003eAfter execution, the script generates a \u003ccode\u003eplayable_bundle_analysis_report.txt\u003c/code\u003e file in the script's directory, detailing the analysis results.\u003c/p\u003e\n"],["\u003cp\u003eThe script will identify and report on bundle files that are too large, file names that contain invalid characters, and if the total bundle size exceeds the allowable limit.\u003c/p\u003e\n"]]],["To use the Playables bundle analyzer, first install Python 3 and create a `playables_bundle_analyzer.py` script using the provided code. Then, open a terminal, navigate to the script's directory, and run it with `python3 playables_bundle_analyzer.py [GAME_DIRECTORY_PATH]`, replacing `[GAME_DIRECTORY_PATH]` with your game bundle directory. The script validates the game bundle, checks for issues like unsupported characters and files exceeding size limits and generates a `playable_bundle_analysis_report.txt` report in the script's directory.\n"],null,["# Playables bundle analyzer\n\nThis page covers how to use the Playables bundle analyzer.\n\nInstructions\n------------\n\nThe Playables bundle analyzer can be run on a Playable game bundle to perform\nseveral validations on the game bundle before uploading the assets on Google\nDrive.\n\n### Prerequisites\n\n- Install [Python 3](https://www.python.org).\n\n### Create the script\n\n1. Identify a directory on your machine to create the script (example: `~/scripts`).\n2. Using the [sample code provided](#code), create a file on your machine called `playables_bundle_analyzer.py`.\n\n### Execute the script to analyze game bundle\n\n1. Open a terminal window on your machine and navigate to the directory containing the `playables_bundle_analyzer.py` script.\n2. Run the script by executing this command, replacing `[GAME_DIRECTORY_PATH]`\n with the actual path of your game bundle directory:\n\n python3 playables_bundle_analyzer.py [GAME_DIRECTORY_PATH]\n\n3. A bundle analysis report will be generated in the script directory. It will\n be named `playable_bundle_analysis_report.txt`.\n\n4. Refer to the [Stability and performance requirements](/youtube/gaming/playables/certification/requirements_stability) for more information\n about bundle size and file names requirement.\n\nCode\n----\n\n # Copyright 2024 Google LLC\n #\n # Licensed under the Apache License, Version 2.0 (the \"License\");\n # you may not use this file except in compliance with the License.\n # You may obtain a copy of the License at\n #\n # https://www.apache.org/licenses/LICENSE-2.0\n #\n # Unless required by applicable law or agreed to in writing, software\n # distributed under the License is distributed on an \"AS IS\" BASIS,\n # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n # See the License for the specific language governing permissions and\n # limitations under the License.\n \"\"\"Contains functions to analyze the Playable game bundles.\"\"\"\n\n import argparse\n import os\n import re\n from typing import Dict, List, Union\n\n SIZE_LIMITS = {\n \"file\": 31457280, # 30 MiB\n \"bundle\": 262144000, # 250 MiB\n }\n\n class BundleAnalyzer:\n \"\"\"Class for analyzing Playable game bundles.\"\"\"\n\n def __init__(self, directory_path):\n \"\"\"Initializes the BundleAnalyzer object with the specified directory path.\n\n Args:\n directory_path: The path to the directory to analyze.\n \"\"\"\n self.directory_path = directory_path\n self.total_size = 0\n self.filenames_with_issues = []\n self.files_too_large = []\n\n def analyze(self):\n \"\"\"Analyzes the Playable game bundle and stores the results.\n\n This function iterates through the directory and its subdirectories,\n calculating the total size, and identifying files with\n issues like unsupported characters, duplicates, and exceeding size limits.\n \"\"\"\n\n for root, _, files in os.walk(self.directory_path):\n for filename in files:\n file_path = os.path.join(root, filename)\n file_size = os.path.getsize(file_path)\n self.total_size += file_size\n\n if file_size \u003e SIZE_LIMITS[\"file\"]:\n self.files_too_large.append(file_path)\n\n if not is_valid_filename(filename):\n self.filenames_with_issues.append(file_path)\n\n def get_results(self) -\u003e Dict[str, Union[List[str], List[str], int]]:\n \"\"\"Returns a dictionary containing the analysis results.\n\n The dictionary includes information about the total number of files,\n files with issues, files exceeding size limits,\n and the total size of the bundle.\n \"\"\"\n\n return {\n \"filenames_with_issues\": self.filenames_with_issues,\n \"files_too_large\": self.files_too_large,\n \"total_size\": self.total_size,\n }\n\n def is_valid_filename(filename: str) -\u003e bool:\n \"\"\"Checks if the filename contains valid characters.\n\n Create a regular expression that matches allowed bundle file characters\n\n Args:\n filename: The filename to be validated.\n\n Returns:\n True if the filename is valid, False otherwise.\n \"\"\"\n\n pattern = r\"^[a-zA-Z0-9\\-\\._]+$\"\n\n return bool(re.fullmatch(pattern, filename))\n\n def main():\n \"\"\"Main function that runs the BundleAnalyzer.\n\n Parses command line arguments, creates a BundleAnalyzer instance,\n runs the analysis, and output the results.\n \"\"\"\n\n parser = argparse.ArgumentParser(description=\"Analyze file size\")\n parser.add_argument(\"path\", help=\"Path to file or directory\")\n args = parser.parse_args()\n\n analyzer = BundleAnalyzer(args.path)\n analyzer.analyze()\n\n analysis_result = analyzer.get_results()\n\n with open(\"playable_bundle_analysis_report.txt\", \"w\") as f:\n if analysis_result[\"filenames_with_issues\"]:\n print(\n \"Files with unsupported characters:\"\n f\" {analysis_result['filenames_with_issues']}\",\n file=f,\n )\n\n if analysis_result[\"files_too_large\"]:\n print(\n f\"Files too large: {analysis_result['files_too_large']}\",\n file=f,\n )\n\n if analysis_result[\"total_size\"] \u003e SIZE_LIMITS[\"bundle\"]:\n print(\n f\"Total bundle is too large:: {analysis_result['total_size']} bytes\",\n file=f,\n )\n\n if __name__ == \"__main__\":\n main()"]]