इस पेज पर Playables बंडल ऐनालाइज़र इस्तेमाल करने का तरीका बताया गया है.
निर्देश
Playables को Playables गेम बंडल पर चलाया जा सकता है, ताकि बेहतर परफ़ॉर्म किया जा सके Google पर ऐसेट अपलोड करने से पहले, गेम बंडल की अलग-अलग पुष्टि करना ड्राइविंग.
ज़रूरी शर्तें
- Python 3 इंस्टॉल करें.
स्क्रिप्ट बनाएं
- स्क्रिप्ट बनाने के लिए, अपनी मशीन पर किसी डायरेक्ट्री की पहचान करें (उदाहरण:
~/scripts
). - दिए गए सैंपल कोड का इस्तेमाल करके, अपनी मशीन पर एक फ़ाइल बनाएं
playables_bundle_analyzer.py
नाम का इस्तेमाल किया गया.
गेम बंडल का विश्लेषण करने के लिए, स्क्रिप्ट चलाएं
- अपनी मशीन पर टर्मिनल विंडो खोलें और डायरेक्ट्री पर जाएं
playables_bundle_analyzer.py
स्क्रिप्ट शामिल है. [GAME_DIRECTORY_PATH]
को बदलकर, इस निर्देश को लागू करके स्क्रिप्ट चलाएं के असली पाथ के साथ:python3 playables_bundle_analyzer.py [GAME_DIRECTORY_PATH]
स्क्रिप्ट डायरेक्ट्री में, बंडल के विश्लेषण की रिपोर्ट जनरेट की जाएगी. यह काम करेगा इसका नाम
playable_bundle_analysis_report.txt
होगा.ज़्यादा जानकारी के लिए, स्थिरता और परफ़ॉर्मेंस से जुड़ी ज़रूरी शर्तें देखें बंडल के साइज़ और फ़ाइल के नाम से जुड़ी ज़रूरी शर्तों के बारे में जानकारी.
कोड
# 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()